5

何かをonChangeイベントにバインドするには、次のようなものを記述します。

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

しかし...その機能をどのようにアンバインドするのでしょうか?

上記のコードは、エディターを作成するときに使用するインスタンス化コードの一部です。ajaxを使用してページを変更すると、問題が発生し、CKEditor(および他のすべてのjavascript変数)がページで定義されたままになります。したがって、onChangeイベントは複数のバインディングを取得することになります...これはパフォーマンスの問題を引き起こす可能性があります。

4

2 に答える 2

8

CKEditorのeventInfoドキュメントには、Firebugを使用して見つけることができる「removeListener」メソッドがありません。今すぐ追加しましたが、公開されるまでに1日かかる場合があります。

イベントオブジェクトでそのメソッドを呼び出す必要があります。次に例を示します。

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

       if (CKEDITOR.instances[element_id].checkDirty()) {
          unsaved_changes = true;
       }
});
于 2012-04-30T17:31:00.420 に答える
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
   });

});

于 2013-09-02T14:46:27.657 に答える