client/js/renderer/nodeeditor.js
changeset 470 47308aa6ce94
parent 469 374e17d0d96a
child 480 a5da9a586297
equal deleted inserted replaced
469:374e17d0d96a 470:47308aa6ce94
    50             var _this = this,
    50             var _this = this,
    51                 editorInstance = _this.options.show_node_editor_description_richtext ?
    51                 editorInstance = _this.options.show_node_editor_description_richtext ?
    52                     $(".Rk-Edit-Description").ckeditor(_this.options.richtext_editor_config) :
    52                     $(".Rk-Edit-Description").ckeditor(_this.options.richtext_editor_config) :
    53                     false,
    53                     false,
    54                 closeEditor = function() {
    54                 closeEditor = function() {
    55                     _this.editor_$.off("keyup");
       
    56                     _this.editor_$.find("input, textarea, select").off("change keyup paste");
       
    57                     _this.editor_$.find(".Rk-Edit-Image-File").off('change');
       
    58                     _this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").off('hover');
       
    59                     _this.editor_$.find(".Rk-Edit-Size-Btn").off('click');
       
    60                     _this.editor_$.find(".Rk-Edit-Image-Del").off('click');
       
    61                     _this.editor_$.find(".Rk-Edit-ColorPicker").find("li").off('hover click');
       
    62                     _this.editor_$.find(".Rk-CloseX").off('click');
       
    63                     _this.editor_$.find(".Rk-Edit-Goto").off('click');
       
    64 
       
    65                     if(_this.options.show_node_editor_description_richtext) {
       
    66                         if(typeof _this.editorListeners !== 'undefined') {
       
    67                             _this.editorListeners.forEach( function(listener) {
       
    68                                 listener.removeListener();
       
    69                             });
       
    70                         }
       
    71                         if(typeof editorInstance.editor !== 'undefined') {
       
    72                             var _editor = editorInstance.editor;
       
    73                             delete editorInstance.editor;
       
    74                             _editor.destroy();
       
    75                         }
       
    76                     }
       
    77                     _this.renderer.removeRepresentation(_this);
    55                     _this.renderer.removeRepresentation(_this);
    78                     paper.view.draw();
    56                     paper.view.draw();
    79                 };
    57                 };
    80 
    58 
    81             this.editor_$.find(".Rk-CloseX").click(closeEditor);
    59             _this.cleanEditor = function() {
       
    60                 _this.editor_$.off("keyup");
       
    61                 _this.editor_$.find("input, textarea, select").off("change keyup paste");
       
    62                 _this.editor_$.find(".Rk-Edit-Image-File").off('change');
       
    63                 _this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").off('hover');
       
    64                 _this.editor_$.find(".Rk-Edit-Size-Btn").off('click');
       
    65                 _this.editor_$.find(".Rk-Edit-Image-Del").off('click');
       
    66                 _this.editor_$.find(".Rk-Edit-ColorPicker").find("li").off('hover click');
       
    67                 _this.editor_$.find(".Rk-CloseX").off('click');
       
    68                 _this.editor_$.find(".Rk-Edit-Goto").off('click');
       
    69 
       
    70                 if(_this.options.show_node_editor_description_richtext) {
       
    71                     if(typeof editorInstance.editor !== 'undefined') {
       
    72                         var _editor = editorInstance.editor;
       
    73                         delete editorInstance.editor;
       
    74                         _editor.focusManager.blur(true);
       
    75                         _editor.destroy();
       
    76                     }
       
    77                 }
       
    78             };
       
    79 
       
    80             this.editor_$.find(".Rk-CloseX").click(function (e) {
       
    81                 e.preventDefault();
       
    82                 closeEditor();
       
    83             });
    82 
    84 
    83             this.editor_$.find(".Rk-Edit-Goto").click(function() {
    85             this.editor_$.find(".Rk-Edit-Goto").click(function() {
    84                 if (!_model.get("uri")) {
    86                 if (!_model.get("uri")) {
    85                     return false;
    87                     return false;
    86                 }
    88                 }
   101                         if (_this.options.show_node_editor_image) {
   103                         if (_this.options.show_node_editor_image) {
   102                             _data.image = _this.editor_$.find(".Rk-Edit-Image").val();
   104                             _data.image = _this.editor_$.find(".Rk-Edit-Image").val();
   103                             _this.editor_$.find(".Rk-Edit-ImgPreview").attr("src", _data.image || _image_placeholder);
   105                             _this.editor_$.find(".Rk-Edit-ImgPreview").attr("src", _data.image || _image_placeholder);
   104                         }
   106                         }
   105                         if (_this.options.show_node_editor_description) {
   107                         if (_this.options.show_node_editor_description) {
   106                             if(_this.options.show_node_editor_description_richtext &&
   108                             if(_this.options.show_node_editor_description_richtext) {
   107                                 typeof editorInstance.editor !== 'undefined' &&
   109                                 if(typeof editorInstance.editor !== 'undefined' &&
   108                                 editorInstance.editor.checkDirty())
   110                                     editorInstance.editor.checkDirty()) {
   109                             {
   111                                     _data.description = editorInstance.editor.getData();
   110                                 _data.description = editorInstance.editor.getData();
   112                                     editorInstance.editor.resetDirty();
   111                                 editorInstance.editor.resetDirty();
   113                                 }
   112                             }
   114                             }
   113                             else {
   115                             else {
   114                                 _data.description = _this.editor_$.find(".Rk-Edit-Description").val();
   116                                 _data.description = _this.editor_$.find(".Rk-Edit-Description").val();
   115                             }
   117                             }
   116                         }
   118                         }
   140                 this.editor_$.find("input, textarea, select").on("change keyup paste", onFieldChange);
   142                 this.editor_$.find("input, textarea, select").on("change keyup paste", onFieldChange);
   141                 if( _this.options.show_node_editor_description &&
   143                 if( _this.options.show_node_editor_description &&
   142                     _this.options.show_node_editor_description_richtext &&
   144                     _this.options.show_node_editor_description_richtext &&
   143                     typeof editorInstance.editor !== 'undefined')
   145                     typeof editorInstance.editor !== 'undefined')
   144                 {
   146                 {
   145                     _this.editorListeners = [];
   147                     editorInstance.editor.on("change", onFieldChange);
   146                     _this.editorListeners.push(editorInstance.editor.on("change", onFieldChange));
   148                     editorInstance.editor.on("blur", onFieldChange);
   147                     _this.editorListeners.push(editorInstance.editor.on("blur", onFieldChange));
       
   148                 }
   149                 }
   149 
   150 
   150                 if(_this.options.allow_image_upload) {
   151                 if(_this.options.allow_image_upload) {
   151                     this.editor_$.find(".Rk-Edit-Image-File").change(function() {
   152                     this.editor_$.find(".Rk-Edit-Image-File").change(function() {
   152                         if (this.files.length) {
   153                         if (this.files.length) {
   276                 var _coords = this.source_representation.paper_coords;
   277                 var _coords = this.source_representation.paper_coords;
   277                 Utils.drawEditBox(this.options, _coords, this.editor_block, this.source_representation.circle_radius * 0.75, this.editor_$);
   278                 Utils.drawEditBox(this.options, _coords, this.editor_block, this.source_representation.circle_radius * 0.75, this.editor_$);
   278             }
   279             }
   279             this.editor_$.show();
   280             this.editor_$.show();
   280             paper.view.draw();
   281             paper.view.draw();
       
   282         },
       
   283         destroy: function() {
       
   284             if(typeof this.cleanEditor !== 'undefined') {
       
   285                 this.cleanEditor();
       
   286             }
       
   287             this.editor_block.remove();
       
   288             this.editor_$.remove();
   281         }
   289         }
   282     }).value();
   290     }).value();
   283 
   291 
   284     /* NodeEditor End */
   292     /* NodeEditor End */
   285 
   293