From fe1747c86d0e562853752ac2b412ed33cd109c4f Mon Sep 17 00:00:00 2001 From: wout Date: Sun, 27 Jan 2013 20:17:17 +0100 Subject: Added data() method --- src/element.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src') diff --git a/src/element.js b/src/element.js index c23ea49..3130d73 100644 --- a/src/element.js +++ b/src/element.js @@ -201,6 +201,20 @@ SVG.extend(SVG.Element, { /* add only te required transformations */ return this.attr('transform', transform.join(' ')); }, + // Store data values on svg nodes + data: function(a, v) { + if (arguments.length < 2) { + var value = this.attr('data-' + a); + return value ? JSON.parse(value) : value; + + } else { + v === null ? + this.node.removeAttribute('data-' + a) : + this.attr('data-' + a, JSON.stringify(v)); + } + + return this; + }, // Get bounding box bbox: function() { /* actual, native bounding box */ -- cgit v1.2.3