简体   繁体   中英

Find ckeditor instance

I want to access and manipulate the content of a textarea where ckeditor is used. My original code before I started using the editor was:

(function ($) {
    "use strict";
    $(document).ready(function () {

         for(var i=0; i<=10; i++) {

                $('#edit-button'+i).click(function(){

                        var tag = $(this).attr("value");
                        var id ="edit-body-und-0-value"; /* id of textarea */

                        var element  = document.getElementById(id);
                        var start    = element.selectionStart;
                        var end      = element.selectionEnd;
                        var text     = element.value;
                var prefix   = text.substring(0, start);
                        var selected = text.substring(start, end);
                        var suffix   = text.substring(end);
                        selected     = "["+tag+"]" + selected + "[/"+tag+"]";
                        element.value      = prefix + selected + suffix;

                        element.selectionStart = start;
                        element.selectionEnd   = start + selected.length;

                        return false;

                        });
            }
        });

})(jQuery);

This stops working when the editor is enabled.

I'm guessing that I need to use some different object then the 'element' object, the ckeditor object, and then I could maybe use the function described here: http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html

But how do I get the ckeditor object?

The ckeditor is added in drupal so I know very little about it and I am very unsure about how to access it or what information to look for in order to be able to know what to do.

On this page: http://ckeditor.com/blog/CKEditor_for_jQuery

$( 'textarea.editor' ).ckeditor();

is used to create the object(?). But I already have an ckeditor instance that I need to find. Can I some how select the editor for a given textarea?

Using the jquery adapter, you can get the ckeditor "object" like this:

$('textarea.editor').ckeditorGet()

So to destroy it, you'd do

$('textarea.editor').ckeditorGet().destroy()

This is using version 4.x of ckeditor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM