CKEDITOR.setData prevents attaching of events with .on function

后端 未结 1 1550
盖世英雄少女心
盖世英雄少女心 2020-12-19 06:20

I have build a few custom plugins, but only one is listening to key events of the keyboard. Below in the code you can see the set-up to set the events. (and it\'s kinda bas

相关标签:
1条回答
  • 2020-12-19 06:47

    Editor#contentDom is fired every time new inner document is set up. In framed editor editor#setData() replaces not only body.innerHTML but entire document, so contentDom is fired every time.

    Thus, your code adds new listener on every setData() but you don't remove the old one. For unclear reasons none of these two listeners are now fired on keydown. I found out this recently and I cannot explain this fact.

    Anyway, you need to detach all listeners on editor#contentDomUnload. Fortunately, there's convenient way to do that by using editable#attachListener.

    editor.on( 'contentDom', function() {
        var editable = editor.editable();
    
        editable.attachListener( editor.document, 'keydown', function() {
            ...
        } );
    } );
    

    Listener will be automatically detached on next contentDomUnload.

    0 讨论(0)
提交回复
热议问题