X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/efe36f4f1b5df351eeb4d40a54c3900cf9a7079b..24ac4f5092661ce053f33d460306bf81d6a3dc8a:/src/editor/modules/documentCanvas/canvas/documentElement.js diff --git a/src/editor/modules/documentCanvas/canvas/documentElement.js b/src/editor/modules/documentCanvas/canvas/documentElement.js index 0627bc1..cd6b3d8 100644 --- a/src/editor/modules/documentCanvas/canvas/documentElement.js +++ b/src/editor/modules/documentCanvas/canvas/documentElement.js @@ -18,18 +18,18 @@ var DocumentElement = function(htmlElement, canvas) { this._setupDOMHandler(htmlElement); } -var elementTypeFromParams = function(params) { - return params.text !== undefined ? DocumentTextElement : DocumentNodeElement; -}; +var elementTypeFromWlxmlNode = function(wlxmlNode) { + return wlxmlNode.nodeType === Node.TEXT_NODE ? DocumentTextElement : DocumentNodeElement; +} $.extend(DocumentElement, { - create: function(params, canvas) { - return elementTypeFromParams(params).create(params); + create: function(node, canvas) { + return elementTypeFromWlxmlNode(node).create(node, canvas); }, - createDOM: function(params) { - return elementTypeFromParams(params).createDOM(params); + createDOM: function(wlxmlNode) { + return elementTypeFromParams(wlxmlNode).createDOM(params); }, fromHTMLElement: function(htmlElement, canvas) { @@ -52,6 +52,13 @@ $.extend(DocumentElement.prototype, { 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) @@ -139,7 +146,15 @@ var DocumentNodeElement = function(htmlElement, canvas) { }; $.extend(DocumentNodeElement, { - createDOM: function(params, canvas) { + 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 = $('