From 26f26828b3cad2c2c1a2f7d4d3c06c025c212f98 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Mon, 8 Jul 2013 13:58:17 +0200 Subject: [PATCH 1/1] refactoring --- .../documentCanvas/canvas/documentElement.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) 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'); } }); -- 2.20.1