return this.nativeNode.parentNode ? this.document.createElementNode(this.nativeNode.parentNode) : null;
},
+ after: function(node) {
+ node = node instanceof ElementNode ? node : this.document.createElementNode(node);
+ this._$.after(node.nativeNode);
+ return node;
+ },
+
before: function(node) {
+ node = node instanceof ElementNode ? node : this.document.createElementNode(node);
this._$.before(node.nativeNode);
+ return node;
},
wrapWith: function(node) {
var ElementNode = function(nativeNode, document) {
DocumentNode.call(this, nativeNode, document);
};
+ElementNode.prototype = Object.create(DocumentNode.prototype);
-$.extend(ElementNode.prototype, DocumentNode.prototype, {
+$.extend(ElementNode.prototype, {
nodeType: Node.ELEMENT_NODE,
setData: function(key, value) {
var TextNode = function(nativeNode, document) {
DocumentNode.call(this, nativeNode, document);
};
+TextNode.prototype = Object.create(DocumentNode.prototype);
-$.extend(TextNode.prototype, DocumentNode.prototype, {
+$.extend(TextNode.prototype, {
nodeType: Node.TEXT_NODE,
getText: function() {
createElementNode: function(from) {
if(!(from instanceof HTMLElement)) {
- from = $('<' + from.tagName + '>')[0];
+ if(from.text) {
+ from = document.createTextNode(from.text);
+ } else {
+ from = $('<' + from.tagName + '>')[0];
+ }
}
return new this.ElementNodeFactory(from, this);
},