Find ckeditor instance

13,339

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.

Share:
13,339
numfar
Author by

numfar

Updated on June 04, 2022

Comments

  • numfar
    numfar almost 2 years

    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?

  • Kuofp
    Kuofp almost 7 years
    Note that, ckeditorGet() is now marked as deprecated. docs.ckeditor.com/#!/api/…