CKEDITOR how to Identify scroll event

≯℡__Kan透↙ 提交于 2019-12-12 04:42:02

问题


Does anyone know how to catch the 'scroll' event in CKEDITOR? there is easy to identify change and other events, but I am unable to cathc Scroll event..

CKEDITOR.instances[i].on('change', function() {alert('text changed!');});

but when want to use same for scroll it does not working

CKEDITOR.instances[i].on('scroll', function() {alert('I am scrolling!');});

does anyone know some workaround?

Thx a lot M


回答1:


First thing you need to know is that CKEditor's instance (which you get from CKEDITOR.instances object) is not a DOM element. It indeed fires some events like change, focus, blur, or save, but they are just short cuts or facades to more complex things.

Therefore, if you want to add a DOM event listener, then you need to retrieve the "editable" element (an element in which editing happens). It can be accessed by the editor.editable() method. However, the tricky thing about editable element is that it's not always available, it's not ready right after starting editor initialization and that editor may replace this element with a new one (usually after switching between modes). Therefore, editor fires a contentDom to notify that the new editable is available and the editable has an attachListener method which, unlike the on cleans the listener when editable is destroyed.

The way to use all those methods is explained in the documentation and there are code samples, but just to save you one click:

editor.on( 'contentDom', function() {
    var editable = editor.editable();

    editable.attachListener( editable.getDocument(), 'scroll', function() {
        console.log( 'Editable has been scrolled' );
    });
});

Update: I forgot that for 'scroll' event you have to listen on document. I updated the code above.



来源:https://stackoverflow.com/questions/22439960/ckeditor-how-to-identify-scroll-event

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!