detach: function() { this._$.detach(); },
sameNode: function(otherNode) {
- return this.nativeNode === otherNode.nativeNode;
+ return otherNode && this.nativeNode === otherNode.nativeNode;
},
parent: function() {
},
wrapWith: function(node) {
+ node = node instanceof ElementNode ? node : this.document.createElementNode(node);
+
if(this.parent()) {
this.before(node);
}
node.append(this);
+ return node;
},
triggerChangeEvent: function(type, metaData) {
setTag: function(tagName) {
var node = this.document.createElementNode({tagName: tagName}),
- oldTagName = this.getTagName();
+ oldTagName = this.getTagName(),
+ myContents = this._$.contents();
this.getAttrs().forEach(function(attribute) {
node.setAttr(attribute.name, attribute.value, true);
}
this._$.replaceWith(node._$);
this._setNativeNode(node._$[0]);
+ this._$.append(myContents);
this.triggerChangeEvent('nodeTagChange', {oldTagName: oldTagName, newTagName: this.getTagName()});
},
toXML: function() {
var wrapper = $('<div>');
- wrapper.append(this._$);
+ wrapper.append(this._getXMLDOMToDump());
return wrapper.html();
+ },
+
+ _getXMLDOMToDump: function() {
+ return this._$;
}
});
return this.nativeNode.data;
},
+ setText: function(text) {
+ this.nativeNode.data = text;
+ this.triggerTextChangeEvent();
+ },
+
appendText: function(text) {
this.nativeNode.data = this.nativeNode.data + text;
+ this.triggerTextChangeEvent();
},
prependText: function(text) {
this.nativeNode.data = text + this.nativeNode.data;
+ this.triggerTextChangeEvent();
+ },
+
+ triggerTextChangeEvent: function() {
+ var event = new events.ChangeEvent('nodeTextChange', {node: this});
+ this.document.trigger('change', event);
}
});
createElementNode: function(from) {
if(!(from instanceof HTMLElement)) {
- from = $('<' + from.tagName + '>');
+ from = $('<' + from.tagName + '>')[0];
}
return new this.ElementNodeFactory(from, this);
},
return new this.TextNodeFactory(nativeNode, this);
},
- loadXML: function(xml) {
+ loadXML: function(xml, options) {
+ options = options || {};
defineDocumentProperties(this, $(parseXML(xml)));
-
- this.trigger('contentSet');
+ if(!options.silent) {
+ this.trigger('contentSet');
+ }
},
toXML: function() {