Path: blob/trunk/third_party/closure/goog/fx/transitionbase.js
4142 views
/**1* @license2* Copyright The Closure Library Authors.3* SPDX-License-Identifier: Apache-2.04*/56/**7* @fileoverview An abstract base class for transitions. This is a simple8* interface that allows for playing, pausing and stopping an animation. It adds9* a simple event model, and animation status.10*/11goog.provide('goog.fx.TransitionBase');1213goog.require('goog.events.EventTarget');14goog.require('goog.fx.Transition'); // Unreferenced: interface15161718/**19* Constructor for a transition object.20*21* @constructor22* @struct23* @implements {goog.fx.Transition}24* @extends {goog.events.EventTarget}25*/26goog.fx.TransitionBase = function() {27'use strict';28goog.fx.TransitionBase.base(this, 'constructor');2930/**31* The internal state of the animation.32* @type {goog.fx.TransitionBase.State}33* @private34*/35this.state_ = goog.fx.TransitionBase.State.STOPPED;3637/**38* Timestamp for when the animation was started.39* @type {?number}40* @protected41*/42this.startTime = null;4344/**45* Timestamp for when the animation finished or was stopped.46* @type {?number}47* @protected48*/49this.endTime = null;50};51goog.inherits(goog.fx.TransitionBase, goog.events.EventTarget);525354/**55* Enum for the possible states of an animation.56* @enum {number}57*/58goog.fx.TransitionBase.State = {59STOPPED: 0,60PAUSED: -1,61PLAYING: 162};636465/**66* Plays the animation.67*68* @param {boolean=} opt_restart Optional parameter to restart the animation.69* @return {boolean} True iff the animation was started.70* @override71*/72goog.fx.TransitionBase.prototype.play = goog.abstractMethod;737475/**76* Stops the animation.77*78* @param {boolean=} opt_gotoEnd Optional boolean parameter to go the end of79* the animation.80* @override81*/82goog.fx.TransitionBase.prototype.stop = goog.abstractMethod;838485/**86* Pauses the animation.87*/88goog.fx.TransitionBase.prototype.pause = goog.abstractMethod;899091/**92* Returns the current state of the animation.93* @return {goog.fx.TransitionBase.State} State of the animation.94*/95goog.fx.TransitionBase.prototype.getStateInternal = function() {96'use strict';97return this.state_;98};99100101/**102* Sets the current state of the animation to playing.103* @protected104*/105goog.fx.TransitionBase.prototype.setStatePlaying = function() {106'use strict';107this.state_ = goog.fx.TransitionBase.State.PLAYING;108};109110111/**112* Sets the current state of the animation to paused.113* @protected114*/115goog.fx.TransitionBase.prototype.setStatePaused = function() {116'use strict';117this.state_ = goog.fx.TransitionBase.State.PAUSED;118};119120121/**122* Sets the current state of the animation to stopped.123* @protected124*/125goog.fx.TransitionBase.prototype.setStateStopped = function() {126'use strict';127this.state_ = goog.fx.TransitionBase.State.STOPPED;128};129130131/**132* @return {boolean} True iff the current state of the animation is playing.133*/134goog.fx.TransitionBase.prototype.isPlaying = function() {135'use strict';136return this.state_ == goog.fx.TransitionBase.State.PLAYING;137};138139140/**141* @return {boolean} True iff the current state of the animation is paused.142*/143goog.fx.TransitionBase.prototype.isPaused = function() {144'use strict';145return this.state_ == goog.fx.TransitionBase.State.PAUSED;146};147148149/**150* @return {boolean} True iff the current state of the animation is stopped.151*/152goog.fx.TransitionBase.prototype.isStopped = function() {153'use strict';154return this.state_ == goog.fx.TransitionBase.State.STOPPED;155};156157158/**159* Dispatches the BEGIN event. Sub classes should override this instead160* of listening to the event, and call this instead of dispatching the event.161* @protected162*/163goog.fx.TransitionBase.prototype.onBegin = function() {164'use strict';165this.dispatchAnimationEvent(goog.fx.Transition.EventType.BEGIN);166};167168169/**170* Dispatches the END event. Sub classes should override this instead171* of listening to the event, and call this instead of dispatching the event.172* @protected173*/174goog.fx.TransitionBase.prototype.onEnd = function() {175'use strict';176this.dispatchAnimationEvent(goog.fx.Transition.EventType.END);177};178179180/**181* Dispatches the FINISH event. Sub classes should override this instead182* of listening to the event, and call this instead of dispatching the event.183* @protected184*/185goog.fx.TransitionBase.prototype.onFinish = function() {186'use strict';187this.dispatchAnimationEvent(goog.fx.Transition.EventType.FINISH);188};189190191/**192* Dispatches the PAUSE event. Sub classes should override this instead193* of listening to the event, and call this instead of dispatching the event.194* @protected195*/196goog.fx.TransitionBase.prototype.onPause = function() {197'use strict';198this.dispatchAnimationEvent(goog.fx.Transition.EventType.PAUSE);199};200201202/**203* Dispatches the PLAY event. Sub classes should override this instead204* of listening to the event, and call this instead of dispatching the event.205* @protected206*/207goog.fx.TransitionBase.prototype.onPlay = function() {208'use strict';209this.dispatchAnimationEvent(goog.fx.Transition.EventType.PLAY);210};211212213/**214* Dispatches the RESUME event. Sub classes should override this instead215* of listening to the event, and call this instead of dispatching the event.216* @protected217*/218goog.fx.TransitionBase.prototype.onResume = function() {219'use strict';220this.dispatchAnimationEvent(goog.fx.Transition.EventType.RESUME);221};222223224/**225* Dispatches the STOP event. Sub classes should override this instead226* of listening to the event, and call this instead of dispatching the event.227* @protected228*/229goog.fx.TransitionBase.prototype.onStop = function() {230'use strict';231this.dispatchAnimationEvent(goog.fx.Transition.EventType.STOP);232};233234235/**236* Dispatches an event object for the current animation.237* @param {string} type Event type that will be dispatched.238* @protected239*/240goog.fx.TransitionBase.prototype.dispatchAnimationEvent = function(type) {241'use strict';242this.dispatchEvent(type);243};244245246