});
node.setData(this.getData());
+ if(this.sameNode(this.document.root)) {
+ defineDocumentProperties(this.document, node._$);
+ }
this._$.replaceWith(node._$);
this._setNativeNode(node._$[0]);
this.triggerChangeEvent('nodeTagChange', {oldTagName: oldTagName, newTagName: this.getTagName()});
},
loadXML: function(xml) {
- var $document = $(parseXML(xml));
-
- var doc = this;
- Object.defineProperty(this, 'root', {get: function() {
- return doc.createElementNode($document[0]);
- }, configurable: true});
- Object.defineProperty(this, 'dom', {get: function() {
- return $document[0];
- }, configurable: true});
+ defineDocumentProperties(this, $(parseXML(xml)));
this.trigger('contentSet');
},
}
});
+var defineDocumentProperties = function(doc, $document) {
+ Object.defineProperty(doc, 'root', {get: function() {
+ return doc.createElementNode($document[0]);
+ }, configurable: true});
+ Object.defineProperty(doc, 'dom', {get: function() {
+ return $document[0];
+ }, configurable: true});
+};
return {
documentFromXML: function(xml) {
expect(node.getTagName()).to.equal('header');
expect(node.getData()).to.eql({key: 'value'});
});
+
+ it('can change document root tag name', function() {
+ var doc = getDocumentFromXML('<div></div>');
+ doc.root.setTag('span');
+ expect(doc.root.getTagName()).to.equal('span');
+ });
});