X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/27aad148fb13a6705a8fd91ea693bd8ea46da396..b2ed6c0477904d9bcbf8494043f231a5197f6b78:/modules/documentCanvas/canvas/documentElement.js?ds=sidebyside diff --git a/modules/documentCanvas/canvas/documentElement.js b/modules/documentCanvas/canvas/documentElement.js index cfdac5d..4a236df 100644 --- a/modules/documentCanvas/canvas/documentElement.js +++ b/modules/documentCanvas/canvas/documentElement.js @@ -80,12 +80,6 @@ $.extend(DocumentElement.prototype, { return wrapper; }, - detach: function() { - this.dom().detach(); - this.canvas = null; - return this; - }, - markAsCurrent: function() { this.canvas.markAsCurrent(this); }, @@ -178,6 +172,24 @@ $.extend(DocumentNodeElement.prototype, { _container: function() { return this.dom().children('[document-element-content]'); }, + detach: function() { + var parent = this.parent(); + if(!parent) + return; + + var parentChildren = parent.children(), + myIdx = parent.childIndex(this); + + if(myIdx > 0 && myIdx < parentChildren.length) { + if((parentChildren[myIdx-1] instanceof DocumentTextElement) && (parentChildren[myIdx+1] instanceof DocumentTextElement)) { + parentChildren[myIdx-1].appendText(parentChildren[myIdx+1].getText()); + parentChildren[myIdx+1].detach(); + } + } + this.dom().detach(); + this.canvas = null; + return this; + }, data: function() { var dom = this.dom(), args = Array.prototype.slice.call(arguments, 0); @@ -367,8 +379,8 @@ $.extend(DocumentNodeElement.prototype, { this.toggleHighlight(toggle); }, - toggleHighlight: function(toogle) { - this._container().toggleClass('highlighted-element'); + toggleHighlight: function(toggle) { + this._container().toggleClass('highlighted-element', toggle); }, toggle: function(toggle) { @@ -417,9 +429,17 @@ $.extend(DocumentTextElement.prototype, { else this.$element = $element; }, + detach: function() { + this.dom().detach(); + this.canvas = null; + return this; + }, setText: function(text) { this.dom().contents()[0].data = text; }, + appendText: function(text) { + this.dom().contents()[0].data += text; + }, getText: function() { return this.dom().text().replace(utils.unicode.ZWS, ''); },