summaryrefslogtreecommitdiffstats
path: root/src/tools.js
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-10-27 20:43:35 +0200
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-10-27 20:43:35 +0200
commit1c75fcaf02ceb144152d59557643c6fdd7264065 (patch)
tree5184af75f2fd27ca6b81c24a06b1676d17ca2c76 /src/tools.js
parentb1b776a710d0ce0a6259043b8ce0665e205195fa (diff)
downloadsvg.js-1c75fcaf02ceb144152d59557643c6fdd7264065.tar.gz
svg.js-1c75fcaf02ceb144152d59557643c6fdd7264065.zip
resolve circular references and make example working again
Diffstat (limited to 'src/tools.js')
-rw-r--r--src/tools.js48
1 files changed, 14 insertions, 34 deletions
diff --git a/src/tools.js b/src/tools.js
index e77d653..2733af4 100644
--- a/src/tools.js
+++ b/src/tools.js
@@ -1,5 +1,5 @@
import {ns} from './namespaces.js'
-import {Container, Element, HtmlNode, Doc, Gradient, Parent} from './classes.js'
+import {capitalize} from './helpers.js'
// Element id sequence
let did = 1000
@@ -23,13 +23,22 @@ export function makeNode (name) {
export function extend (modules, methods) {
var key, i
+ if (Array.isArray(methods)) {
+ methods.forEach((method) => {
+ extend(modules, method)
+ })
+ return
+ }
+
modules = Array.isArray(modules) ? modules : [modules]
for (i = modules.length - 1; i >= 0; i--) {
- if (modules[i]) {
- for (key in methods) {
- modules[i].prototype[key] = methods[key]
- }
+ if (methods.name) {
+ modules[i].extensions = (modules[i].extensions || []).concat(methods)
+ }
+ for (key in methods) {
+ if (modules[i].prototype[key] || key == 'name' || key == 'setup') continue
+ modules[i].prototype[key] = methods[key]
}
}
}
@@ -63,32 +72,3 @@ export function invent (config) {
return initializer
}
-
-// Adopt existing svg elements
-export function adopt (node) {
- // check for presence of node
- if (!node) return null
-
- // make sure a node isn't already adopted
- if (node.instance instanceof Element) return node.instance
-
- if (!(node instanceof window.SVGElement)) {
- return new HtmlNode(node)
- }
-
- // initialize variables
- var element
-
- // adopt with element-specific settings
- if (node.nodeName === 'svg') {
- element = new Doc(node)
- } else if (node.nodeName === 'linearGradient' || node.nodeName === 'radialGradient') {
- element = new Gradient(node)
- } else if (SVG[capitalize(node.nodeName)]) {
- element = new SVG[capitalize(node.nodeName)](node)
- } else {
- element = new Parent(node)
- }
-
- return element
-}