diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2017-07-25 14:19:49 +0200 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2017-07-25 14:19:49 +0200 |
commit | ee0b340bfeb2430767d4a2850413f864c42e5405 (patch) | |
tree | 7cb4fe28d59643b2054edd6ae5c33ed8d2b33987 /src/svg.js | |
parent | d6d389133409b315bc1b74752f58ef2647033bb9 (diff) | |
download | svg.js-ee0b340bfeb2430767d4a2850413f864c42e5405.tar.gz svg.js-ee0b340bfeb2430767d4a2850413f864c42e5405.zip |
add new default constructor (#714)
Diffstat (limited to 'src/svg.js')
-rw-r--r-- | src/svg.js | 21 |
1 files changed, 6 insertions, 15 deletions
@@ -53,8 +53,8 @@ SVG.invent = function(config) { // Create element initializer var initializer = typeof config.create == 'function' ? config.create : - function() { - this.constructor.call(this, SVG.create(config.create)) + function(node) { + this.constructor.call(this, node || SVG.create(config.create)) } // Inherit prototype @@ -88,25 +88,16 @@ SVG.adopt = function(node) { // adopt with element-specific settings if (node.nodeName == 'svg') - element = node.parentNode instanceof window.SVGElement ? new SVG.Nested : new SVG.Doc + element = node.parentNode instanceof window.SVGElement ? new SVG.Nested(node) : new SVG.Doc(node) else if (node.nodeName == 'linearGradient') - element = new SVG.Gradient('linear') + element = new SVG.Gradient(node) else if (node.nodeName == 'radialGradient') - element = new SVG.Gradient('radial') + element = new SVG.Gradient(node) else if (SVG[capitalize(node.nodeName)]) - element = new SVG[capitalize(node.nodeName)] + element = new SVG[capitalize(node.nodeName)](node) else element = new SVG.Parent(node) - // ensure references - element.type = node.nodeName - element.node = node - node.instance = element - - // SVG.Class specific preparations - if (element instanceof SVG.Doc) - element.namespace().defs() - // pull svgjs data from the dom (getAttributeNS doesn't work in html5) element.setData(JSON.parse(node.getAttribute('svgjs:data')) || {}) |