1 /**
  2  * create a tQuery.Animations
  3  *
  4  * @name tQuery.createAnimations
  5  * @class
  6 */
  7 tQuery.registerStatic('createAnimations', function(){
  8 	return new tQuery.Animations();
  9 });
 10 
 11 /**
 12  * handle multiple tQuery.Animation mutually exclusive
 13  *
 14  * @name tQuery.Animations
 15  * @class
 16 */
 17 tQuery.registerStatic('Animations', function(){
 18 	this._animations	= {};
 19 	this._currentAnim	= null;
 20 	this._animationName	= null;
 21 });
 22 
 23 /**
 24  * Destructor
 25 */
 26 tQuery.Animations.prototype.destroy	= function(){
 27 	this._currentAnim	&& this._currentAnim.destroy();
 28 }
 29 
 30 //////////////////////////////////////////////////////////////////////////////////
 31 //										//
 32 //////////////////////////////////////////////////////////////////////////////////
 33 
 34 /**
 35  * Add an animation
 36  *
 37  * @param {String} name the name of the animation to add
 38  * @param {tQuery.Animation} animation the tQuery.Animation to add
 39 */
 40 tQuery.Animations.prototype.add	= function(name, animation){
 41 	console.assert( animation instanceof tQuery.Animation );
 42 	this._animations[name]	= animation;
 43 	return this;	// for chained api
 44 };
 45 
 46 tQuery.Animations.prototype.list	= function(){
 47 	return this._animations;
 48 };
 49 
 50 /**
 51  * return the name of all animations
 52  * 
 53  * @returns {String[]} list of the animations names
 54 */
 55 tQuery.Animations.prototype.names	= function(){
 56 	return Object.keys(this._animations);
 57 };
 58 
 59 //////////////////////////////////////////////////////////////////////////////////
 60 //										//
 61 //////////////////////////////////////////////////////////////////////////////////
 62 
 63 /**
 64  * Start a animation. If an animation is already running, it is stopped
 65  * 
 66  * @param {string} animationName the name of the animation
 67 */
 68 tQuery.Animations.prototype.start	= function(animationName){
 69 	// if this animation is already the current one, do nothing
 70 	if( this._animationName === animationName )	return this;
 71 	// stop current animation
 72 	if( this.isRunning() )	this.stop();
 73 	console.assert( this._animations[animationName] !== undefined, "unknown animation name: "+animationName)
 74 	this._animationName	= animationName;
 75 	this._currentAnim	= this._animations[animationName];
 76 	this._currentAnim.start();
 77 	return this;	// for chained API
 78 };
 79 
 80 /**
 81  * test if an animation is running
 82  * 
 83  * @returns {boolean} true if an animation is running, false otherwise
 84 */
 85 tQuery.Animations.prototype.isRunning	= function(){
 86 	return this._currentAnim ? true : false;
 87 }
 88 
 89 tQuery.Animations.prototype.animationName	= function(){
 90 	return this._animationName;
 91 }
 92 
 93 /**
 94  * Stop the running animation if any
 95 */
 96 tQuery.Animations.prototype.stop	= function(){
 97 	this._currentAnim	&& this._currentAnim.destroy();
 98 	this._currentAnim	= null;
 99 	this._animationName	= null;
100 	return this;	// for chained API
101 }
102