+ wrapWith: function(node) {
+ if(this.parent()) {
+ this.before(node);
+ }
+ node.append(this);
+ },
+
+ triggerChangeEvent: function(type, metaData) {
+ var event = new events.ChangeEvent(type, $.extend({node: this}, metaData || {}));
+ this.document.trigger('change', event);
+ },
+});
+
+var ElementNode = function(nativeNode, document) {
+ DocumentNode.call(this, nativeNode, document);
+};
+
+$.extend(ElementNode.prototype, DocumentNode.prototype, {
+ nodeType: Node.ELEMENT_NODE,
+
+ setData: function(key, value) {
+ if(value !== undefined) {
+ this._$.data(key, value);
+ } else {
+ this._$.removeData(_.keys(this._$.data()));
+ this._$.data(key);
+ }
+ },
+
+ getData: function(key) {
+ if(key) {
+ return this._$.data(key);
+ }
+ return this._$.data();
+ },
+
+ getTagName: function() {
+ return this.nativeNode.tagName.toLowerCase();
+ },
+
+ contents: function() {
+ var toret = [],
+ document = this.document;
+ this._$.contents().each(function() {
+ if(this.nodeType === Node.ELEMENT_NODE) {
+ toret.push(document.createElementNode(this));
+ }
+ else if(this.nodeType === Node.TEXT_NODE) {
+ toret.push(document.createTextNode(this));
+ }
+ });
+ return toret;
+ },
+
+ indexOf: function(node) {
+ return this._$.contents().index(node._$);
+ },
+
+ setTag: function(tagName) {
+ var node = this.document.createElementNode({tagName: tagName}),
+ oldTagName = this.getTagName();
+
+ this.getAttrs().forEach(function(attribute) {
+ node.setAttr(attribute.name, attribute.value, true);