X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/2ee6a5d07d57b868eb91c59cb633732771f08b77..60c827deca03f56b138fddbd22d42d0ba52dcdc5:/modules/documentCanvas/canvas/documentElement.js diff --git a/modules/documentCanvas/canvas/documentElement.js b/modules/documentCanvas/canvas/documentElement.js index 637da5f..35ffeea 100644 --- a/modules/documentCanvas/canvas/documentElement.js +++ b/modules/documentCanvas/canvas/documentElement.js @@ -31,6 +31,18 @@ $.extend(DocumentElement.prototype, { toret.push(element); }); return toret; + }, + parent: function() { + return documentElementFromHTMLElement(this.$element.parent()[0]); + }, + + 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)); } }); @@ -45,6 +57,26 @@ var DocumentTextElement = function(htmlElement) { DocumentNodeElement.prototype = new DocumentElement(); DocumentTextElement.prototype = new DocumentElement(); +$.extend(DocumentNodeElement.prototype, { + append: function(params) { + var to_append = DocumentNodeElement.createDOM(params.tag, params.klass) + this.$element.append(to_append); + return documentElementFromHTMLElement(to_append); + }, + after: function(params) { + var to_append = DocumentNodeElement.createDOM(params.tag, params.klass) + this.$element.after(to_append); + return documentElementFromHTMLElement(to_append); + } +}) + +DocumentNodeElement.createDOM = function(tag, klass) { + var dom = $('<' + tag + '>'); + if(klass) + dom.attr('class', klass); + return dom; +} + var documentElementFromHTMLElement = function(htmlElement) { if(htmlElement.nodeType === Node.ELEMENT_NODE) return new DocumentNodeElement(htmlElement);