From 6faf2c538a90e99e5fadd8662955466ba4ebe6f1 Mon Sep 17 00:00:00 2001 From: Ulrich-Matthias Schäfer Date: Fri, 28 Jul 2017 14:20:48 +0200 Subject: The dom is checked for an svgjs:data attribute which is imported when creating an element --- src/element.js | 9 +++++++-- src/svg.js | 7 +------ 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src') 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 } -- cgit v1.2.3