2012-04-30 18 views
4

綁定的東西到onChange事件,一個會寫一些與此類似:如何從CKEditor解除事件?

CKEDITOR.on('currentInstance', function(ev) 
{ 
     if (CKEDITOR.instances[element_id].checkDirty()) { 
      unsaved_changes = true; 
     } 
}); 

但是......一個人如何解綁該功能?

上面的代碼是我在創建編輯器時使用的一些實例化代碼的一部分。當我使用ajax更改頁面時,出現了一個問題,並且CKEditor(以及所有其他JavaScript變量)在頁面上保持定義。所以,onChange事件最終會得到多個綁定......這可能會導致性能問題。

回答

6

CKEditor的eventInfo文檔缺少使用Firebug可以找到的「removeListener」方法。我已經添加了它,但它可能需要一天才會發布。

你只需要調用事件對象上的方法,例如:

CKEDITOR.on('currentInstance', function(ev) 
{ 
     ev.removeListener(); 

     if (CKEDITOR.instances[element_id].checkDirty()) { 
      unsaved_changes = true; 
     } 
}); 
+0

謝謝! = D這正是我正在尋找的! – NullVoxPopuli

1
window.ckeditor=CKEDITOR.replace('ckeditor'); //create instance 

var focus_action =function(){ console.log('focus'); }; /*callback must have own name*/

ckeditor.on('instanceReady',function(){ var _this=this;

this.document.on('keyup',function(){ 
    console.log(ckeditor.checkDirty()); 
    }); 

    this.document.on('focus',focus_action); //bind our callback 


    this.document.on('blur',function(){ 
    console.log('blur'); 
    _this.document.removeListener('focus',focus_action); //remove our callback 
    //_this.document.removeAllListeners(); //remove all listeners 
    }); 

});