eventhandler.js
Class to create objects which want to handle multiple events and have their listeners easily cleaned up via a dispose method. Example:
 function Something() {
 goog.events.EventHandler.call(this);

 ... set up object ...

 // Add event listeners
 this.listen(this.starEl, 'click', this.handleStar);
 this.listen(this.headerEl, 'click', this.expand);
 this.listen(this.collapseEl, 'click', this.collapse);
 this.listen(this.infoEl, 'mouseover', this.showHover);
 this.listen(this.infoEl, 'mouseout', this.hideHover);
 }
 goog.inherits(Something, goog.events.EventHandler);

 Something.prototype.disposeInternal = function() {
 Something.superClass_.disposeInternal.call(this);
 goog.dom.removeNode(this.container);
 };


 // Then elsewhere:

 var activeSomething = null;
 function openSomething() {
 activeSomething = new Something();
 }

 function closeSomething() {
 if (activeSomething) {
 activeSomething.dispose();  // Remove event listeners
 activeSomething = null;
 }
 }
 

File Location

events/eventhandler.js

Classes

goog.events.EventHandler
Super class for objects that want to easily manage a number of event listeners. It allows a short cut to listen and also provides a quick way to remove all events listeners belonging to this object. It is optimized to use less objects if only one event is being listened to, but if that's the case, it may not be worth using the EventHandler anyway.

Public Protected Private

Global Properties

goog.events.EventHandler.KEY_POOL_INITIAL_COUNT :
Initial count for the keyPool_
Code »
goog.events.EventHandler.KEY_POOL_MAX_COUNT :
Max count for the keyPool_
Code »
goog.events.EventHandler.keyPool_ :
SimplePool to cache the key object. This was implemented to make IE6 performance better and removed an object allocation in the listen method when in steady state.
Code »
goog.events.EventHandler.key_ :
Keys for event that is being listened to if only one event is being listened to. This is a performance optimization to avoid creating an extra object if not necessary.
Code »
goog.events.EventHandler.keys_ :
Keys for events that are being listened to. This is used once there are more than one event to listen to. If there is only one event to listen to, key_ is used.
Code »

Directory events

File Reference