editor: cleanup - removing unnecessary wlxml class handling code in canvas generic...
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 2 Jul 2014 10:00:33 +0000 (12:00 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Fri, 18 Jul 2014 09:47:37 +0000 (11:47 +0200)
- generic element doesn't actually handle onNodeAttrChange for a 'class'
attribute -  that kind of change leads to creating new canvas element
instance since e0aad96df245c7148966887cbcc77417a4b7675b
- for the same reason support for changing class information on a generic
element during its life time is not necessary

src/editor/modules/documentCanvas/canvas/genericElement.js
src/editor/modules/documentCanvas/canvas/keyboard.js

index 4dfbe59..a703b0c 100644 (file)
@@ -24,8 +24,9 @@ $.extend(generic, {
     init: function() {
         DocumentNodeElement.prototype.init.call(this);
         this._container()
     init: function() {
         DocumentNodeElement.prototype.init.call(this);
         this._container()
-            .attr('wlxml-tag', this.wlxmlNode.getTagName());
-        this.setWlxmlClass(this.wlxmlNode.getClass());
+            .attr('wlxml-tag', this.wlxmlNode.getTagName())
+            .attr('wlxml-class', this.wlxmlNode.getClass().replace(/\./g, '-'));
+
         this.wlxmlNode.contents().forEach(function(node) {
             var el = this.canvas.createElement(node);
             if(el.dom) {
         this.wlxmlNode.contents().forEach(function(node) {
             var el = this.canvas.createElement(node);
             if(el.dom) {
@@ -101,11 +102,6 @@ $.extend(generic, {
         return toret;
     },
 
         return toret;
     },
 
-    onNodeAttrChange: function(event) {
-        if(event.meta.attr === 'class') {
-            this.setWlxmlClass(event.meta.newVal); //
-        }
-    },
     onNodeAdded: function(event) {
         if(event.meta.node.isRoot()) {
             this.canvas.reloadRoot();
     onNodeAdded: function(event) {
         if(event.meta.node.isRoot()) {
             this.canvas.reloadRoot();
@@ -233,26 +229,6 @@ $.extend(generic, {
             }
         });
         return toret;
             }
         });
         return toret;
-    },
-
-    getWlxmlClass: function() {
-        var klass = this._container().attr('wlxml-class');
-        if(klass) {
-            return klass.replace(/-/g, '.');
-        }
-        return undefined;
-    },
-    setWlxmlClass: function(klass) {
-        if(klass === this.getWlxmlClass()) {
-            return;
-        }
-        if(klass) {
-            this._container().attr('wlxml-class', klass.replace(/\./g, '-'));
-        }
-        else {
-            this._container().removeAttr('wlxml-class');
-        }
-        this.refreshPath();
     }
 });
 
     }
 });
 
index 71a50b0..646c68a 100644 (file)
@@ -52,7 +52,7 @@ handlers.push({key: KEYS.ENTER,
                 canvas.wlxmlDocument.transaction(function() {
                     var added = currentElement.wlxmlNode.after({
                         tagName: currentElement.wlxmlNode.getTagName() || 'div',
                 canvas.wlxmlDocument.transaction(function() {
                     var added = currentElement.wlxmlNode.after({
                         tagName: currentElement.wlxmlNode.getTagName() || 'div',
-                        attrs: {'class': currentElement.getWlxmlClass() || 'p'}
+                        attrs: {'class': currentElement.wlxmlNode.getClass() || 'p'}
                     });
                     added.append({text:''});
                     return added;
                     });
                     added.append({text:''});
                     return added;
@@ -77,7 +77,7 @@ handlers.push({key: KEYS.ENTER,
 
                 canvas.wlxmlDocument.transaction(function() {
                     var added = element.wlxmlNode.after(
 
                 canvas.wlxmlDocument.transaction(function() {
                     var added = element.wlxmlNode.after(
-                        {tagName: element.wlxmlNode.getTagName() || 'div', attrs: {'class': element.getWlxmlClass() || 'p'}}
+                        {tagName: element.wlxmlNode.getTagName() || 'div', attrs: {'class': element.wlxmlNode.getClass() || 'p'}}
                     );
                     added.append({text: ''});
                     return added;
                     );
                     added.append({text: ''});
                     return added;