summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2017-07-28 14:20:48 +0200
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2017-07-28 14:20:48 +0200
commit6faf2c538a90e99e5fadd8662955466ba4ebe6f1 (patch)
tree86527be80ae580bad129a66366e5700ca75b83d5 /src
parentecea84ea3ae7f9986144c4fbd70994cfb9925654 (diff)
downloadsvg.js-6faf2c538a90e99e5fadd8662955466ba4ebe6f1.tar.gz
svg.js-6faf2c538a90e99e5fadd8662955466ba4ebe6f1.zip
The dom is checked for an svgjs:data attribute which is imported when creating an element
Diffstat (limited to 'src')
-rw-r--r--src/element.js9
-rw-r--r--src/svg.js7
2 files changed, 8 insertions, 8 deletions
diff --git a/src/element.js b/src/element.js
index 7c95156..c9b3fd7 100644
--- a/src/element.js
+++ b/src/element.js
@@ -12,6 +12,11 @@ SVG.Element = SVG.invent({
if (this.node = node) {
this.type = node.nodeName
this.node.instance = this
+
+ if(node.hasAttribute('svgjs:data')) {
+ // pull svgjs data from the dom (getAttributeNS doesn't work in html5)
+ this.setData(JSON.parse(node.getAttribute('svgjs:data')) || {})
+ }
}
}
@@ -98,7 +103,7 @@ SVG.Element = SVG.invent({
if(typeof id == 'undefined' && !this.node.id) {
this.node.id = SVG.eid(this.type)
}
-
+
// dont't set directly width this.node.id to make `null` work correctly
return this.attr('id', id)
}
@@ -233,7 +238,7 @@ SVG.Element = SVG.invent({
} else {
// write svgjs data to the dom
this.writeDataToDom()
-
+
return this.node.outerHTML
}
diff --git a/src/svg.js b/src/svg.js
index 3441348..ea27c5c 100644
--- a/src/svg.js
+++ b/src/svg.js
@@ -89,17 +89,12 @@ SVG.adopt = function(node) {
// adopt with element-specific settings
if (node.nodeName == 'svg')
element = node.parentNode instanceof window.SVGElement ? new SVG.Nested(node) : new SVG.Doc(node)
- else if (node.nodeName == 'linearGradient')
- element = new SVG.Gradient(node)
- else if (node.nodeName == 'radialGradient')
+ else if (node.nodeName == 'linearGradient' || node.nodeName == 'radialGradient')
element = new SVG.Gradient(node)
else if (SVG[capitalize(node.nodeName)])
element = new SVG[capitalize(node.nodeName)](node)
else
element = new SVG.Parent(node)
- // pull svgjs data from the dom (getAttributeNS doesn't work in html5)
- element.setData(JSON.parse(node.getAttribute('svgjs:data')) || {})
-
return element
}