Hi,
in my code some elements have events handlers, which are set on element creation or editor setData event, as the handlers shall work also on loaded documents.
My problem is that, when switching to code view and then returning back in wysiwyg, the events are lost. Since setData is not called when going back to this view, the handlers aren't re-binded.
In detail, when I load my plugin, I do:
I'm using jquery .live() method. It is registered on the document, not on each element, and it allow to auto-bind the handler to every matching element existing at the time call or inserted in the future.
This works pretty well when inserting elements and loading an existing document - as it's invoked on setData event - but when switching, the bindings are lost.
The best method I can think of is: how to tell ckeditor not to remve the bindings?
Else: how can I execute a function (for binding the handlers) when switching from code to document view? I.e. does exists an event when switching view?
(With this solution, I could execute the above code both on setData and on switch-to-document-view event.)
Or any other solution?
TIA
~Aki
in my code some elements have events handlers, which are set on element creation or editor setData event, as the handlers shall work also on loaded documents.
My problem is that, when switching to code view and then returning back in wysiwyg, the events are lost. Since setData is not called when going back to this view, the handlers aren't re-binded.
In detail, when I load my plugin, I do:
editor.on('setData', function() {
$(myElements).live('mouseover', function() { handle(); });
});I'm using jquery .live() method. It is registered on the document, not on each element, and it allow to auto-bind the handler to every matching element existing at the time call or inserted in the future.
This works pretty well when inserting elements and loading an existing document - as it's invoked on setData event - but when switching, the bindings are lost.
The best method I can think of is: how to tell ckeditor not to remve the bindings?
Else: how can I execute a function (for binding the handlers) when switching from code to document view? I.e. does exists an event when switching view?
(With this solution, I could execute the above code both on setData and on switch-to-document-view event.)
Or any other solution?
TIA
~Aki

Re: Event handler lost when switching view
var jsRegisterer = function() { bindEvents() }; editor.on('mode', function() { if (editor.mode == 'wysiwyg') jsRegisterer() }); editor.on('setData', jsRegisterer);