Вопрос

I am working on an Ember.js - based platform, where I use nicEdit. Here is my code

RichHTMLView = Ember.TextArea.extend({
    id: null,
    editor: null,
    didInsertElement: function(){
        var view = this;

        view.id = this.get("elementId");

        view.editor = new nicEditor({
                buttonList : ['bold','italic','underline','right','center','justify', 'link', 'ul', 'ol']
        }).panelInstance(view.id);

        //When the editor looses focus the content of the editor is passed to descr
        view.editor.addEvent('blur',function(){
            view.get('controller').set('descr',view.getViewContent());
        });

        //So the editor looks nice
        $('.nicEdit-panelContain').parent().width('100%');
        $('.nicEdit-panelContain').parent().next().width('100%');
    },
    getViewContent: function(){
        var view = this,
            inlineEditor = view.editor.instanceById(view.id);
        return inlineEditor.getContent();
    },
    willClearRender: function(){
        var view = this;
    }

});

So this works nicely as long as I am on the page which hosts the view, but if I transition to another route, the view has some leftovers, namely the editor is destroyed, but I assume that nicEdit keeps track of event bindings, so I end up with the blur event being bound to editor, which is undefined in the new context, as the view does not exist.

My best guess is that I need to somehow unbind the editor in the willClearRender, but I don't know how.

Это было полезно?

Решение

as I got no reply and nicEdit is abandoned I made some changes to the source-code in order to deal with this issue by adding removeEvent to bkEvent:

removeEvent: function(A, B){

if (B){
    this.eventList = this.eventList || {};
    this.eventList[A] = this.eventList[A] || [];
    this.eventList[A].splice(this.eventList[A].indexOf(B),1);
}

Then I can remove the event in willClearRender:

view.editor.removeEvent('blur',view.onBlur);

Be aware that I've not tested it with multiple editors, as my needs do not require, but if you have multiple editors with the same callback the behavior is not defined.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top