client/js/renderer/nodeeditor.js
changeset 480 a5da9a586297
parent 479 be510a7fc5ac
parent 470 47308aa6ce94
child 482 a55c33989404
--- a/client/js/renderer/nodeeditor.js	Fri Jun 12 15:41:26 2015 +0200
+++ b/client/js/renderer/nodeeditor.js	Mon Jun 15 11:02:09 2015 +0200
@@ -53,33 +53,35 @@
                     $(".Rk-Edit-Description").ckeditor(_this.options.richtext_editor_config) :
                     false,
                 closeEditor = function() {
-                    _this.editor_$.off("keyup");
-                    _this.editor_$.find("input, textarea, select").off("change keyup paste");
-                    _this.editor_$.find(".Rk-Edit-Image-File").off('change');
-                    _this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").off('hover');
-                    _this.editor_$.find(".Rk-Edit-Size-Btn").off('click');
-                    _this.editor_$.find(".Rk-Edit-Image-Del").off('click');
-                    _this.editor_$.find(".Rk-Edit-ColorPicker").find("li").off('hover click');
-                    _this.editor_$.find(".Rk-CloseX").off('click');
-                    _this.editor_$.find(".Rk-Edit-Goto").off('click');
-
-                    if(_this.options.show_node_editor_description_richtext) {
-                        if(typeof _this.editorListeners !== 'undefined') {
-                            _this.editorListeners.forEach( function(listener) {
-                                listener.removeListener();
-                            });
-                        }
-                        if(typeof editorInstance.editor !== 'undefined') {
-                            var _editor = editorInstance.editor;
-                            delete editorInstance.editor;
-                            _editor.destroy();
-                        }
-                    }
                     _this.renderer.removeRepresentation(_this);
                     paper.view.draw();
                 };
 
-            this.editor_$.find(".Rk-CloseX").click(closeEditor);
+            _this.cleanEditor = function() {
+                _this.editor_$.off("keyup");
+                _this.editor_$.find("input, textarea, select").off("change keyup paste");
+                _this.editor_$.find(".Rk-Edit-Image-File").off('change');
+                _this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").off('hover');
+                _this.editor_$.find(".Rk-Edit-Size-Btn").off('click');
+                _this.editor_$.find(".Rk-Edit-Image-Del").off('click');
+                _this.editor_$.find(".Rk-Edit-ColorPicker").find("li").off('hover click');
+                _this.editor_$.find(".Rk-CloseX").off('click');
+                _this.editor_$.find(".Rk-Edit-Goto").off('click');
+
+                if(_this.options.show_node_editor_description_richtext) {
+                    if(typeof editorInstance.editor !== 'undefined') {
+                        var _editor = editorInstance.editor;
+                        delete editorInstance.editor;
+                        _editor.focusManager.blur(true);
+                        _editor.destroy();
+                    }
+                }
+            };
+
+            this.editor_$.find(".Rk-CloseX").click(function (e) {
+                e.preventDefault();
+                closeEditor();
+            });
 
             this.editor_$.find(".Rk-Edit-Goto").click(function() {
                 if (!_model.get("uri")) {
@@ -104,12 +106,12 @@
                             _this.editor_$.find(".Rk-Edit-ImgPreview").attr("src", _data.image || _image_placeholder);
                         }
                         if (_this.options.show_node_editor_description) {
-                            if(_this.options.show_node_editor_description_richtext &&
-                                typeof editorInstance.editor !== 'undefined' &&
-                                editorInstance.editor.checkDirty())
-                            {
-                                _data.description = editorInstance.editor.getData();
-                                editorInstance.editor.resetDirty();
+                            if(_this.options.show_node_editor_description_richtext) {
+                                if(typeof editorInstance.editor !== 'undefined' &&
+                                    editorInstance.editor.checkDirty()) {
+                                    _data.description = editorInstance.editor.getData();
+                                    editorInstance.editor.resetDirty();
+                                }
                             }
                             else {
                                 _data.description = _this.editor_$.find(".Rk-Edit-Description").val();
@@ -143,9 +145,8 @@
                     _this.options.show_node_editor_description_richtext &&
                     typeof editorInstance.editor !== 'undefined')
                 {
-                    _this.editorListeners = [];
-                    _this.editorListeners.push(editorInstance.editor.on("change", onFieldChange));
-                    _this.editorListeners.push(editorInstance.editor.on("blur", onFieldChange));
+                    editorInstance.editor.on("change", onFieldChange);
+                    editorInstance.editor.on("blur", onFieldChange);
                 }
 
                 if(_this.options.allow_image_upload) {
@@ -279,6 +280,13 @@
             }
             this.editor_$.show();
             paper.view.draw();
+        },
+        destroy: function() {
+            if(typeof this.cleanEditor !== 'undefined') {
+                this.cleanEditor();
+            }
+            this.editor_block.remove();
+            this.editor_$.remove();
         }
     }).value();