aboutsummaryrefslogtreecommitdiffstats
path: root/src/svg.js
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2017-07-25 14:19:49 +0200
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2017-07-25 14:19:49 +0200
commitee0b340bfeb2430767d4a2850413f864c42e5405 (patch)
tree7cb4fe28d59643b2054edd6ae5c33ed8d2b33987 /src/svg.js
parentd6d389133409b315bc1b74752f58ef2647033bb9 (diff)
downloadsvg.js-ee0b340bfeb2430767d4a2850413f864c42e5405.tar.gz
svg.js-ee0b340bfeb2430767d4a2850413f864c42e5405.zip
add new default constructor (#714)
Diffstat (limited to 'src/svg.js')
-rw-r--r--src/svg.js21
1 files changed, 6 insertions, 15 deletions
diff --git a/src/svg.js b/src/svg.js
index 61d557e..3441348 100644
--- a/src/svg.js
+++ b/src/svg.js
@@ -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')) || {})