X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/efe36f4f1b5df351eeb4d40a54c3900cf9a7079b..7e4209de3c2972b1ca4ada5e3de85197365f58af:/src/editor/modules/documentCanvas/canvas/documentElement.js?ds=sidebyside diff --git a/src/editor/modules/documentCanvas/canvas/documentElement.js b/src/editor/modules/documentCanvas/canvas/documentElement.js index 0627bc1..1c0719f 100644 --- a/src/editor/modules/documentCanvas/canvas/documentElement.js +++ b/src/editor/modules/documentCanvas/canvas/documentElement.js @@ -1,11 +1,10 @@ define([ 'libs/jquery', 'libs/underscore', -'modules/documentCanvas/classAttributes', 'modules/documentCanvas/canvas/utils', 'modules/documentCanvas/canvas/widgets', 'modules/documentCanvas/canvas/wlxmlManagers' -], function($, _, classAttributes, utils, widgets, wlxmlManagers) { +], function($, _, utils, widgets, wlxmlManagers) { 'use strict'; @@ -18,18 +17,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 +51,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) @@ -73,13 +79,6 @@ $.extend(DocumentElement.prototype, { return other && (typeof other === typeof this) && other.dom()[0] === this.dom()[0]; }, - wrapWithNodeElement: function(wlxmlNode) { - var wrapper = DocumentNodeElement.create({tag: wlxmlNode.tag, klass: wlxmlNode.klass}, this); - this.dom().replaceWith(wrapper.dom()); - wrapper.append(this); - return wrapper; - }, - markAsCurrent: function() { this.canvas.markAsCurrent(this); }, @@ -139,7 +138,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 = $('