}),
wrapWith: function(node) {
- node = node instanceof ElementNode ? node : this.document.createElementNode(node);
-
+ var insertion = this.getNodeInsertion(node);
if(this.parent()) {
- this.before(node);
+ this.before(insertion.ofNode);
+ }
+ insertion.ofNode.append(this);
+ return insertion.ofNode;
+ },
+
+ /**
+ * Removes parent of a node if node has no siblings.
+ */
+ unwrap: function() {
+ if(this.isRoot()) {
+ return;
+ }
+ var parent = this.parent(),
+ grandParent;
+ if(parent.contents().length === 1) {
+ grandParent = parent.parent();
+ parent.unwrapContent();
+ return grandParent;
}
- node.append(this);
- return node;
},
triggerChangeEvent: function(type, metaData) {
},
getIndex: function() {
+ if(this.isRoot()) {
+ return 0;
+ }
return this.parent().indexOf(this);
}
});
myContents = this.contents(),
myIdx = parent.indexOf(this);
+
if(myContents.length === 0) {
return this.detach();
}
};
},
- /**
- * Removes parent of a node if node has no siblings.
- */
- unwrap: function() {
- if(this.isRoot()) {
- return;
- }
- var parent = this.parent(),
- grandParent;
- if(parent.contents().length === 1) {
- grandParent = parent.parent();
- parent.unwrapContent();
- return grandParent;
- }
- },
-
wrapText: function(params) {
return this.document._wrapText(_.extend({inside: this}, params));
},