transition-timer.js revision ca4ee40983d39fb8235d544a1049ba4ecc67964e
8a66318e41ed14c5a88130e8c362610e8faa2121Mark Andrews* The Transition Utility provides an API for creating advanced transitions.
8a66318e41ed14c5a88130e8c362610e8faa2121Mark Andrews* @module node
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley* Provides the base Transition class, for animating numeric properties.
8a66318e41ed14c5a88130e8c362610e8faa2121Mark Andrews* @module node
8a66318e41ed14c5a88130e8c362610e8faa2121Mark Andrews* @submodule transition
8a66318e41ed14c5a88130e8c362610e8faa2121Mark Andrews * A class for constructing animation instances.
8a66318e41ed14c5a88130e8c362610e8faa2121Mark Andrews * @class Transition
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley * @for Transition
8a66318e41ed14c5a88130e8c362610e8faa2121Mark Andrews * @constructor
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley _start: function() {
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley _runTimer: function() {
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley _end: function() {
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley this._running = false;
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley _runFrame: function() {
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley var t = new Date() - this._startTime;
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley if ((attribute && attribute.transition === anim)) {
33682c92e96b39c395cdb2c3feb8eb5914e7d5a8Andreas Gustafsson setter = (i in customAttr && 'set' in customAttr[i]) ?
33682c92e96b39c395cdb2c3feb8eb5914e7d5a8Andreas Gustafsson customAttr[i].set : Transition.DEFAULT_SETTER;
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley setter(anim, name, attribute.from, attribute.to, t - delay, d - delay,
841179549b6433e782c164a562eb3422f603533dAndreas Gustafsson setTimeout(function() { // IE: allow previous update to finish
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley if (attrs.hasOwnProperty(name) && (attribute && attribute.transition === anim)) {
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley begin = (name in customAttr && 'get' in customAttr[name]) ?
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley customAttr[name].get(anim, name) : Transition.DEFAULT_GETTER(anim, name);
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley unit = mTo ? mTo[2] : mFrom ? mFrom[2] : ''; // one might be zero TODO: mixed units
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley if (!unit && Transition.RE_DEFAULT_UNIT.test(name)) {
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley Y.log('invalid "from" or "to" for "' + name + '"', 'error', 'transition');
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley easing = easing.substring(13, easing.length - 1).split(',');
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley destroy: function() {
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley this._node = null;
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley * Regex of properties that should use the default unit.
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley * @property RE_DEFAULT_UNIT
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley RE_DEFAULT_UNIT: /^width|height|top|right|bottom|left|margin.*|padding.*|border.*$/i,
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley * The default unit to use with properties that pass the RE_DEFAULT_UNIT test.
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley * @property DEFAULT_UNIT
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley * Time in milliseconds passed to setInterval for frame processing
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley * @property intervalTime
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley * @default 20
33682c92e96b39c395cdb2c3feb8eb5914e7d5a8Andreas Gustafsson * Bucket for custom getters and setters
33682c92e96b39c395cdb2c3feb8eb5914e7d5a8Andreas Gustafsson * @property behaviors
33682c92e96b39c395cdb2c3feb8eb5914e7d5a8Andreas Gustafsson return Y.DOM._getAttrOffset(anim._node._node, attr);
33682c92e96b39c395cdb2c3feb8eb5914e7d5a8Andreas Gustafsson * The default setter to use when setting object properties.
33682c92e96b39c395cdb2c3feb8eb5914e7d5a8Andreas Gustafsson * @property DEFAULT_SETTER
33682c92e96b39c395cdb2c3feb8eb5914e7d5a8Andreas Gustafsson DEFAULT_SETTER: function(anim, att, from, to, elapsed, duration, fn, unit) {
33682c92e96b39c395cdb2c3feb8eb5914e7d5a8Andreas Gustafsson val = Transition.cubicBezier(fn, elapsed / duration);
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley if (att in node._node.style || att in Y.DOM.CUSTOM_STYLES) {
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley * The default getter to use when getting object properties.
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley * @property DEFAULT_GETTER
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley if (att in node._node.style || att in Y.DOM.CUSTOM_STYLES) {
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley Transition._timer = setInterval(Transition._runFrame, Transition.intervalTime);
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley _stopTimer: function() {
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley * Called per Interval to handle each animation frame.
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley * @method _runFrame
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley cubicBezier: function(p, t) {
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley x = (((A*t) + B)*t + C)*t + D,
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley y = (((E*t) + F)*t + G)*t + H;
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley return [x, y];
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley RE_UNITS: /^(-?\d*\.?\d*){1}(em|ex|px|in|cm|mm|pt|pc|%)*$/