diff options
author | wout <wout@impinc.co.uk> | 2014-01-29 22:00:53 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2014-01-29 22:00:53 +0100 |
commit | 0a165763e99d3fd5625f130a83e7117c007a2f7e (patch) | |
tree | 7dcd478ec8fe056655878e17666bf218bd19bfc2 /src | |
parent | a52a1d7e362382c93d71d2cea27a4a691cd6d215 (diff) | |
download | svg.js-0a165763e99d3fd5625f130a83e7117c007a2f7e.tar.gz svg.js-0a165763e99d3fd5625f130a83e7117c007a2f7e.zip |
Preparing SVG namespace when dom is loaded
Diffstat (limited to 'src')
-rwxr-xr-x | src/svg.js | 29 |
1 files changed, 16 insertions, 13 deletions
@@ -8,6 +8,9 @@ // The main wrapping element this.SVG = function(element) { + if (!SVG.parser) + SVG.prepare() + if (SVG.supported) return new SVG.Doc(element) } @@ -56,22 +59,14 @@ SVG.extend = function() { SVG.Set.inherit() } -// Method for getting an eleemnt by id +// Method for getting an element by id SVG.get = function(id) { var node = document.getElementById(id) if (node) return node.instance } -// svg support test -SVG.supported = (function() { - return !! document.createElementNS && - !! document.createElementNS(SVG.ns,'svg').createSVGRect -})() - -if (!SVG.supported) return false - // Initialize parsing element -SVG.parser = (function() { +SVG.prepare = function() { /* select document body and create svg element*/ var body = document.getElementsByTagName('body')[0] || document.getElementsByTagName('svg')[0] , svg = SVG.create('svg') @@ -89,12 +84,20 @@ SVG.parser = (function() { svg.appendChild(poly) svg.appendChild(path) - /* return parser object */ - return { + /* create parser object */ + SVG.parser = { body: body , doc: svg , poly: poly , path: path } -})()
\ No newline at end of file +} + +// svg support test +SVG.supported = (function() { + return !! document.createElementNS && + !! document.createElementNS(SVG.ns,'svg').createSVGRect +})() + +if (!SVG.supported) return false
\ No newline at end of file |