From 8c838a1e2df218ea7da65a8a449da1188e091f51 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Wed, 2 Jul 2014 12:00:33 +0200 Subject: [PATCH] editor: cleanup - removing unnecessary wlxml class handling code in canvas generic element - 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 --- .../documentCanvas/canvas/genericElement.js | 30 ++----------------- .../modules/documentCanvas/canvas/keyboard.js | 4 +-- 2 files changed, 5 insertions(+), 29 deletions(-) diff --git a/src/editor/modules/documentCanvas/canvas/genericElement.js b/src/editor/modules/documentCanvas/canvas/genericElement.js index 4dfbe59..a703b0c 100644 --- a/src/editor/modules/documentCanvas/canvas/genericElement.js +++ b/src/editor/modules/documentCanvas/canvas/genericElement.js @@ -24,8 +24,9 @@ $.extend(generic, { 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) { @@ -101,11 +102,6 @@ $.extend(generic, { 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(); @@ -233,26 +229,6 @@ $.extend(generic, { } }); 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(); } }); diff --git a/src/editor/modules/documentCanvas/canvas/keyboard.js b/src/editor/modules/documentCanvas/canvas/keyboard.js index 71a50b0..646c68a 100644 --- a/src/editor/modules/documentCanvas/canvas/keyboard.js +++ b/src/editor/modules/documentCanvas/canvas/keyboard.js @@ -52,7 +52,7 @@ handlers.push({key: KEYS.ENTER, 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; @@ -77,7 +77,7 @@ handlers.push({key: KEYS.ENTER, 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; -- 2.20.1