Advertisement
Guest User

Untitled

a guest
Oct 9th, 2015
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. function Week1()
  2. {
  3. this.controller = null;
  4. }
  5.  
  6. Week1.prototype.execute = function( controller, whereSheLeftThings )
  7. {
  8. this.controller = controller;
  9. console.log('Executing week 1 animation');
  10.  
  11. // ANIMATE ITSELF
  12.  
  13. // ALL DONE!
  14. this.controller.setComplete();
  15. }
  16.  
  17. // ---
  18.  
  19. function Week2()
  20. {
  21. this.controller = null;
  22. }
  23.  
  24. Week2.prototype.execute = function( controller, whereSheLeftThings )
  25. {
  26. this.controller = controller;
  27. console.log('Executing week 2 animation');
  28.  
  29. // ANIMATE ITSELF
  30.  
  31. // ALL DONE!
  32. this.controller.setComplete();
  33. }
  34.  
  35. // --- ----------------------------------------------------------------------
  36.  
  37. function AnimationController()
  38. {
  39. this.queue = [];
  40. this.animIsRunning = false;
  41. this.whereILeftThings = null;
  42. }
  43.  
  44. AnimationController.prototype.setComplete = function( whereILeftThings ) {
  45. this.whereILeftThings = whereILeftThings;
  46.  
  47. this.animIsRunning = false;
  48. }
  49.  
  50. AnimationController.prototype.run = function( animation )
  51. {
  52. this.queue.push( animation );
  53.  
  54. var scope = this;
  55. setInterval(function() {
  56. if ( !scope.animIsRunning && (scope.queue.length > 0) ) {
  57. var nextAnimation = scope.queue.shift();
  58. console.log( 'About to run a new animation', nextAnimation );
  59.  
  60. scope.animIsRunning = true;
  61. animation['execute'].call( scope, scope, scope.whereILeftThings );
  62. }
  63. }, 500);
  64. }
  65.  
  66. $(document).ready(function() {
  67.  
  68. var animController = new AnimationController();
  69.  
  70. var wk1 = new Week1();
  71. var wk2 = new Week2();
  72.  
  73. animController.run( wk1 );
  74. animController.run( wk2 );
  75. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement