X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/ecf3b34e969acfeeb5d09b7287b233ce4bffed83..739242f6208f3e58570194fb1000086bafd527ef:/modules/documentCanvas/canvas/documentElement.js diff --git a/modules/documentCanvas/canvas/documentElement.js b/modules/documentCanvas/canvas/documentElement.js index 749a2ef..cfdac5d 100644 --- a/modules/documentCanvas/canvas/documentElement.js +++ b/modules/documentCanvas/canvas/documentElement.js @@ -83,6 +83,7 @@ $.extend(DocumentElement.prototype, { detach: function() { this.dom().detach(); this.canvas = null; + return this; }, markAsCurrent: function() { @@ -165,7 +166,7 @@ var manipulate = function(e, params, action) { } else { element = DocumentElement.create(params); } - var target = action === 'append' ? e._container() : e.dom(); + var target = (action === 'append' || action === 'prepend') ? e._container() : e.dom(); target[action](element.dom()); return element; }; @@ -257,6 +258,9 @@ $.extend(DocumentNodeElement.prototype, { this.data('orig-end', undefined); return manipulate(this, params, 'append'); }, + prepend: function(params) { + return manipulate(this, params, 'prepend'); + }, before: function(params) { return manipulate(this, params, 'before'); @@ -475,6 +479,10 @@ $.extend(DocumentTextElement.prototype, { idx = grandParent.childIndex(parent), prev = idx - 1 > -1 ? grandParentChildren[idx-1] : null, next = idx + 1 < grandParentChildren.length ? grandParentChildren[idx+1] : null; + + prev = (prev instanceof DocumentTextElement) ? prev : null; + next = (next instanceof DocumentTextElement) ? next : null; + if(prev && next) { prev.setText(prev.getText() + this.getText() + next.getText()); next.detach();