From: Aleksander Ɓukasz Date: Mon, 8 Jul 2013 11:58:17 +0000 (+0200) Subject: refactoring X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/26f26828b3cad2c2c1a2f7d4d3c06c025c212f98 refactoring --- diff --git a/modules/documentCanvas/canvas/documentElement.js b/modules/documentCanvas/canvas/documentElement.js index 9fa290f..13ed6a6 100644 --- a/modules/documentCanvas/canvas/documentElement.js +++ b/modules/documentCanvas/canvas/documentElement.js @@ -69,21 +69,22 @@ var DocumentTextElement = function(htmlElement) { DocumentNodeElement.prototype = new DocumentElement(); DocumentTextElement.prototype = new DocumentElement(); +var manipulate = function(e, params, action) { + var newElement = DocumentNodeElement.createDOM(params); + e.$element[action](newElement); + return documentElementFromHTMLElement(newElement); +}; + $.extend(DocumentNodeElement.prototype, { append: function(params) { - var to_append = DocumentNodeElement.createDOM(params); - this.$element.append(to_append); - return documentElementFromHTMLElement(to_append); + manipulate(this, params, 'append'); }, before: function(params) { - var to_append = DocumentNodeElement.createDOM(params); - this.$element.before(to_append); - return documentElementFromHTMLElement(to_append); + manipulate(this, params, 'before'); + }, after: function(params) { - var to_append = DocumentNodeElement.createDOM(params); - this.$element.after(to_append); - return documentElementFromHTMLElement(to_append); + manipulate(this, params, 'after'); } });