Selectively fire change events in CKEditor

I am writing a plugin that uses a dialog box.

I noticed that clicking a button on the toolbar to open a dialog box triggers an event changein the editor. In any case, disable this event when opening a dialog box?

The plugin modifies the contents with setAttribute(), removeAttribute()and removeStyles(). Are there anyway calls for these methods to trigger a change event?


After further research, I discovered 2 problems (which, I think, relates to the use of the YUI App Framework), which may be the cause of unexpected behavior.

Playback: http://jsfiddle.net/c3tqk/

Task 1: 1. Select part of the first paragraph ( text) and press the button Edit Link. 2. Select part of the second paragraph ( link) and press the button Edit Link. Check the console and note the change event.

Problem 2: 1. Select exin the first paragraph and press the button Bold. 2. Deselect and select xin the first paragraph and press the button Bold. Note that the change event is fired twice.

+4
source share
1 answer

You can always fire an event manually, but it is usually not recommended . Use CKEDITOR.event.fire:

element.setAttribute( 'foo', 'bar' );
editor.fire( 'change' );

editor#saveSnapshot , ( , ) editor#change , :

element.setAttribute( 'foo', 'bar' );
editor.fire( 'saveSnapshot' );

, . CKEDITOR.event.on .

editor.on( 'change', function( evt ) {
    if ( some condition ) {
        evt.stop();
        // ...or...
        evt.cancel();
    }
}, editor, null, -999 ); // by default listeners have priority=10

. CKEDITOR.eventInfo.stop CKEDITOR.eventInfo.cancel. .

, , , ( ), . ( Chrome FF); change (, Bold, Link ..). ( CKEditor , config ), .

+5

Source: https://habr.com/ru/post/1547307/


All Articles