smartxml: Improving get/set data api
[fnpeditor.git] / src / smartxml / smartxml.js
index bac53af..1876076 100644 (file)
@@ -1,8 +1,9 @@
 define([
     'libs/jquery',
+    'libs/underscore',
     'libs/backbone',
     'smartxml/events'
-], function($, Backbone, events) {
+], function($, _, Backbone, events) {
     
 'use strict';
 
@@ -54,6 +55,22 @@ 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();
     },