summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/color.js2
-rw-r--r--src/fx.js12
-rw-r--r--src/gradient.js4
-rw-r--r--src/matrix.js2
-rw-r--r--src/point.js2
-rw-r--r--src/sugar.js4
-rw-r--r--src/svg.js30
7 files changed, 33 insertions, 23 deletions
diff --git a/src/color.js b/src/color.js
index 1564bba..25f41d6 100644
--- a/src/color.js
+++ b/src/color.js
@@ -7,6 +7,8 @@ SVG.Color = function(color) {
this.g = 0
this.b = 0
+ if(!color) return
+
// parse color
if (typeof color === 'string') {
if (SVG.regex.isRgb.test(color)) {
diff --git a/src/fx.js b/src/fx.js
index ee61808..9238e2b 100644
--- a/src/fx.js
+++ b/src/fx.js
@@ -5,8 +5,10 @@ SVG.easing = {
, '<': function(pos){return -Math.cos(pos * Math.PI / 2) + 1}
}
-SVG.morph = function(from, to) {
- return new MorphObj(from, to).at(pos)
+SVG.morph = function(pos){
+ return function(from, to) {
+ return new SVG.MorphObj(from, to).at(pos)
+ }
}
SVG.Situation = SVG.invent({
@@ -279,7 +281,7 @@ SVG.FX = SVG.invent({
this.active = false
- if(jumpToEnd){
+ if(jumpToEnd && this.situation){
this.situation.loop = false
@@ -409,7 +411,7 @@ SVG.FX = SVG.invent({
var c = this.last()
, wrapper = function(e){
if(e.detail.situation == c){
- fn.call(this, e.detail.pos, SVG.morph, e.detail.eased, c)
+ fn.call(this, e.detail.pos, SVG.morph(e.detail.pos), e.detail.eased, c)
}
}
@@ -436,7 +438,7 @@ SVG.FX = SVG.invent({
// calls on every animation step for all animations
, duringAll: function(fn){
var wrapper = function(e){
- fn.call(this, e.detail.pos, SVG.morph, e.detail.eased, e.detail.situation)
+ fn.call(this, e.detail.pos, SVG.morph(e.detail.pos), e.detail.eased, e.detail.situation)
}
this.target().off('during.fx', wrapper).on('during.fx', wrapper)
diff --git a/src/gradient.js b/src/gradient.js
index 9478747..17145e6 100644
--- a/src/gradient.js
+++ b/src/gradient.js
@@ -55,13 +55,13 @@ SVG.Gradient = SVG.invent({
SVG.extend(SVG.Gradient, SVG.FX, {
// From position
from: function(x, y) {
- return (this.target || this).type == 'radial' ?
+ return (this._target || this).type == 'radial' ?
this.attr({ fx: new SVG.Number(x), fy: new SVG.Number(y) }) :
this.attr({ x1: new SVG.Number(x), y1: new SVG.Number(y) })
}
// To position
, to: function(x, y) {
- return (this.target || this).type == 'radial' ?
+ return (this._target || this).type == 'radial' ?
this.attr({ cx: new SVG.Number(x), cy: new SVG.Number(y) }) :
this.attr({ x2: new SVG.Number(x), y2: new SVG.Number(y) })
}
diff --git a/src/matrix.js b/src/matrix.js
index e727b2f..37bd860 100644
--- a/src/matrix.js
+++ b/src/matrix.js
@@ -156,7 +156,7 @@ SVG.Matrix = SVG.invent({
// Convert to native SVGMatrix
, native: function() {
// create new matrix
- var matrix = SVG.parser.draw.node.createSVGMatrix()
+ var matrix = SVG.parser.native.createSVGMatrix()
// update with current values
for (var i = abcdef.length - 1; i >= 0; i--)
diff --git a/src/point.js b/src/point.js
index ba7bd8f..8d1dae9 100644
--- a/src/point.js
+++ b/src/point.js
@@ -45,7 +45,7 @@ SVG.Point = SVG.invent({
// Convert to native SVGPoint
, native: function() {
// create new point
- var point = SVG.parser.draw.node.createSVGPoint()
+ var point = SVG.parser.native.createSVGPoint()
// update with current values
point.x = this.x
diff --git a/src/sugar.js b/src/sugar.js
index 6e1bbf4..7db5ce6 100644
--- a/src/sugar.js
+++ b/src/sugar.js
@@ -76,9 +76,9 @@ SVG.extend(SVG.Element, SVG.FX, {
SVG.extend(SVG.Rect, SVG.Ellipse, SVG.Circle, SVG.Gradient, SVG.FX, {
// Add x and y radius
radius: function(x, y) {
- var type = (this.target || this).type;
+ var type = (this._target || this).type;
return type == 'radial' || type == 'circle' ?
- this.attr({ 'r': new SVG.Number(x) }) :
+ this.attr('r', new SVG.Number(x)) :
this.rx(x).ry(y == null ? x : y)
}
})
diff --git a/src/svg.js b/src/svg.js
index c69aebc..1175a62 100644
--- a/src/svg.js
+++ b/src/svg.js
@@ -2,10 +2,10 @@
var SVG = this.SVG = function(element) {
if (SVG.supported) {
element = new SVG.Doc(element)
-
- if (!SVG.parser)
- SVG.prepare(element)
-
+
+ if(!SVG.parser.draw)
+ SVG.prepare()
+
return element
}
}
@@ -127,20 +127,26 @@ SVG.adopt = function(node) {
}
// Initialize parsing element
-SVG.prepare = function(element) {
+SVG.prepare = function() {
// Select document body and create invisible svg element
var body = document.getElementsByTagName('body')[0]
- , draw = (body ? new SVG.Doc(body) : element.nested()).size(2, 0)
- , path = SVG.create('path')
-
- // Insert parsers
- draw.node.appendChild(path)
+ , draw = (body ? new SVG.Doc(body) : new SVG.Doc(document.documentElement).nested()).size(2, 0)
// Create parser object
SVG.parser = {
- body: body || element.parent()
+ body: body || document.documentElement
, draw: draw.style('opacity:0;position:fixed;left:100%;top:100%;overflow:hidden')
, poly: draw.polyline().node
- , path: path
+ , path: draw.path().node
+ , native: SVG.create('svg')
}
}
+
+SVG.parser = {
+ native: SVG.create('svg')
+}
+
+document.addEventListener('DOMContentLoaded', function() {
+ if(!SVG.parser.draw)
+ SVG.prepare()
+}, false)