Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Week1()
- {
- this.controller = null;
- }
- Week1.prototype.execute = function( controller, whereSheLeftThings )
- {
- this.controller = controller;
- console.log('Executing week 1 animation');
- // ANIMATE ITSELF
- // ALL DONE!
- this.controller.setComplete();
- }
- // ---
- function Week2()
- {
- this.controller = null;
- }
- Week2.prototype.execute = function( controller, whereSheLeftThings )
- {
- this.controller = controller;
- console.log('Executing week 2 animation');
- // ANIMATE ITSELF
- // ALL DONE!
- this.controller.setComplete();
- }
- // --- ----------------------------------------------------------------------
- function AnimationController()
- {
- this.queue = [];
- this.animIsRunning = false;
- this.whereILeftThings = null;
- }
- AnimationController.prototype.setComplete = function( whereILeftThings ) {
- this.whereILeftThings = whereILeftThings;
- this.animIsRunning = false;
- }
- AnimationController.prototype.run = function( animation )
- {
- this.queue.push( animation );
- var scope = this;
- setInterval(function() {
- if ( !scope.animIsRunning && (scope.queue.length > 0) ) {
- var nextAnimation = scope.queue.shift();
- console.log( 'About to run a new animation', nextAnimation );
- scope.animIsRunning = true;
- animation['execute'].call( scope, scope, scope.whereILeftThings );
- }
- }, 500);
- }
- $(document).ready(function() {
- var animController = new AnimationController();
- var wk1 = new Week1();
- var wk2 = new Week2();
- animController.run( wk1 );
- animController.run( wk2 );
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement