summaryrefslogtreecommitdiffstats
path: root/src/element.js
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2015-11-06 22:08:38 +0100
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2015-11-06 22:08:38 +0100
commit2702ceb26d3021720f3ff979bcf5f46fc65699e9 (patch)
treecf24afdc5ca280e161347512469f48ba6c80dc8e /src/element.js
parent042edca2e4e25a293c8d3a55794793636af5b910 (diff)
downloadsvg.js-2702ceb26d3021720f3ff979bcf5f46fc65699e9.tar.gz
svg.js-2702ceb26d3021720f3ff979bcf5f46fc65699e9.zip
svgjs now saves crucial data in the dom (fixes #369 again)
Diffstat (limited to 'src/element.js')
-rw-r--r--src/element.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/element.js b/src/element.js
index aa75235..194886e 100644
--- a/src/element.js
+++ b/src/element.js
@@ -5,6 +5,9 @@ SVG.Element = SVG.invent({
// make stroke value accessible dynamically
this._stroke = SVG.defaults.attrs.stroke
+ // initialize data object
+ this.dom = {}
+
// create circular reference
if (this.node = node) {
this.type = node.nodeName
@@ -177,6 +180,7 @@ SVG.Element = SVG.invent({
, doc: function() {
return this instanceof SVG.Doc ? this : this.parent(SVG.Doc)
}
+ // return array of all ancestors of given type up to the root svg
, parents: function(type) {
var parents = [], parent = this
@@ -216,6 +220,9 @@ SVG.Element = SVG.invent({
// create a wrapping svg element in case of partial content
well.appendChild(svg = document.createElement('svg'))
+ // write svgjs data to the dom
+ this.writeDataToDom()
+
// insert a copy of this node
svg.appendChild(this.node.cloneNode(true))
@@ -225,5 +232,26 @@ SVG.Element = SVG.invent({
return this
}
+ // write svgjs data to the dom
+ , writeDataToDom: function() {
+
+ // dump variables recursively
+ if(this.each || this.lines){
+ var fn = this.each ? this : this.lines();
+ fn.each(function(){
+ this.writeDataToDom()
+ })
+ }
+
+ if(Object.keys(this.dom).length)
+ this.node.setAttributeNS(SVG.svgjs, 'svgjs:data', JSON.stringify(this.dom))
+
+ return this
+ }
+ // set given data to the elements data property
+ , setData: function(o){
+ this.dom = o
+ return this
+ }
}
})