X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/35abf5d5c78b517329e313b1158f8b980940acd6..20ce93fdd697712c5b085145d85db9bb1b632f58:/modules/documentCanvas/canvas/documentElement.js diff --git a/modules/documentCanvas/canvas/documentElement.js b/modules/documentCanvas/canvas/documentElement.js index cd94759..3f6a208 100644 --- a/modules/documentCanvas/canvas/documentElement.js +++ b/modules/documentCanvas/canvas/documentElement.js @@ -38,6 +38,11 @@ $.extend(DocumentElement.prototype, { sameNode: function(other) { return other && (typeof other === typeof this) && other.$element[0] === this.$element[0]; + }, + + wrapWithNodeElement: function(wlxmlNode) { + this.$element.wrap($('<' + wlxmlNode.tag + ' class="' + wlxmlNode.klass + '"">')[0]); + return documentElementFromHTMLElement(this.$element.parent().get(0)); } }); @@ -52,6 +57,23 @@ var DocumentTextElement = function(htmlElement) { DocumentNodeElement.prototype = new DocumentElement(); DocumentTextElement.prototype = new DocumentElement(); +$.extend(DocumentNodeElement.prototype, { + append: function(params) { + var to_append = $('<' + params.tag + '>'); + if(params.klass) + to_append.attr('class', params.klass); + this.$element.append(to_append); + return documentElementFromHTMLElement(to_append); + }, + after: function(params) { + var to_append = $('<' + params.tag + '>'); + if(params.klass) + to_append.attr('class', params.klass); + this.$element.after(to_append); + return documentElementFromHTMLElement(to_append); + } +}) + var documentElementFromHTMLElement = function(htmlElement) { if(htmlElement.nodeType === Node.ELEMENT_NODE) return new DocumentNodeElement(htmlElement);