client/js/renderer/nodeeditor.js
changeset 468 364c367df7fc
parent 461 48235ed6b07d
child 469 374e17d0d96a
--- a/client/js/renderer/nodeeditor.js	Wed Jun 10 14:27:12 2015 +0200
+++ b/client/js/renderer/nodeeditor.js	Fri Jun 12 14:46:08 2015 +0200
@@ -1,5 +1,5 @@
 
-define(['jquery', 'underscore', 'requtils', 'renderer/baseeditor', 'renderer/shapebuilder'], function ($, _, requtils, BaseEditor, ShapeBuilder) {
+define(['jquery', 'underscore', 'requtils', 'renderer/baseeditor', 'renderer/shapebuilder', 'ckeditor-jquery'], function ($, _, requtils, BaseEditor, ShapeBuilder) {
     'use strict';
 
     var Utils = requtils.getUtils();
@@ -48,20 +48,31 @@
             }));
             this.redraw();
             var _this = this,
-            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');
+                editorInstance = _this.options.show_node_editor_description_richtext ?
+                    $(".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');
 
-                _this.renderer.removeRepresentation(_this);
-                paper.view.draw();
-            };
+                    if(_this.options.show_node_editor_description_richtext) {
+                        if(typeof _this.blurListener !== 'undefined') {
+                            _this.editorBlurListener.removeListener();
+                        }
+                        if(typeof editorInstance.editor !== 'undefined') {
+                            editorInstance.editor.destroy();
+                        }
+                    }
+                    _this.renderer.removeRepresentation(_this);
+                    paper.view.draw();
+                };
 
             this.editor_$.find(".Rk-CloseX").click(closeEditor);
 
@@ -88,7 +99,16 @@
                             _this.editor_$.find(".Rk-Edit-ImgPreview").attr("src", _data.image || _image_placeholder);
                         }
                         if (_this.options.show_node_editor_description) {
-                            _data.description = _this.editor_$.find(".Rk-Edit-Description").val();
+                            if(_this.options.show_node_editor_description_richtext &&
+                                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();
+                            }
                         }
                         if (_this.options.show_node_editor_style) {
                             var dash = _this.editor_$.find(".Rk-Edit-Dash").is(':checked');
@@ -105,7 +125,7 @@
                         closeEditor();
                     }
                   });
-                }, 500);
+                }, 1000);
 
                 this.editor_$.on("keyup", function(_e) {
                     if (_e.keyCode === 27) {
@@ -114,6 +134,13 @@
                 });
 
                 this.editor_$.find("input, textarea, select").on("change keyup paste", onFieldChange);
+                if( _this.options.show_node_editor_description &&
+                    _this.options.show_node_editor_description_richtext &&
+                    typeof editorInstance.editor !== 'undefined')
+                {
+                    editorInstance.editor.on("change", onFieldChange);
+                    _this.editorBlurListener = editorInstance.editor.on("blur", onFieldChange);
+                }
 
                 if(_this.options.allow_image_upload) {
                     this.editor_$.find(".Rk-Edit-Image-File").change(function() {
@@ -242,7 +269,7 @@
         redraw: function() {
             if (this.options.popup_editor){
                 var _coords = this.source_representation.paper_coords;
-                Utils.drawEditBox(this.options, _coords, this.editor_block, this.source_representation.circle_radius * 0.75, this.editor_$);                
+                Utils.drawEditBox(this.options, _coords, this.editor_block, this.source_representation.circle_radius * 0.75, this.editor_$);
             }
             this.editor_$.show();
             paper.view.draw();