fnp
/
fnpeditor.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
smartxml: allow for setting metadata on nodes
[fnpeditor.git]
/
src
/
smartxml
/
smartxml.js
diff --git
a/src/smartxml/smartxml.js
b/src/smartxml/smartxml.js
index
477166b
..
034b907
100644
(file)
--- a/
src/smartxml/smartxml.js
+++ b/
src/smartxml/smartxml.js
@@
-1,6
+1,8
@@
define([
define([
- 'libs/jquery'
-], function($) {
+ 'libs/jquery',
+ 'libs/backbone',
+ 'smartxml/events'
+], function($, Backbone, events) {
'use strict';
'use strict';
@@
-38,6
+40,11
@@
$.extend(DocumentNode.prototype, {
}
node.append(this);
},
}
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) {
});
var ElementNode = function(nativeNode, document) {
@@
-47,6
+54,13
@@
var ElementNode = function(nativeNode, document) {
$.extend(ElementNode.prototype, DocumentNode.prototype, {
nodeType: Node.ELEMENT_NODE,
$.extend(ElementNode.prototype, DocumentNode.prototype, {
nodeType: Node.ELEMENT_NODE,
+ setData: function(key, value) {
+ this._$.data(key, value);
+ },
+ getData: function(key) {
+ return this._$.data(key);
+ },
+
getTagName: function() {
return this.nativeNode.tagName.toLowerCase();
},
getTagName: function() {
return this.nativeNode.tagName.toLowerCase();
},
@@
-74,7
+88,9
@@
$.extend(ElementNode.prototype, DocumentNode.prototype, {
},
setAttr: function(name, value) {
},
setAttr: function(name, value) {
+ var oldVal = this.getAttr(name);
this._$.attr(name, value);
this._$.attr(name, value);
+ this.triggerChangeEvent('nodeAttrChange', {attr: name, oldVal: oldVal, newVal: value});
},
getAttrs: function() {
},
getAttrs: function() {
@@
-178,7
+194,7
@@
var Document = function(xml) {
return $document[0];
}});
};
return $document[0];
}});
};
-$.extend(Document.prototype, {
+$.extend(Document.prototype,
Backbone.Events,
{
ElementNodeFactory: ElementNode,
TextNodeFactory: TextNode,
ElementNodeFactory: ElementNode,
TextNodeFactory: TextNode,