簡體   English   中英

在插件命令中獲取Inline CKEditor的當前實例

[英]Getting current instance of Inline CKEditor in plugin command

最近,我們離開了tinymce,我們創建了一個自定義函數,其中有一個工具欄按鈕,一旦單擊該按鈕,就會在工具欄上方滑動一個自定義div,並在頁面加載時附加到該工具欄上。

現在,使用嵌入式版本時,問題對於CKEditor而言是相同的。 既然有十個實例同時處於活動狀態,那么在單擊自定義插件按鈕后,如何獲取當前彈出的嵌入式Ckeditor的實例,以便可以使用jQuery附加到實例中?

使用最新版本的CKEditor4.x。

很難想象您要完成什么。 無論如何,您可以觀察到聚焦於哪個編輯器實例(最終可以將引用存儲在某個變量中):

CKEDITOR.on( 'instanceReady', function( event ) {
    event.editor.on( 'focus', function() {
        console.log( 'focused', this );
    });
});

畢竟,您還可以瀏覽編輯器實例,因為它們存儲在全局名稱空間的CKEDITOR.instances對象中。 這樣,您就可以通過名稱,ID或其他任何內容(即先前與您的按鈕相關聯)找到您的實例。

我會這樣

    var ck_instance_name = false;
    for ( var ck_instance in CKEDITOR.instances ){
        if (CKEDITOR.instances[ck_instance].focusManager.hasFocus){
            ck_instance_name = ck_instance;
            return ck_instance_name;
        }
    }

獲取ck編輯器的當前實例。 這是簡單的代碼

var currentEditor;    
 for(var id in CKEDITOR.instances) {
  CKEDITOR.instances[id].on('focus', function(e) {
    // Fill some global var here
    currentEditor = e.editor.name;
});
}

使用上面接受的答案,我發現觸發給定插件的編輯器實例的編輯器“名稱”(眾所周知)可以通過this._.editor.name (using CKEditor v4.3)

這樣,您可以通過這種方式檢索編輯器內容。

CKEDITOR.instances[this._.editor.name].getData();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM