Merge in canvas refactorizations
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Fri, 28 Mar 2014 11:55:55 +0000 (12:55 +0100)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Fri, 28 Mar 2014 11:55:55 +0000 (12:55 +0100)
src/editor/modules/documentCanvas/canvas/canvas.js
src/editor/modules/documentCanvas/canvas/canvas.test.js
src/editor/modules/documentCanvas/canvas/documentElement.js
src/editor/modules/documentCanvas/canvas/keyboard.js
src/editor/modules/documentCanvas/canvas/utils.js
src/editor/modules/documentCanvas/canvas/wlxmlListener.js
src/editor/modules/documentCanvas/canvas/wlxmlManagers.js
src/editor/modules/documentCanvas/commands.js

index 6bc5c41..476a95b 100644 (file)
@@ -71,6 +71,31 @@ $.extend(Canvas.prototype, {
         this.reloadRoot();
     },
 
+    createElement: function(wlxmlNode) {
+        var Factory = wlxmlNode.nodeType === Node.TEXT_NODE ? documentElement.DocumentTextElement : documentElement.DocumentNodeElement;
+        return new Factory(wlxmlNode, this);
+    },
+
+    getDocumentElement: function(htmlElement) {
+        /* globals HTMLElement, Text */
+        if(!htmlElement || !(htmlElement instanceof HTMLElement || htmlElement instanceof Text)) {
+            return null;
+        }
+        var $element = $(htmlElement);
+        if(htmlElement.nodeType === Node.ELEMENT_NODE && $element.attr('document-node-element') !== undefined) {
+            return $element.data('canvas-element');
+        }
+
+        if(htmlElement.nodeType === Node.TEXT_NODE && $element.parent().attr('document-text-element') !== undefined) {
+            $element = $element.parent();
+        }
+
+        if($element.attr('document-text-element') !== undefined || (htmlElement.nodeType === Node.TEXT_NODE && $element.parent().attr('document-text-element') !== undefined)) {
+            //return DocumentTextElement.fromHTMLElement(htmlElement, canvas);
+            return $element.data('canvas-element');
+        }
+    },
+
     reloadRoot: function() {
         var canvasDOM = this.generateCanvasDOM(this.wlxmlDocument.root);
         //var canvasDOM = this.wlxmlDocument.root.getData('canvasElement') ? this.wlxmlDocument.root.getData('canvasElement').dom() : this.generateCanvasDOM(this.wlxmlDocument.root);
@@ -81,8 +106,9 @@ $.extend(Canvas.prototype, {
     },
 
     generateCanvasDOM: function(wlxmlNode) {
-        var element = documentElement.DocumentNodeElement.create(wlxmlNode, this);
-        return element.dom();
+        //var element = new documentElement.DocumentNodeElement(wlxmlNode, this);
+        //return element.dom();
+        return this.createElement(wlxmlNode).dom();
     },
 
     setupEventHandling: function() {
@@ -151,8 +177,8 @@ $.extend(Canvas.prototype, {
 
                     //textElement.data('wlxmlNode').setText(toSet);
                     //textElement.data('wlxmlNode').document.transform('setText', {node: textElement.data('wlxmlNode'), text: toSet});
-                    if(textElement.data('wlxmlNode').getText() !== toSet) {
-                        canvas.textHandler.handle(textElement.data('wlxmlNode'), toSet);
+                    if(textElement.wlxmlNode.getText() !== toSet) {
+                        canvas.textHandler.handle(textElement.wlxmlNode, toSet);
                     }
                 }
             });
@@ -199,7 +225,7 @@ $.extend(Canvas.prototype, {
         if(this.d === null) {
             return null;
         }
-        return documentElement.DocumentNodeElement.fromHTMLElement(this.d.get(0), this); //{wlxmlTag: this.d.prop('tagName')};
+        return this.getDocumentElement(this.d[0]);
     },
 
     toggleElementHighlight: function(node, toggle) {
@@ -207,27 +233,23 @@ $.extend(Canvas.prototype, {
         element.toggleHighlight(toggle);
     },
 
-    createNodeElement: function(params) {
-        return documentElement.DocumentNodeElement.create(params, this);
-    },
-
-    getDocumentElement: function(from) {
-        /* globals HTMLElement, Text */
-        if(from instanceof HTMLElement || from instanceof Text) {
-           return documentElement.DocumentElement.fromHTMLElement(from, this);
-        }
-    },
     getCursor: function() {
         return new Cursor(this);
     },
 
     
     getCurrentNodeElement: function() {
-        return this.getDocumentElement(this.wrapper.find('.current-node-element').parent()[0]);
+        var htmlElement = this.wrapper.find('.current-node-element').parent()[0];
+        if(htmlElement) {
+            return this.getDocumentElement(htmlElement);
+        }
     },
 
     getCurrentTextElement: function() {
-        return this.getDocumentElement(this.wrapper.find('.current-text-element')[0]);
+        var htmlElement = this.wrapper.find('.current-text-element')[0];
+        if(htmlElement) {
+            return this.getDocumentElement(htmlElement);
+        }
     },
 
     contains: function(element) {
@@ -285,7 +307,7 @@ $.extend(Canvas.prototype, {
                 this._moveCaretToTextElement(textElementToLand, params.caretTo); // as method on element?
             }
             if(!(textElementToLand.sameNode(currentTextElement))) {
-                this.publisher('currentTextElementSet', textElementToLand.data('wlxmlNode'));
+                this.publisher('currentTextElementSet', textElementToLand.wlxmlNode);
             }
         } else {
             document.getSelection().removeAllRanges();
@@ -294,7 +316,7 @@ $.extend(Canvas.prototype, {
         if(!(currentNodeElement && currentNodeElement.sameNode(nodeElementToLand))) {
             _markAsCurrent(nodeElementToLand);
 
-            this.publisher('currentNodeElementSet', nodeElementToLand.data('wlxmlNode'));
+            this.publisher('currentNodeElementSet', nodeElementToLand.wlxmlNode);
         }
     },
 
index 67f59b6..346a82b 100644 (file)
@@ -33,6 +33,7 @@ describe('new Canvas', function() {
 
         expect(c.doc().children()).to.have.length(3);
         expect(c.doc().children()[0].canvas).to.equal(c);
+        expect(c.doc().children()[0].wlxmlNode.sameNode(doc.root));
     });
 });
 
@@ -57,7 +58,7 @@ describe('Handling changes to the document', function() {
             c = canvas.fromXMLDocument(doc);
 
         var header = doc.root.replaceWith({tagName: 'header'});
-        expect(c.doc().data('wlxmlNode').sameNode(header)).to.equal(true);
+        expect(c.doc().wlxmlNode.sameNode(header)).to.equal(true);
     });
 });
 
@@ -103,7 +104,7 @@ describe('Listening to document changes', function() {
 
         /* Make sure we handle invalidation of reference to wlxmlNode after changing its tag */
         expect(headerNode.getData('canvasElement').sameNode(headerElement)).to.equal(true, 'node->element');
-        expect(headerElement.data('wlxmlNode').sameNode(headerNode)).to.equal(true, 'element->node');
+        expect(headerElement.wlxmlNode.sameNode(headerNode)).to.equal(true, 'element->node');
     });
 
     it('Handles nodeDetached event for an empty text node', function(done) {
@@ -119,7 +120,7 @@ describe('Listening to document changes', function() {
         wait(function() {
             var parent = aTextElement.parent();
             expect(aTextElement.getText({raw:true})).to.equal(utils.unicode.ZWS, 'canvas represents this as empty node');
-            aTextElement.data('wlxmlNode').detach();
+            aTextElement.wlxmlNode.detach();
             expect(parent.children().length).to.equal(1);
             expect(parent.children()[0].getWlxmlTag()).to.equal('span');
             done();
index 7f448ba..afa510f 100644 (file)
@@ -10,58 +10,28 @@ define([
 
 
 // DocumentElement represents a text or an element node from WLXML document rendered inside Canvas
-var DocumentElement = function(htmlElement, canvas) {
+var DocumentElement = function(wlxmlNode, canvas) {
     if(arguments.length === 0) {
         return;
     }
+    this.wlxmlNode = wlxmlNode;
     this.canvas = canvas;
-    this._setupDOMHandler(htmlElement);
-};
-
 
-var elementTypeFromWlxmlNode = function(wlxmlNode) {
-    return wlxmlNode.nodeType === Node.TEXT_NODE ? DocumentTextElement : DocumentNodeElement;
+    this.$element = this.createDOM();
+    this.$element.data('canvas-element', this);
 };
 
-$.extend(DocumentElement, {
-    create: function(node, canvas) {
-        return elementTypeFromWlxmlNode(node).create(node, canvas);
-    },
-
-    fromHTMLElement: function(htmlElement, canvas) {
-        var $element = $(htmlElement);
-        if(htmlElement.nodeType === Node.ELEMENT_NODE && $element.attr('document-node-element') !== undefined) {
-            return DocumentNodeElement.fromHTMLElement(htmlElement, canvas);
-        }
-        if($element.attr('document-text-element') !== undefined || (htmlElement.nodeType === Node.TEXT_NODE && $element.parent().attr('document-text-element') !== undefined)) {
-            return DocumentTextElement.fromHTMLElement(htmlElement, canvas);
-        }
-        return undefined;
-    }
-});
-
 $.extend(DocumentElement.prototype, {
-    _setupDOMHandler: function(htmlElement) {
-        this.$element = $(htmlElement);
-    },
     bound: function() {
         return $.contains(document.documentElement, this.dom()[0]);
     },
     dom: function() {
         return this.$element;
     },
-    data: function() {
-        var dom = this.dom(),
-            args = Array.prototype.slice.call(arguments, 0);
-        if(args.length === 2 && args[1] === undefined) {
-            return dom.removeData(args[0]);
-        }
-        return dom.data.apply(dom, arguments);
-    },
     parent: function() {
         var parents = this.$element.parents('[document-node-element]');
         if(parents.length) {
-            return DocumentElement.fromHTMLElement(parents[0], this.canvas);
+            return this.canvas.getDocumentElement(parents[0]);
         }
         return null;
     },
@@ -128,63 +98,26 @@ $.extend(DocumentElement.prototype, {
     },
 
     exec: function(method) {
-        var manager = this.data('_wlxmlManager');
-        if(manager[method]) {
-            return manager[method].apply(manager, Array.prototype.slice.call(arguments, 1));
+        if(this.manager && this.manager[method]) {
+            return this.manager[method].apply(this.manager, Array.prototype.slice.call(arguments, 1));
         }
     }
 });
 
 
 // DocumentNodeElement represents an element node from WLXML document rendered inside Canvas
-var DocumentNodeElement = function(htmlElement, canvas) {
-    DocumentElement.call(this, htmlElement, canvas);
+var DocumentNodeElement = function(wlxmlNode, canvas) {
+    DocumentElement.call(this, wlxmlNode, canvas);
+    wlxmlNode.setData('canvasElement', this);
 };
 
-$.extend(DocumentNodeElement, {
-    create: function(wlxmlNode, canvas) {
-        return this.fromHTMLElement(this.createDOM(wlxmlNode, canvas)[0], canvas);
-    },
-
-    fromHTMLElement: function(htmlElement, canvas) {
-        return new this(htmlElement, canvas);
-    },
-
-    createDOM: function(wlxmlNode, canvas) {
-        var dom = $('<div>')
-                .attr('document-node-element', ''),
-            widgetsContainer = $('<div>')
-                .addClass('canvas-widgets')
-                .attr('contenteditable', false),
-            container = $('<div>')
-                .attr('document-element-content', '');
-        
-        dom.append(widgetsContainer, container);
-        // Make sure widgets aren't navigable with arrow keys
-        widgetsContainer.find('*').add(widgetsContainer).attr('tabindex', -1);
-
-        var element = this.fromHTMLElement(dom[0], canvas);
-
-        element.data('wlxmlNode', wlxmlNode);
-        wlxmlNode.setData('canvasElement', element);
-
-        element.setWlxml({tag: wlxmlNode.getTagName(), klass: wlxmlNode.getClass()});
-
-        wlxmlNode.contents().forEach(function(node) {
-            container.append(DocumentElement.create(node, canvas).dom());
-        }.bind(this));
-
-        return dom;
-    }
-
-});
 
 var manipulate = function(e, params, action) {
     var element;
     if(params instanceof DocumentElement) {
         element = params;
     } else {
-        element = DocumentElement.create(params);
+        element = e.canvas.createElement(params);
     }
     var target = (action === 'append' || action === 'prepend') ? e._container() : e.dom();
     target[action](element.dom());
@@ -195,6 +128,26 @@ DocumentNodeElement.prototype = new DocumentElement();
 
 
 $.extend(DocumentNodeElement.prototype, {
+    createDOM: function() {
+        var dom = $('<div>')
+                .attr('document-node-element', ''),
+            widgetsContainer = $('<div>')
+                .addClass('canvas-widgets')
+                .attr('contenteditable', false),
+            container = $('<div>')
+                .attr('document-element-content', '');
+        
+        dom.append(widgetsContainer, container);
+        // Make sure widgets aren't navigable with arrow keys
+        widgetsContainer.find('*').add(widgetsContainer).attr('tabindex', -1);
+        this.$element = dom; //@!!!
+        this.setWlxml({tag: this.wlxmlNode.getTagName(), klass: this.wlxmlNode.getClass()});
+
+        this.wlxmlNode.contents().forEach(function(node) {
+            container.append(this.canvas.createElement(node).dom());
+        }.bind(this));
+        return dom;
+    },
     _container: function() {
         return this.dom().children('[document-element-content]');
     },
@@ -226,7 +179,7 @@ $.extend(DocumentNodeElement.prototype, {
         var elementContent = this._container().contents();
         var element = this;
         elementContent.each(function() {
-            var childElement = DocumentElement.fromHTMLElement(this, element.canvas);
+            var childElement = element.canvas.getDocumentElement(this);
             if(childElement === undefined) {
                 return true;
             }
@@ -291,9 +244,8 @@ $.extend(DocumentNodeElement.prototype, {
         this.__updatingWlxml = false;
     },
     _updateWlxmlManager: function() {
-        var manager = wlxmlManagers.getFor(this);
-        this.data('_wlxmlManager', manager);
-        manager.setup();
+        this.manager = wlxmlManagers.getFor(this);
+        this.manager.setup();
     },
     is: function(what) {
         if(what === 'list' && _.contains(['list.items', 'list.items.enum'], this.getWlxmlClass())) {
@@ -313,36 +265,19 @@ $.extend(DocumentNodeElement.prototype, {
     },
 
     toggle: function(toggle) {
-        var mng = this.data('_wlxmlManager');
-        if(mng) {
-            mng.toggle(toggle);
+        if(this.manager) {
+            this.manager.toggle(toggle);
         }
     }
 });
 
 
 // DocumentNodeElement represents a text node from WLXML document rendered inside Canvas
-var DocumentTextElement = function(htmlElement, canvas) {
-    DocumentElement.call(this, htmlElement, canvas);
+var DocumentTextElement = function(wlxmlTextNode, canvas) {
+    DocumentElement.call(this, wlxmlTextNode, canvas);
 };
 
 $.extend(DocumentTextElement, {
-    createDOM: function(wlxmlTextNode, canvas) {
-        var dom = $('<div>')
-            .attr('document-text-element', '')
-            .text(wlxmlTextNode.getText() || utils.unicode.ZWS),
-        element = this.fromHTMLElement(dom[0], canvas);
-        element.data('wlxmlNode', wlxmlTextNode);
-        return dom;
-    },
-
-    create: function(wlxmlTextNode, canvas) {
-        return this.fromHTMLElement(this.createDOM(wlxmlTextNode, canvas)[0], canvas);
-    },
-
-    fromHTMLElement: function(htmlElement, canvas) {
-        return new this(htmlElement, canvas);
-    },
     isContentContainer: function(htmlElement) {
         return htmlElement.nodeType === Node.TEXT_NODE && $(htmlElement).parent().is('[document-text-element]');
     }
@@ -351,14 +286,10 @@ $.extend(DocumentTextElement, {
 DocumentTextElement.prototype = new DocumentElement();
 
 $.extend(DocumentTextElement.prototype, {
-    _setupDOMHandler: function(htmlElement) {
-        var $element = $(htmlElement);
-        if(htmlElement.nodeType === Node.TEXT_NODE) {
-            this.$element = $element.parent();
-        }
-        else {
-            this.$element = $element;
-        }
+    createDOM: function() {
+        return $('<div>')
+            .attr('document-text-element', '')
+            .text(this.wlxmlNode.getText() || utils.unicode.ZWS);
     },
     detach: function() {
         this.dom().detach();
@@ -388,7 +319,7 @@ $.extend(DocumentTextElement.prototype, {
         if(params instanceof DocumentNodeElement) {
             element = params;
         } else {
-            element = DocumentElement.create(params, this.canvas);
+            element = this.canvas.createElement(params);
         }
         this.dom().wrap('<div>');
         this.dom().parent().after(element.dom());
@@ -403,7 +334,7 @@ $.extend(DocumentTextElement.prototype, {
         if(params instanceof DocumentNodeElement) {
             element = params;
         } else {
-            element = DocumentNodeElement.create(params, this.canvas);
+            element = this.canvas.createElement(params);
         }
         this.dom().wrap('<div>');
         this.dom().parent().before(element.dom());
@@ -411,27 +342,6 @@ $.extend(DocumentTextElement.prototype, {
         return element;
     },
 
-    divide: function(params) {
-        var myText = this.getText();
-
-        if(params.offset === myText.length) {
-            return this.after(params);
-        }
-        if(params.offset === 0) {
-            return this.before(params);
-        }
-
-        var lhsText = myText.substr(0, params.offset),
-            rhsText = myText.substr(params.offset),
-            newElement = DocumentNodeElement.create({tag: params.tag, klass: params.klass}, this.canvas),
-            rhsTextElement = DocumentTextElement.create({text: rhsText});
-
-        this.setText(lhsText);
-        this.after(newElement);
-        newElement.after(rhsTextElement);
-        return newElement;
-    },
-
     toggleHighlight: function() {
         // do nothing for now
     }
index 85fbd43..f879851 100644 (file)
@@ -51,7 +51,7 @@ handlers.push({key: KEYS.ENTER,
             var currentElement = canvas.getCurrentNodeElement();
             if(currentElement) {
                 canvas.wlxmlDocument.startTransaction();
-                added = currentElement.data('wlxmlNode').after({
+                added = currentElement.wlxmlNode.after({
                     tagName: currentElement.getWlxmlTag() || 'div',
                     attrs: {'class': currentElement.getWlxmlClass() || 'p'}
                 });
@@ -69,7 +69,7 @@ handlers.push({key: KEYS.ENTER,
                 }
 
                 canvas.wlxmlDocument.startTransaction();
-                added = element.data('wlxmlNode').after(
+                added = element.wlxmlNode.after(
                     {tagName: element.getWlxmlTag() || 'div', attrs: {'class': element.getWlxmlClass() || 'p'}}
                 );
                 added.append({text: ''});
@@ -101,7 +101,7 @@ handlers.push({key: KEYS.ENTER,
                 //     gotoOptions = {caretTo: 'start'};
                 // }
 
-                var result = position.element.data('wlxmlNode').breakContent({offset: position.offset}),
+                var result = position.element.wlxmlNode.breakContent({offset: position.offset}),
                     goto, gotoOptions;
                 if(result.emptyText) {
                     goto = result.emptyText;
@@ -183,7 +183,7 @@ handlers.push({keys: [KEYS.BACKSPACE, KEYS.DELETE],
         var cursor = canvas.getCursor(),
             position = canvas.getCursor().getPosition(),
             element = position.element,
-            node = element.data('wlxmlNode'),
+            node = element.wlxmlNode,
             direction = 'above',
             caretTo = 'end',
             goto;
@@ -219,11 +219,11 @@ handlers.push({keys: [KEYS.BACKSPACE, KEYS.DELETE],
 
             canvas.wlxmlDocument.deleteText({
                 from: {
-                    node: start.element.data('wlxmlNode'),
+                    node: start.element.wlxmlNode,
                     offset: start.offset
                 },
                 to: {
-                    node: end.element.data('wlxmlNode'),
+                    node: end.element.wlxmlNode,
                     offset: end.offset
                 }
             });
@@ -256,14 +256,14 @@ handlers.push({keys: [KEYS.BACKSPACE, KEYS.DELETE],
                 }
                 if(parent.children().length === 1 && parent.children()[0].sameNode(element)) {
                     if(grandParent && grandParent.children().length === 1) {
-                        goto = grandParent.data('wlxmlNode').append({text: ''});
+                        goto = grandParent.wlxmlNode.append({text: ''});
                     } else {
                         goto = element.getNearestTextElement(direction);
                     }
-                    parent.data('wlxmlNode').detach();
+                    parent.wlxmlNode.detach();
                 } else {
                     goto = element.getNearestTextElement(direction);
-                    element.data('wlxmlNode').detach();
+                    element.wlxmlNode.detach();
                 }
                 canvas.setCurrentElement(goto, {caretTo: caretTo});
             }
@@ -272,7 +272,7 @@ handlers.push({keys: [KEYS.BACKSPACE, KEYS.DELETE],
                     element = element.getNearestTextElement(direction);
                 }
                 if(element) {
-                    goto = element.data('wlxmlNode').mergeContentUp();
+                    goto = element.wlxmlNode.mergeContentUp();
                     canvas.setCurrentElement(goto.node, {caretTo: goto.offset});
                 }
                 event.preventDefault();
index 337f4d3..56093f6 100644 (file)
@@ -45,7 +45,7 @@ var findCanvasElementInParent = function(wlxmlChildNode, wlxmlParentNode) {
     } else {
         parentElement = findCanvasElement(wlxmlParentNode);
         parentElement.children().forEach(function(child) {
-            if(child.data('wlxmlNode').sameNode(wlxmlChildNode)) { // czemu tu, przy drugim undo child nie mial data?
+            if(child.wlxmlNode.sameNode(wlxmlChildNode)) { // czemu tu, przy drugim undo child nie mial data?
                 toret = child;
             }
         });
index 0ae8885..cbf8d08 100644 (file)
@@ -45,7 +45,7 @@ var handlers = {
     nodeTagChange: function(event) {
         var canvasNode = utils.findCanvasElement(event.meta.node);
         canvasNode.setWlxmlTag(event.meta.newTagName);
-        canvasNode.data('wlxmlNode', event.meta.node);
+        canvasNode.wlxmlNode = event.meta.node;
     },
     nodeAdded: function(event, checkForExistence) {
         if(event.meta.node.isRoot()) {
index a35c079..66b2ea0 100644 (file)
@@ -41,8 +41,7 @@ var DocumentElementWrapper = function(documentElement) {
         eventBus.trigger.apply(eventBus, arguments);
     };
 
-    this.node = documentElement.data('wlxmlNode');
-
+    this.node = documentElement.wlxmlNode;
 };
 
 var getDisplayStyle = function(tag, klass) {
index 55de02c..6335e0a 100644 (file)
@@ -34,7 +34,7 @@ commands.register('redo', function(canvas) {
 });
 
 commands.register('remove-node', function(canvas) {
-    canvas.getCurrentNodeElement().data('wlxmlNode').detach();
+    canvas.getCurrentNodeElement().wlxmlNode.detach();
 });
 
 commands.register('unwrap-node', function(canvas) {
@@ -45,14 +45,14 @@ commands.register('unwrap-node', function(canvas) {
         parent2 = selectionEnd.element.parent() || undefined;
 
     var selectionAnchor = cursor.getSelectionAnchor(),
-        node1 = parent1.data('wlxmlNode'),
-        node2 = parent2.data('wlxmlNode'),
+        node1 = parent1.wlxmlNode,
+        node2 = parent2.wlxmlNode,
         doc = node1.document;
     if(doc.areItemsOfSameList({node1: node1, node2: node2})) {
         doc.extractItems({item1: node1, item2: node2});
         canvas.setCurrentElement(selectionAnchor.element, {caretTo: selectionAnchor.offset});
     } else if(!cursor.isSelecting()) {
-        var nodeToUnwrap = cursor.getPosition().element.data('wlxmlNode'),
+        var nodeToUnwrap = cursor.getPosition().element.wlxmlNode,
             parentNode = nodeToUnwrap.unwrap();
         if(parentNode) {
             canvas.setCurrentElement(utils.findCanvasElement(parentNode));
@@ -67,8 +67,8 @@ commands.register('wrap-node', function(canvas) {
         parent1 = selectionStart.element.parent() || undefined,
         parent2 = selectionEnd.element.parent() || undefined;
 
-    var node1 = parent1.data('wlxmlNode'),
-        node2 = parent2.data('wlxmlNode'),
+    var node1 = parent1.wlxmlNode,
+        node2 = parent2.wlxmlNode,
         doc = node1.document;
 
     if(doc.areItemsOfSameList({node1: node1, node2: node2})) {
@@ -90,8 +90,8 @@ commands.register('list', function(canvas, params) {
         return;
     }
 
-    var node1 = parent1.data('wlxmlNode'),
-        node2 = parent2.data('wlxmlNode'),
+    var node1 = parent1.wlxmlNode,
+        node2 = parent2.wlxmlNode,
         doc = node1.document;
     
     doc.createList({node1: node1, node2: node2});
@@ -165,7 +165,7 @@ commands.register('newNodeRequested', function(canvas, params, user) {
     if(cursor.isSelecting()) {
         if(cursor.isSelectingSiblings()) {
             if(cursor.isSelectingWithinElement()) {
-                wlxmlNode = selectionStart.element.data('wlxmlNode');
+                wlxmlNode = selectionStart.element.wlxmlNode;
                 caretTo = selectionStart.offset < selectionEnd.offset ? 'start' : 'end';
 
                 insertNode(
@@ -179,7 +179,7 @@ commands.register('newNodeRequested', function(canvas, params, user) {
                 );
             }
             else {
-                wlxmlNode = selectionStart.element.data('wlxmlNode').parent();
+                wlxmlNode = selectionStart.element.wlxmlNode.parent();
                 caretTo = selectionStart.element.sameNode(cursor.getSelectionAnchor().element) ? 'end' : 'start';
 
                 insertNode(
@@ -188,7 +188,7 @@ commands.register('newNodeRequested', function(canvas, params, user) {
                             _with: {tagName: params.wlxmlTag, attrs: {'class': params.wlxmlClass}},
                             offsetStart: selectionStart.offset,
                             offsetEnd: selectionEnd.offset,
-                            textNodeIdx: [wlxmlNode.indexOf(selectionStart.element.data('wlxmlNode')), wlxmlNode.indexOf(selectionEnd.element.data('wlxmlNode'))] //parent.childIndex(selectionEnd.element)]
+                            textNodeIdx: [wlxmlNode.indexOf(selectionStart.element.wlxmlNode), wlxmlNode.indexOf(selectionEnd.element.wlxmlNode)] //parent.childIndex(selectionEnd.element)]
                         });
                     },
                     function(wrapper) {
@@ -198,8 +198,8 @@ commands.register('newNodeRequested', function(canvas, params, user) {
                 );
             }
         } else {
-            var node1 = selectionStart.element.data('wlxmlNode'),
-                node2 = selectionEnd.element.data('wlxmlNode'),
+            var node1 = selectionStart.element.wlxmlNode,
+                node2 = selectionEnd.element.wlxmlNode,
                 siblingParents = canvas.wlxmlDocument.getSiblingParents({node1: node1, node2: node2});
 
             if(siblingParents) {
@@ -215,7 +215,7 @@ commands.register('newNodeRequested', function(canvas, params, user) {
             }
         }
     } else if(canvas.getCurrentNodeElement()) {
-        wlxmlNode = canvas.getCurrentNodeElement().data('wlxmlNode');
+        wlxmlNode = canvas.getCurrentNodeElement().wlxmlNode;
 
         var linkFound = [wlxmlNode].concat(wlxmlNode.parents()).some(function(node) {
             if(node.getClass() === 'link') {
@@ -272,9 +272,9 @@ commands.register('footnote', function(canvas, params) {
         
 
     if(cursor.isSelectingWithinElement()) {
-        asideNode = position.element.data('wlxmlNode').wrapWith({tagName: 'aside', attrs:{'class': 'footnote'}, start: cursor.getSelectionStart().offset, end: cursor.getSelectionEnd().offset});
+        asideNode = position.element.wlxmlNode.wrapWith({tagName: 'aside', attrs:{'class': 'footnote'}, start: cursor.getSelectionStart().offset, end: cursor.getSelectionEnd().offset});
     } else {
-        node = position.element.data('wlxmlNode');
+        node = position.element.wlxmlNode;
         node.document.transaction(function() {
             asideNode = node.divideWithElementNode({tagName: 'aside', attrs:{'class': 'footnote'}}, {offset: position.offset});
             asideNode.append({text: ''});
@@ -295,7 +295,7 @@ commands.register('take-away-node', function(canvas) {
         return;
     }
 
-    var range = nodeElement.data('wlxmlNode').unwrapContent();
+    var range = nodeElement.wlxmlNode.unwrapContent();
 
     if(element) {
         var elementIsFirstChild = nodeElement.childIndex(element);