aboutsummaryrefslogtreecommitdiffstats
path: root/src/svg.js
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2014-02-03 15:14:47 +0100
committerwout <wout@impinc.co.uk>2014-02-03 15:14:47 +0100
commite2304534e0cfb6f6f4ab8c37ea5275ae26cd455a (patch)
tree2386e9f361d9c5fa1308387aeeaf33f00241b3c5 /src/svg.js
parent7a29817ffd764cf7ab6906250b57f234801c94e0 (diff)
downloadsvg.js-e2304534e0cfb6f6f4ab8c37ea5275ae26cd455a.tar.gz
svg.js-e2304534e0cfb6f6f4ab8c37ea5275ae26cd455a.zip
Implemented SVG.invent function and bumped to v1.0rc3
Diffstat (limited to 'src/svg.js')
-rwxr-xr-xsrc/svg.js30
1 files changed, 13 insertions, 17 deletions
diff --git a/src/svg.js b/src/svg.js
index b0f6ecd..364a786 100755
--- a/src/svg.js
+++ b/src/svg.js
@@ -1,18 +1,14 @@
-// Use the `SVG()` function to create a SVG document within a given html element. The first argument can either be an id of the element or the selected element itself.
-//
-// var draw = SVG('drawing').size(300, 300)
-// var rect = draw.rect(100, 100).attr({ fill: '#f06' })
-
-
-
// The main wrapping element
this.SVG = function(element) {
- if (!SVG.parser)
- SVG.prepare()
+ if (SVG.supported) {
+ element = new SVG.Doc(element)
- if (SVG.supported)
- return new SVG.Doc(element)
+ if (!SVG.parser)
+ SVG.prepare(element)
+
+ return element
+ }
}
// Default namespaces
@@ -66,15 +62,15 @@ SVG.get = function(id) {
}
// Initialize parsing element
-SVG.prepare = function() {
- /* select document body and create svg element*/
- var body = document.getElementsByTagName('body')[0] || document.getElementsByTagName('svg')[0]
- , draw = new SVG.Doc(body).size(2, 2).style('opacity:0;position:fixed;left:100%;top:100%;')
+SVG.prepare = function(element) {
+ /* select document body and create invisible svg element */
+ var body = document.getElementsByTagName('body')[0]
+ , draw = (body ? new SVG.Doc(body) : element.nested()).size(2, 2)
/* create parser object */
SVG.parser = {
- body: body
- , draw: draw
+ body: body || element.parent
+ , draw: draw.style('opacity:0;position:fixed;left:100%;top:100%;overflow:hidden')
, poly: draw.polygon().node
, path: draw.path().node
}