diff options
Diffstat (limited to 'src/adopter.js')
-rw-r--r-- | src/adopter.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/adopter.js b/src/adopter.js new file mode 100644 index 0000000..c762a2b --- /dev/null +++ b/src/adopter.js @@ -0,0 +1,23 @@ +// Adopt existing svg elements +SVG.adopt = function(node) { + // Make sure a node isn't already adopted + if (node.instance) return node.instance + + // Initialize variables + var element + + // Adopt with element-specific settings + if (node.nodeName == 'svg') + element = node.parentNode instanceof SVGElement ? new SVG.Nested : new SVG.Doc + else if (node.nodeName == 'lineairGradient') + element = new SVG.Gradient('lineair') + else if (node.nodeName == 'radialGradient') + element = new SVG.Gradient('radial') + else + element = new SVG[capitalize(node.nodeName)] + + // Ensure references + element.type = node.nodeName + element.node = node + return node.instance = element +}
\ No newline at end of file |