2014-12-19 30 views
2

我們需要做一些特殊的處理來處理CKEditor的'toHtml'事件。 我們需要用原始字符串格式的數據進行這種處理,所以我們必須設置一個低優先級(如1)。 我們可以用下面這樣做:用CKEDITOR.config.on定義事件處理函數的優先級

CKEDITOR.instances.editorName.on('toHtml', toHtmlHandler, null, null, 1); 

但是,我們必須噸根據頁面上的可能實例,所以我們試圖用這種方式來做到這一點只有一次:

configuration.on = { 
    toHtml: toHtmlHandler 
} 

的問題在於,我們無法弄清楚如何在這種形式下設置優先級,這是否可能?

謝謝

回答

3

不,沒有辦法設置優先順序。另一個偵聽器內(前toHtml)安裝監聽器:

function toHtmlHandler(evt) { 
    console.log('toHtml event', evt); 
} 

CKEDITOR.replace('editor1', { 
    on: { 
     pluginsLoaded: function() { 
      this.on('toHtml', toHtmlHandler, null, null, 1); 
     } 
    } 
}); 
+0

大,我們採取了這一做法,但處理「instanceLoaded」事件,感謝@oleq。 – gmangado

+1

使用['instanceCreated'](http://docs.ckeditor.com/#!/api/CKEDITOR-event-instanceCreated)而不是['instanceLoaded'](http://docs.ckeditor.com/#!/ API/CKEDITOR-事件instanceLoaded)。否則,你會失去最初的'toHtml'(當數據來自textarea時),在'instanceLoaded'之前被觸發。 – oleq