X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/4bd7ae43a9d3cd78105f174d1f92c1bc92d35f02..9da575320a658b0f543c8ff4ac0ebe43fdd975e1:/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 4378e73..89ffce9 100644 --- a/src/editor/modules/documentCanvas/canvas/documentElement.js +++ b/src/editor/modules/documentCanvas/canvas/documentElement.js @@ -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) @@ -162,6 +169,9 @@ $.extend(DocumentNodeElement, { var element = this.fromHTMLElement(dom[0], canvas); + element.data('wlxmlNode', wlxmlNode); + wlxmlNode.setData('canvasElement', element); + element.setWlxml({tag: wlxmlNode.getTagName(), klass: wlxmlNode.getClass()}); _.keys(wlxmlNode.getMetaAttributes()).forEach(function(key) { @@ -257,13 +267,6 @@ $.extend(DocumentNodeElement.prototype, { element2: parent.children()[myIdx + childrenLength-1 + (moveRightRange ? 1 : 0)] }; }, - 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); - }, toXML: function(level) { var node = $('<' + this.getWlxmlTag() + '>'); @@ -477,9 +480,12 @@ var DocumentTextElement = function(htmlElement, canvas) { $.extend(DocumentTextElement, { createDOM: function(wlxmlTextNode) { - return $('
') + var dom = $('
') .attr('document-text-element', '') - .text(wlxmlTextNode.getText() || utils.unicode.ZWS); + .text(wlxmlTextNode.getText() || utils.unicode.ZWS), + element = this.fromHTMLElement(dom[0], this); + element.data('wlxmlNode', wlxmlTextNode); + return dom; }, create: function(wlxmlTextNode, canvas) { @@ -521,8 +527,13 @@ $.extend(DocumentTextElement.prototype, { prependText: function(text) { this.dom().contents()[0].data = text + this.dom().contents()[0].data; }, - getText: function() { - return this.dom().text().replace(utils.unicode.ZWS, ''); + getText: function(options) { + options = _.extend({raw: false}, options || {}); + var toret = this.dom().text(); + if(!options.raw) { + toret = toret.replace(utils.unicode.ZWS, ''); + } + return toret; }, isEmpty: function() { // Having at least Zero Width Space is guaranteed be Content Observer