diff options
author | wout <wout@impinc.co.uk> | 2014-07-26 21:58:56 +0200 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2014-07-26 21:58:56 +0200 |
commit | 80521a95f894c37d6db2e0480454c1afc3d8f6a5 (patch) | |
tree | 762ec2c50953bc7871fbe03770bc985abaeaa351 /src/fx.js | |
parent | 9842187d84e71e736ada6a2e9444bab592945600 (diff) | |
download | svg.js-80521a95f894c37d6db2e0480454c1afc3d8f6a5.tar.gz svg.js-80521a95f894c37d6db2e0480454c1afc3d8f6a5.zip |
Installed Jasmin 2.0.1
Diffstat (limited to 'src/fx.js')
-rwxr-xr-x | src/fx.js | 117 |
1 files changed, 46 insertions, 71 deletions
@@ -1,7 +1,7 @@ SVG.FX = SVG.invent({ // Initialize FX object create: function(element) { - /* store target element */ + // store target element this.target = element } @@ -9,44 +9,44 @@ SVG.FX = SVG.invent({ , extend: { // Add animation parameters and start animation animate: function(d, ease, delay) { - var akeys, tkeys, skeys, key + var akeys, skeys, key , element = this.target , fx = this - /* dissect object if one is passed */ + // dissect object if one is passed if (typeof d == 'object') { delay = d.delay ease = d.ease d = d.duration } - /* ensure default duration and easing */ + // ensure default duration and easing d = d == '=' ? d : d == null ? 1000 : new SVG.Number(d).valueOf() ease = ease || '<>' - /* process values */ - fx.to = function(pos) { + // process values + fx.at = function(pos) { var i - /* normalise pos */ + // normalise pos pos = pos < 0 ? 0 : pos > 1 ? 1 : pos - /* collect attribute keys */ + // collect attribute keys if (akeys == null) { akeys = [] for (key in fx.attrs) akeys.push(key) - /* make sure morphable elements are scaled, translated and morphed all together */ + // make sure morphable elements are scaled, translated and morphed all together if (element.morphArray && (fx._plot || akeys.indexOf('points') > -1)) { - /* get destination */ + // get destination var box , p = new element.morphArray(fx._plot || fx.attrs.points || element.array) - /* add size */ + // add size if (fx._size) p.size(fx._size.width.to, fx._size.height.to) - /* add movement */ + // add movement box = p.bbox() if (fx._x) p.move(fx._x.to, box.y) else if (fx._cx) p.move(fx._cx.to - box.width / 2, box.y) @@ -55,7 +55,7 @@ SVG.FX = SVG.invent({ if (fx._y) p.move(box.x, fx._y.to) else if (fx._cy) p.move(box.x, fx._cy.to - box.height / 2) - /* delete element oriented changes */ + // delete element oriented changes delete fx._x delete fx._y delete fx._cx @@ -66,21 +66,14 @@ SVG.FX = SVG.invent({ } } - /* collect transformation keys */ - if (tkeys == null) { - tkeys = [] - for (key in fx.trans) - tkeys.push(key) - } - - /* collect style keys */ + // collect style keys if (skeys == null) { skeys = [] for (key in fx.styles) skeys.push(key) } - /* apply easing */ + // apply easing pos = ease == '<>' ? (-Math.cos(pos * Math.PI) / 2) + 0.5 : ease == '>' ? @@ -93,29 +86,29 @@ SVG.FX = SVG.invent({ ease(pos) : pos - /* run plot function */ + // run plot function if (fx._plot) { element.plot(fx._plot.at(pos)) } else { - /* run all x-position properties */ + // run all x-position properties if (fx._x) element.x(fx._x.at(pos)) else if (fx._cx) element.cx(fx._cx.at(pos)) - /* run all y-position properties */ + // run all y-position properties if (fx._y) element.y(fx._y.at(pos)) else if (fx._cy) element.cy(fx._cy.at(pos)) - /* run all size properties */ + // run all size properties if (fx._size) element.size(fx._size.width.at(pos), fx._size.height.at(pos)) } - /* run all viewbox properties */ + // run all viewbox properties if (fx._viewbox) element.viewbox( fx._viewbox.x.at(pos) @@ -124,23 +117,19 @@ SVG.FX = SVG.invent({ , fx._viewbox.height.at(pos) ) - /* run leading property */ + // run leading property if (fx._leading) element.leading(fx._leading.at(pos)) - /* animate attributes */ + // animate attributes for (i = akeys.length - 1; i >= 0; i--) element.attr(akeys[i], at(fx.attrs[akeys[i]], pos)) - /* animate transformations */ - for (i = tkeys.length - 1; i >= 0; i--) - element.transform(tkeys[i], at(fx.trans[tkeys[i]], pos)) - - /* animate styles */ + // animate styles for (i = skeys.length - 1; i >= 0; i--) element.style(skeys[i], at(fx.styles[skeys[i]], pos)) - /* callback for each keyframe */ + // callback for each keyframe if (fx._during) fx._during.call(element, pos, function(from, to) { return at({ from: from, to: to }, pos) @@ -148,11 +137,11 @@ SVG.FX = SVG.invent({ } if (typeof d === 'number') { - /* delay animation */ + // delay animation this.timeout = setTimeout(function() { var start = new Date().getTime() - /* initialize situation object */ + // initialize situation object fx.situation = { interval: 1000 / 60 , start: start @@ -161,18 +150,18 @@ SVG.FX = SVG.invent({ , duration: d } - /* render function */ + // render function fx.render = function() { if (fx.situation.play === true) { - // This code was borrowed from the emile.js micro framework by Thomas Fuchs, aka MadRobby. + // calculate pos var time = new Date().getTime() , pos = time > fx.situation.finish ? 1 : (time - fx.situation.start) / d - /* process values */ - fx.to(pos) + // process values + fx.at(pos) - /* finish off animation */ + // finish off animation if (time > fx.situation.finish) { if (fx._plot) element.plot(new SVG.PointArray(fx._plot.destination).settle()) @@ -194,7 +183,7 @@ SVG.FX = SVG.invent({ } - /* start animation */ + // start animation fx.render() }, new SVG.Number(delay).valueOf()) @@ -208,14 +197,19 @@ SVG.FX = SVG.invent({ } // Add animatable attributes , attr: function(a, v) { + // apply attributes individually if (typeof a == 'object') { for (var key in a) this.attr(key, a[key]) } else { + // get the current state var from = this.target.attr(a) - this.attrs[a] = SVG.Color.isColor(from) ? + // detect format + this.attrs[a] = a == 'transform' ? + this.target.ctm().morph(v) : + SVG.Color.isColor(from) ? new SVG.Color(from).morph(v) : SVG.regex.unit.test(from) ? new SVG.Number(from).morph(v) : @@ -225,27 +219,8 @@ SVG.FX = SVG.invent({ return this } // Add animatable transformations - , transform: function(o, v) { - // if (arguments.length == 1) { - // /* parse matrix string */ - // o = parseMatrix(o) - - // /* dlete matrixstring from object */ - // delete o.matrix - - // /* store matrix values */ - // for (v in o) - // this.trans[v] = { from: this.target.trans[v], to: o[v] } - - // } else { - // /* apply transformations as object if key value arguments are given*/ - // var transform = {} - // transform[o] = v - - // this.transform(transform) - // } - - // return this + , transform: function(o) { + return this.attr('transform', o) } // Add animatable styles , style: function(s, v) { @@ -293,11 +268,11 @@ SVG.FX = SVG.invent({ // Add animatable size , size: function(width, height) { if (this.target instanceof SVG.Text) { - /* animate font size for Text elements */ + // animate font size for Text elements this.attr('font-size', width) } else { - /* animate bbox based size for all other elements */ + // animate bbox based size for all other elements var box = this.target.bbox() this._size = { @@ -366,7 +341,7 @@ SVG.FX = SVG.invent({ } // Stop running animation , stop: function(fulfill) { - /* fulfill animation */ + // fulfill animation if (fulfill === true) { this.animate(0) @@ -375,16 +350,16 @@ SVG.FX = SVG.invent({ this._after.apply(this.target, [this]) } else { - /* stop current animation */ + // stop current animation clearTimeout(this.timeout) - /* reset storage for properties that need animation */ + // reset storage for properties that need animation this.attrs = {} this.trans = {} this.styles = {} this.situation = {} - /* delete destinations */ + // delete destinations delete this._x delete this._y delete this._cx |