X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/8095e9703888ebe28d96a094905e43eebccb6676..24e73bdbeb5e83ff18d2f9b359e7b41fe8230c1a:/src/smartxml/smartxml.js?ds=sidebyside diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index 2d0e09f..43e3041 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -29,7 +29,21 @@ $.extend(DocumentNode.prototype, { sameNode: function(otherNode) { return this.nativeNode === otherNode.nativeNode; - } + }, + + parent: function() { + return this.nativeNode.parentNode ? new ElementNode(this.nativeNode.parentNode) : null; + }, + + before: function(node) { + this._$.before(node.nativeNode); + }, + + wrapWith: function(node) { + if(this.parent()) + this.before(node); + node.append(this); + }, }); var ElementNode = function(nativeNode) { @@ -43,14 +57,6 @@ $.extend(ElementNode.prototype, DocumentNode.prototype, { return this.nativeNode.tagName.toLowerCase(); }, - append: function(documentNode) { - this._$.append(documentNode.nativeNode); - }, - - before: function(node) { - this._$.before(node.nativeNode); - }, - contents: function() { var toret = []; this._$.contents().each(function() { @@ -66,8 +72,16 @@ $.extend(ElementNode.prototype, DocumentNode.prototype, { return this._$.contents().index(node._$); }, - parent: function() { - return new ElementNode(this._$.parent()); + getAttr: function(name) { + return this._$.attr(name); + }, + + setAttr: function(name, value) { + this._$.attr(name, value); + }, + + append: function(documentNode) { + this._$.append(documentNode.nativeNode); }, unwrapContent: function() {