123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312 |
- goog.provide('goog.fx.AnimationParallelQueue');
- goog.provide('goog.fx.AnimationQueue');
- goog.provide('goog.fx.AnimationSerialQueue');
- goog.require('goog.array');
- goog.require('goog.asserts');
- goog.require('goog.events');
- goog.require('goog.fx.Animation');
- goog.require('goog.fx.Transition');
- goog.require('goog.fx.TransitionBase');
- goog.fx.AnimationQueue = function() {
- goog.fx.AnimationQueue.base(this, 'constructor');
-
- this.queue = [];
- };
- goog.inherits(goog.fx.AnimationQueue, goog.fx.TransitionBase);
- goog.fx.AnimationQueue.prototype.add = function(animation) {
- goog.asserts.assert(
- this.isStopped(),
- 'Not allowed to add animations to a running animation queue.');
- if (goog.array.contains(this.queue, animation)) {
- return;
- }
- this.queue.push(animation);
- goog.events.listen(
- animation, goog.fx.Transition.EventType.FINISH, this.onAnimationFinish,
- false, this);
- };
- goog.fx.AnimationQueue.prototype.remove = function(animation) {
- goog.asserts.assert(
- this.isStopped(),
- 'Not allowed to remove animations from a running animation queue.');
- if (goog.array.remove(this.queue, animation)) {
- goog.events.unlisten(
- animation, goog.fx.Transition.EventType.FINISH, this.onAnimationFinish,
- false, this);
- }
- };
- goog.fx.AnimationQueue.prototype.onAnimationFinish = goog.abstractMethod;
- goog.fx.AnimationQueue.prototype.disposeInternal = function() {
- goog.array.forEach(this.queue, function(animation) { animation.dispose(); });
- this.queue.length = 0;
- goog.fx.AnimationQueue.base(this, 'disposeInternal');
- };
- goog.fx.AnimationParallelQueue = function() {
- goog.fx.AnimationParallelQueue.base(this, 'constructor');
-
- this.finishedCounter_ = 0;
- };
- goog.inherits(goog.fx.AnimationParallelQueue, goog.fx.AnimationQueue);
- goog.fx.AnimationParallelQueue.prototype.play = function(opt_restart) {
- if (this.queue.length == 0) {
- return false;
- }
- if (opt_restart || this.isStopped()) {
- this.finishedCounter_ = 0;
- this.onBegin();
- } else if (this.isPlaying()) {
- return false;
- }
- this.onPlay();
- if (this.isPaused()) {
- this.onResume();
- }
- var resuming = this.isPaused() && !opt_restart;
- this.startTime = goog.now();
- this.endTime = null;
- this.setStatePlaying();
- goog.array.forEach(this.queue, function(anim) {
- if (!resuming || anim.isPaused()) {
- anim.play(opt_restart);
- }
- });
- return true;
- };
- goog.fx.AnimationParallelQueue.prototype.pause = function() {
- if (this.isPlaying()) {
- goog.array.forEach(this.queue, function(anim) {
- if (anim.isPlaying()) {
- anim.pause();
- }
- });
- this.setStatePaused();
- this.onPause();
- }
- };
- goog.fx.AnimationParallelQueue.prototype.stop = function(opt_gotoEnd) {
- goog.array.forEach(this.queue, function(anim) {
- if (!anim.isStopped()) {
- anim.stop(opt_gotoEnd);
- }
- });
- this.setStateStopped();
- this.endTime = goog.now();
- this.onStop();
- this.onEnd();
- };
- goog.fx.AnimationParallelQueue.prototype.onAnimationFinish = function(e) {
- this.finishedCounter_++;
- if (this.finishedCounter_ == this.queue.length) {
- this.endTime = goog.now();
- this.setStateStopped();
- this.onFinish();
- this.onEnd();
- }
- };
- goog.fx.AnimationSerialQueue = function() {
- goog.fx.AnimationSerialQueue.base(this, 'constructor');
-
- this.current_ = 0;
- };
- goog.inherits(goog.fx.AnimationSerialQueue, goog.fx.AnimationQueue);
- goog.fx.AnimationSerialQueue.prototype.play = function(opt_restart) {
- if (this.queue.length == 0) {
- return false;
- }
- if (opt_restart || this.isStopped()) {
- if (this.current_ < this.queue.length &&
- !this.queue[this.current_].isStopped()) {
- this.queue[this.current_].stop(false);
- }
- this.current_ = 0;
- this.onBegin();
- } else if (this.isPlaying()) {
- return false;
- }
- this.onPlay();
- if (this.isPaused()) {
- this.onResume();
- }
- this.startTime = goog.now();
- this.endTime = null;
- this.setStatePlaying();
- this.queue[this.current_].play(opt_restart);
- return true;
- };
- goog.fx.AnimationSerialQueue.prototype.pause = function() {
- if (this.isPlaying()) {
- this.queue[this.current_].pause();
- this.setStatePaused();
- this.onPause();
- }
- };
- goog.fx.AnimationSerialQueue.prototype.stop = function(opt_gotoEnd) {
- this.setStateStopped();
- this.endTime = goog.now();
- if (opt_gotoEnd) {
- for (var i = this.current_; i < this.queue.length; ++i) {
- var anim = this.queue[i];
-
-
- if (anim.isStopped()) anim.play();
-
-
- if (!anim.isStopped()) anim.stop(true);
- }
- } else if (this.current_ < this.queue.length) {
- this.queue[this.current_].stop(false);
- }
- this.onStop();
- this.onEnd();
- };
- goog.fx.AnimationSerialQueue.prototype.onAnimationFinish = function(e) {
- if (this.isPlaying()) {
- this.current_++;
- if (this.current_ < this.queue.length) {
- this.queue[this.current_].play();
- } else {
- this.endTime = goog.now();
- this.setStateStopped();
- this.onFinish();
- this.onEnd();
- }
- }
- };
|