summaryrefslogtreecommitdiffstats
path: root/src
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
parentd6d389133409b315bc1b74752f58ef2647033bb9 (diff)
downloadsvg.js-ee0b340bfeb2430767d4a2850413f864c42e5405.tar.gz
svg.js-ee0b340bfeb2430767d4a2850413f864c42e5405.zip
add new default constructor (#714)
Diffstat (limited to 'src')
-rw-r--r--src/container.js4
-rw-r--r--src/defs.js4
-rw-r--r--src/doc.js7
-rw-r--r--src/gradient.js2
-rw-r--r--src/helpers.js6
-rw-r--r--src/parent.js4
-rw-r--r--src/shape.js6
-rw-r--r--src/svg.js21
-rw-r--r--src/text.js4
-rw-r--r--src/use.js2
10 files changed, 21 insertions, 39 deletions
diff --git a/src/container.js b/src/container.js
index 68adf93..e620041 100644
--- a/src/container.js
+++ b/src/container.js
@@ -1,7 +1,7 @@
SVG.Container = SVG.invent({
// Initialize node
- create: function(element) {
- this.constructor.call(this, element)
+ create: function(node) {
+ this.constructor.call(this, node)
}
// Inherit from
diff --git a/src/defs.js b/src/defs.js
index ad66cc5..ba96869 100644
--- a/src/defs.js
+++ b/src/defs.js
@@ -1,9 +1,7 @@
-
SVG.Defs = SVG.invent({
// Initialize node
create: 'defs'
// Inherit from
, inherit: SVG.Container
-
-}) \ No newline at end of file
+})
diff --git a/src/doc.js b/src/doc.js
index 667794d..d5bc30e 100644
--- a/src/doc.js
+++ b/src/doc.js
@@ -1,8 +1,7 @@
SVG.Doc = SVG.invent({
// Initialize node
- create: function(element) {
- element = element || SVG.create('svg')
- this.constructor.call(this, element)
+ create: function(node) {
+ this.constructor.call(this, node || SVG.create('svg'))
// set svg element attributes and ensure defs node
this.namespace().defs()
@@ -22,7 +21,7 @@ SVG.Doc = SVG.invent({
}
// Creates and returns defs element
, defs: function() {
- return this.put(this.node.getElementsByTagName('defs')[0] || new SVG.Defs)
+ return (this.node.getElementsByTagName('defs')[0] || this.put(new SVG.Defs).node).instance
}
// custom parent method
, parent: function() {
diff --git a/src/gradient.js b/src/gradient.js
index e7b1f72..4c8ed30 100644
--- a/src/gradient.js
+++ b/src/gradient.js
@@ -1,7 +1,7 @@
SVG.Gradient = SVG.invent({
// Initialize node
create: function(type) {
- this.constructor.call(this, SVG.create(type + 'Gradient'))
+ this.constructor.call(this, typeof type == 'object' ? type : SVG.create(type + 'Gradient'))
}
// Inherit from
diff --git a/src/helpers.js b/src/helpers.js
index 88a37bb..9f52431 100644
--- a/src/helpers.js
+++ b/src/helpers.js
@@ -18,12 +18,6 @@ function createElement(element, makeNested) {
element = SVG.adopt(node.firstElementChild)
- //if(element instanceof SVG.Nested) {
- // // We cant use the adopter for this because it will create an SVG.Nested
- // element = new SVG.Doc(element.node)
- // element.setData(JSON.parse(element.node.getAttribute('svgjs:data')) || {})
- //}
-
return element
}
diff --git a/src/parent.js b/src/parent.js
index 372c2ca..f8b6ee1 100644
--- a/src/parent.js
+++ b/src/parent.js
@@ -1,7 +1,7 @@
SVG.Parent = SVG.invent({
// Initialize node
- create: function(element) {
- this.constructor.call(this, element)
+ create: function(node) {
+ this.constructor.call(this, node)
}
// Inherit from
diff --git a/src/shape.js b/src/shape.js
index 3bfc210..0f7b954 100644
--- a/src/shape.js
+++ b/src/shape.js
@@ -1,10 +1,10 @@
SVG.Shape = SVG.invent({
// Initialize node
- create: function(element) {
- this.constructor.call(this, element)
+ create: function(node) {
+ this.constructor.call(this, node)
}
// Inherit from
, inherit: SVG.Element
-}) \ No newline at end of file
+})
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')) || {})
diff --git a/src/text.js b/src/text.js
index fa14894..bf37d60 100644
--- a/src/text.js
+++ b/src/text.js
@@ -1,7 +1,7 @@
SVG.Text = SVG.invent({
// Initialize node
- create: function() {
- this.constructor.call(this, SVG.create('text'))
+ create: function(node) {
+ this.constructor.call(this, node || SVG.create('text'))
this.dom.leading = new SVG.Number(1.3) // store leading value for rebuilding
this._rebuild = true // enable automatic updating of dy values
diff --git a/src/use.js b/src/use.js
index d3150f7..96f7411 100644
--- a/src/use.js
+++ b/src/use.js
@@ -21,4 +21,4 @@ SVG.Use = SVG.invent({
return this.put(new SVG.Use).element(element, file)
}
}
-}) \ No newline at end of file
+})