X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/00d1285a2038e326246c5f5ff3bca7728f67925b..723ac1f3c7cd74605ea7103d7738daad92772515:/modules/documentCanvas/canvas/documentElement.js?ds=inline diff --git a/modules/documentCanvas/canvas/documentElement.js b/modules/documentCanvas/canvas/documentElement.js index 88287b8..d0adbc0 100644 --- a/modules/documentCanvas/canvas/documentElement.js +++ b/modules/documentCanvas/canvas/documentElement.js @@ -12,8 +12,6 @@ var DocumentElement = function(htmlElement, canvas) { return; this.canvas = canvas; this.$element = $(htmlElement); - - this.wlxmlTag = this.$element.attr('wlxml-tag'); } $.extend(DocumentElement.prototype, { @@ -49,8 +47,10 @@ $.extend(DocumentElement.prototype, { }, wrapWithNodeElement: function(wlxmlNode) { - this.$element.wrap($('<' + wlxmlNode.tag + ' class="' + wlxmlNode.klass.replace('.', '-') + '">')[0]); - return documentElementFromHTMLElement(this.$element.parent().get(0), this.canvas); + var wrapper = DocumentNodeElement.create({tag: wlxmlNode.tag, klass: wlxmlNode.klass}); + this.$element.replaceWith(wrapper.dom()); + wrapper.append(this); + return wrapper; }, childIndex: function(child) { @@ -184,18 +184,25 @@ $.extend(DocumentTextElement.prototype, { return documentElementFromHTMLElement(dom[0]); }, wrapWithNodeElement: function(wlxmlNode) { - if(wlxmlNode.start && wlxmlNode.end) { + if(typeof wlxmlNode.start === 'number' && typeof wlxmlNode.end === 'number') { return this.canvas.wrapText({ inside: this.parent(), textNodeIdx: this.parent().childIndex(this), - offsetStart: wlxmlNode.start, - offsetEnd: wlxmlNode.end, + offsetStart: Math.min(wlxmlNode.start, wlxmlNode.end), + offsetEnd: Math.max(wlxmlNode.start, wlxmlNode.end), _with: {tag: wlxmlNode.tag, klass: wlxmlNode.klass} }); } else { return DocumentElement.prototype.wrapWithNodeElement.call(this, wlxmlNode); } }, + unwrap: function() { + if(this.parent().children().length === 1) { + var parent = this.parent(); + parent.after(this); + parent.detach(); + } + }, split: function(params) { var parentElement = this.parent(), myIdx = parentElement.childIndex(this), @@ -216,9 +223,9 @@ $.extend(DocumentTextElement.prototype, { if(prefix.length > 0) this.setText(prefix); else - this.remove(); + this.detach(); - var newElement = DocumentNodeElement.create({tag: parentElement.wlxmlTag, klass: parentElement.wlxmlClass}, myCanvas); + var newElement = DocumentNodeElement.create({tag: parentElement.getWlxmlTag(), klass: parentElement.getWlxmlClass()}, myCanvas); parentElement.after(newElement); if(suffix.length > 0)