Opened 9 years ago

Last modified 9 years ago

#13122 confirmed Bug

On editor.setData() native listeners are detached, but document stays so CKE listeners stop working

Reported by: Piotrek Koszuliński Owned by:
Priority: Normal Milestone:
Component: General Version:
Keywords: Cc:

Description (last modified by Piotrek Koszuliński)

  1. Open any sample with wysiwygarea.
  2. CKEDITOR.instances.editor1.document.on( 'click', function() { console.log( 'click1' ) } );
  3. Test that it works. OK.
  4. CKEDITOR.instances.editor1.setData( 'xxx' );
  5. Test that the click listener no longer works. OK.
  6. CKEDITOR.instances.editor1.document.on( 'click', function() { console.log( 'click2' ) } );
  7. Test that it works. NOK.

In general - if listener to some event was attached before set data, then it will no longer work after setting data and it won't be possible to attach a new listener to that event.

The reason is that setting data (unlike switching modes) keeps the same document, but writing to that document removes all its previous listeners.

On every domObject.on() we push the listener to domObject.getCustomData( '_' ) (the listeners repository) and if a native listener has not been added yet we add it to the native element. So there's only one native listener per event name.

Since setting data keeps the same document, the custom data (our listeners repository) stays the same. But the native listeners are removed. This means that when trying to add a new listener editor thinks that a native listener was already added, because the listeners repository already contains an entry for that event.

The solution will be to clear events repository on set data.

Change History (3)

comment:1 Changed 9 years ago by Piotrek Koszuliński

Description: modified (diff)
Status: newconfirmed

comment:2 Changed 9 years ago by Olek Nowodziński


comment:3 Changed 9 years ago by Marek Lewandowski


Note: See TracTickets for help on using tickets.
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy