define([
- 'libs/jquery'
-], function($) {
+ 'libs/jquery',
+ 'libs/underscore',
+ 'libs/backbone',
+ 'smartxml/events'
+], function($, _, Backbone, events) {
'use strict';
}
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) {
$.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();
},
},
setAttr: function(name, value) {
+ var oldVal = this.getAttr(name);
this._$.attr(name, value);
+ this.triggerChangeEvent('nodeAttrChange', {attr: name, oldVal: oldVal, newVal: value});
},
getAttrs: function() {
return $document[0];
}});
};
-$.extend(Document.prototype, {
+$.extend(Document.prototype, Backbone.Events, {
ElementNodeFactory: ElementNode,
TextNodeFactory: TextNode,