Path: blob/trunk/third_party/closure/goog/events/event.js
4143 views
/**1* @license2* Copyright The Closure Library Authors.3* SPDX-License-Identifier: Apache-2.04*/56/**7* @fileoverview A base class for event objects.8*/91011goog.provide('goog.events.Event');1213/**14* goog.events.Event no longer depends on goog.Disposable. Keep requiring15* goog.Disposable here to not break projects which assume this dependency.16* @suppress {extraRequire}17*/18goog.require('goog.Disposable');19goog.require('goog.events.EventId');202122/**23* A base class for event objects, so that they can support preventDefault and24* stopPropagation.25*26* @param {string|!goog.events.EventId} type Event Type.27* @param {Object=} opt_target Reference to the object that is the target of28* this event. It has to implement the `EventTarget` interface29* declared at {@link http://developer.mozilla.org/en/DOM/EventTarget}.30* @constructor31*/32goog.events.Event = function(type, opt_target) {33'use strict';34/**35* Event type.36* @type {string}37*/38this.type = type instanceof goog.events.EventId ? String(type) : type;3940/**41* TODO(tbreisacher): The type should probably be42* EventTarget|goog.events.EventTarget.43*44* Target of the event.45* @type {Object|undefined}46*/47this.target = opt_target;4849/**50* Object that had the listener attached.51* @type {Object|undefined}52*/53this.currentTarget = this.target;5455/**56* Whether to cancel the event in internal capture/bubble processing for IE.57* @type {boolean}58* @private59*/60this.propagationStopped_ = false;6162/**63* Whether the default action has been prevented.64* This is a property to match the W3C specification at65* {@link http://www.w3.org/TR/DOM-Level-3-Events/66* #events-event-type-defaultPrevented}.67* Must be treated as read-only outside the class.68* @type {boolean}69*/70this.defaultPrevented = false;71};7273/**74* @return {boolean} true iff internal propagation has been stopped.75*/76goog.events.Event.prototype.hasPropagationStopped = function() {77'use strict';78return this.propagationStopped_;79};8081/**82* Stops event propagation.83* @return {void}84*/85goog.events.Event.prototype.stopPropagation = function() {86'use strict';87this.propagationStopped_ = true;88};899091/**92* Prevents the default action, for example a link redirecting to a url.93* @return {void}94*/95goog.events.Event.prototype.preventDefault = function() {96'use strict';97this.defaultPrevented = true;98};99100101/**102* Stops the propagation of the event. It is equivalent to103* `e.stopPropagation()`, but can be used as the callback argument of104* {@link goog.events.listen} without declaring another function.105* @param {!goog.events.Event} e An event.106* @return {void}107*/108goog.events.Event.stopPropagation = function(e) {109'use strict';110e.stopPropagation();111};112113114/**115* Prevents the default action. It is equivalent to116* `e.preventDefault()`, but can be used as the callback argument of117* {@link goog.events.listen} without declaring another function.118* @param {!goog.events.Event} e An event.119* @return {void}120*/121goog.events.Event.preventDefault = function(e) {122'use strict';123e.preventDefault();124};125126127