diff options
author | wout <wout@impinc.co.uk> | 2013-03-09 22:28:47 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2013-03-09 22:28:47 +0100 |
commit | 6c6c82ed59533f44f8754b69d47e3b11cd6dd129 (patch) | |
tree | adaef53d8970acb228fe14d490c532f1baabbb13 /src/svg.js | |
parent | 16c4a146ee97fa43e0c456fe801490351e551e96 (diff) | |
download | svg.js-6c6c82ed59533f44f8754b69d47e3b11cd6dd129.tar.gz svg.js-6c6c82ed59533f44f8754b69d47e3b11cd6dd129.zip |
Bumped to v0.9, added better style management, text support and extended animation functionality0.10
Diffstat (limited to 'src/svg.js')
-rw-r--r-- | src/svg.js | 86 |
1 files changed, 45 insertions, 41 deletions
@@ -1,56 +1,60 @@ -// 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. +// 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('paper').size(300, 300) +// var draw = SVG('paper').size(300, 300) // var rect = draw.rect(100, 100).attr({ fill: '#f06' }) -// Shortcut for creating a svg document -this.svg = function(element) { +// The main wrapping element +this.SVG = function(element) { if (SVG.supported) return new SVG.Doc(element) } -// The main wrapping element -this.SVG = { - /* default namespaces */ - ns: 'http://www.w3.org/2000/svg' -, xlink: 'http://www.w3.org/1999/xlink' +// DEPRECATED!!! Use SVG() instead +this.svg = function(element) { + console.warn('WARNING: svg() is deprecated, please use SVG() instead.') + return SVG(element) +} + +// Default namespaces +SVG.ns = 'http://www.w3.org/2000/svg' +SVG.xlink = 'http://www.w3.org/1999/xlink' + +// Element id sequence +SVG.did = 1000 + +// Get next named element id +SVG.eid = function(name) { + return 'Svgjs' + name.charAt(0).toUpperCase() + name.slice(1) + 'Element' + (SVG.did++) +} + +// Method for element creation +SVG.create = function(name) { + /* create element */ + var element = document.createElementNS(this.ns, name) - /* element id sequence */ -, did: 1000 - - // Get next named element id -, eid: function(name) { - return 'Svgjs' + name.charAt(0).toUpperCase() + name.slice(1) + 'Element' + (SVG.did++) - } - // Method for element creation -, create: function(name) { - /* create element */ - var element = document.createElementNS(this.ns, name) - - /* apply unique id */ - element.setAttribute('id', this.eid(name)) - - return element - } + /* apply unique id */ + element.setAttribute('id', this.eid(name)) + + return element +} + // Method for extending objects -, extend: function() { - var modules, methods, key, i - - /* get list of modules */ - modules = Array.prototype.slice.call(arguments) - - /* get object with extensions */ - methods = modules.pop() - - for (i = modules.length - 1; i >= 0; i--) - if (modules[i]) - for (key in methods) - modules[i].prototype[key] = methods[key] - } +SVG.extend = function() { + var modules, methods, key, i + + /* get list of modules */ + modules = Array.prototype.slice.call(arguments) + + /* get object with extensions */ + methods = modules.pop() + for (i = modules.length - 1; i >= 0; i--) + if (modules[i]) + for (key in methods) + modules[i].prototype[key] = methods[key] } // svg support test @@ -59,4 +63,4 @@ SVG.supported = (function() { !! document.createElementNS(SVG.ns,'svg').createSVGRect })() -if (!SVG.supported) return false;
\ No newline at end of file +if (!SVG.supported) return false
\ No newline at end of file |