Class for handling timing events.

Inheritance

Constructor

goog.Timer(opt_intervalopt_timerObject)

Parameters

opt_interval :
(number | undefined)
Number of ms between ticks (Default: 1ms).
opt_timerObject :
(Object | null | undefined)
An object that has setTimeout, setInterval, clearTimeout and clearInterval (eg Window).

Instance Methods

Public Protected Private
Defined in goog.Timer
dispatchTick()
Dispatches the TICK event. This is its own method so subclasses can override.
code »
disposeInternal()
No description.
code »
getInterval()
Gets the interval of the timer.
Returns:   interval Number of ms between ticks.
code »
setInterval(interval)
Sets the interval of the timer.
Arguments:
interval :
Number of ms between ticks.
code »
start()
Starts the timer.
code »
stop()
Stops the timer.
code »
tick_()
Callback for the setTimeout used by the timer
code »
addEventListener(typehandleropt_captureopt_handlerScope)
Adds an event listener to the event target. The same handler can only be added once per the type. Even if you add the same handler multiple times using the same type then it will only be called once when the event is dispatched. Supported for legacy but use goog.events.listen(src, type, handler) instead.
Arguments:
type :
The type of the event to listen for.
handler :
(Object | null)
The function to handle the event. The handler can also be an object that implements the handleEvent method which takes the event object as argument.
opt_capture :
(boolean | undefined)
In DOM-compliant browsers, this determines whether the listener is fired during the capture or bubble phase of the event.
opt_handlerScope :
(Object | null | undefined)
Object in whose scope to call the listener.
code »
dispatchEvent(e)
Dispatches an event (or event like object) and calls all listeners listening for events of this type. The type of the event is decided by the type property on the event object. If any of the listeners returns false OR calls preventDefault then this function will return false. If one of the capture listeners calls stopPropagation, then the bubble listeners won't fire.
Arguments:
e :
(Object | goog.events.Event | null | string)
Event object.
Returns:   If anyone called preventDefault on the event object (or if any of the handlers returns false this will also return false.
code »
disposeInternal()
Unattach listeners from this object. Classes that extend EventTarget may need to override this method in order to remove references to DOM Elements and additional listeners, it should be something like this:
MyClass.prototype.disposeInternal = function() {
MyClass.superClass_.disposeInternal.call(this);
// Dispose logic for MyClass
};
code »
getParentEventTarget()
Returns the parent of this event target to use for bubbling.
Returns:   The parent EventTarget or null if there is no parent.
code »
removeEventListener(typehandleropt_captureopt_handlerScope)
Removes an event listener from the event target. The handler must be the same object as the one added. If the handler has not been added then nothing is done.
Arguments:
type :
The type of the event to listen for.
handler :
(Object | null)
The function to handle the event. The handler can also be an object that implements the handleEvent method which takes the event object as argument.
opt_capture :
(boolean | undefined)
In DOM-compliant browsers, this determines whether the listener is fired during the capture or bubble phase of the event.
opt_handlerScope :
(Object | null | undefined)
Object in whose scope to call the listener.
code »
setParentEventTarget(parent)
Sets the parent of this event target to use for bubbling.
Arguments:
parent :
Parent EventTarget (null if none).
code »
dispose()
undefined
Disposes of the object. If the object hasn't already been disposed of, calls #disposeInternal. Classes that extend goog.Disposable should override #disposeInternal in order to delete references to COM objects, DOM nodes, and other disposable objects. Reentrant.
Returns: 
undefined
  Nothing.
code »
disposeInternal()
Deletes or nulls out any references to COM objects, DOM nodes, or other disposable objects. Classes that extend goog.Disposable should override this method. Not reentrant. To avoid calling it twice, it must only be called from the subclass' disposeInternal method. Everywhere else the public dispose method must be used. For example:
mypackage.MyClass = function() {
goog.base(this);
// Constructor logic specific to MyClass.
...
};
goog.inherits(mypackage.MyClass, goog.Disposable);

mypackage.MyClass.prototype.disposeInternal = function() {
goog.base(this, 'disposeInternal');
// Dispose logic specific to MyClass.
...
};
code »
getDisposed()
Use #isDisposed instead. No description.
Returns:   Whether the object has been disposed of.
code »
isDisposed()
No description.
Returns:   Whether the object has been disposed of.
code »
registerDisposable(disposable)
Associates a disposable object with this object so that they will be disposed together.
Arguments:
disposable :
that will be disposed when this object is disposed.
code »

Instance Properties

Defined in goog.Timer
boundTick_ :
(Function | null)
Cached tick_ bound to the object for later use in the timer.
Code »
enabled :
Whether this timer is enabled
Code »
interval_ :
Number of ms between ticks
Code »
last_ :
Firefox browser often fires the timer event sooner (sometimes MUCH sooner) than the requested timeout. So we compare the time to when the event was last fired, and reschedule if appropriate. See also goog.Timer.intervalScale
Code »
timerObject_ :
(Object | null)
An object that implements setTimout, setInterval, clearTimeout and clearInterval. We default to the window object. Changing this on goog.Timer.prototype changes the object for all timer instances which can be useful if your environment has some other implementation of timers than the window object.
Code »
timer_ :
(null | number)
Variable for storing the result of setInterval
Code »
customEvent_ :
Used to tell if an event is a real event in goog.events.listen() so we don't get listen() calling addEventListener() and vice-versa.
Code »
parentEventTarget_ :
Parent event target, used during event bubbling.
Code »
dependentDisposables_ :
(Array | null)
Disposables that should be disposed when this object is disposed.
Code »
disposed_ :
Whether the object has been disposed of.
Code »

Static Methods

goog.Timer.callOnce(listeneropt_delayopt_handler)
Calls the given function once, after the optional pause. The function is always called asynchronously, even if the delay is 0. This is a common trick to schedule a function to run after a batch of browser event processing.
Arguments:
listener :
(Function | null)
Function or object that has a handleEvent method.
opt_delay :
(number | undefined)
Milliseconds to wait; default is 0.
opt_handler :
(Object | null | undefined)
Object in whose scope to call the listener.
Returns:   A handle to the timer ID.
code »
goog.Timer.clear(timerId)
Clears a timeout initiated by callOnce
Arguments:
timerId :
(null | number)
a timer ID.
code »

Static Properties

goog.Timer.MAX_TIMEOUT_ :
Maximum timeout value. Timeout values too big to fit into a signed 32-bit integer may cause overflow in FF, Safari, and Chrome, resulting in the timeout being scheduled immediately. It makes more sense simply not to schedule these timeouts, since 24.8 days is beyond a reasonable expectation for the browser to stay open.
Code »
goog.Timer.TICK :
Constant for the timer's event type
Code »
goog.Timer.defaultTimerObject :
(Object | null)
An object that implements setTimout, setInterval, clearTimeout and clearInterval. We default to the window object. Changing this on goog.Timer.prototype changes the object for all timer instances which can be useful if your environment has some other implementation of timers than the window object.
Code »
goog.Timer.intervalScale :
A variable that controls the timer error correction. If the timer is called before the requested interval times intervalScale, which often happens on mozilla, the timer is rescheduled. See also this.last_
Code »

Package Timer

Package Reference