# lib/goog/events/event.js

    1// Copyright 2005 The Closure Library Authors. All Rights Reserved.2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7//      http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS-IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.1415/**16 * @fileoverview A base class for event objects.17 *18 */192021goog.provide('goog.events.Event');22goog.provide('goog.events.EventLike');2324/**25 * goog.events.Event no longer depends on goog.Disposable. Keep requiring26 * goog.Disposable here to not break projects which assume this dependency.27 * @suppress {extraRequire}28 */29goog.require('goog.Disposable');30goog.require('goog.events.EventId');313233/**34 * A typedef for event like objects that are dispatchable via the35 * goog.events.dispatchEvent function. strings are treated as the type for a36 * goog.events.Event. Objects are treated as an extension of a new37 * goog.events.Event with the type property of the object being used as the type38 * of the Event.39 * @typedef {string|Object|goog.events.Event|goog.events.EventId}40 */41goog.events.EventLike;42434445/**46 * A base class for event objects, so that they can support preventDefault and47 * stopPropagation.48 *49 * @param {string|!goog.events.EventId} type Event Type.50 * @param {Object=} opt_target Reference to the object that is the target of51 *     this event. It has to implement the {@code EventTarget} interface52 *     declared at {@link http://developer.mozilla.org/en/DOM/EventTarget}.53 * @constructor54 */55goog.events.Event = function(type, opt_target) {56  /**57   * Event type.58   * @type {string}59   */60  this.type = type instanceof goog.events.EventId ? String(type) : type;6162  /**63   * TODO(user): The type should probably be64   * EventTarget|goog.events.EventTarget.65   *66   * Target of the event.67   * @type {Object|undefined}68   */69  this.target = opt_target;7071  /**72   * Object that had the listener attached.73   * @type {Object|undefined}74   */75  this.currentTarget = this.target;7677  /**78   * Whether to cancel the event in internal capture/bubble processing for IE.79   * @type {boolean}80   * @public81   * @suppress {underscore|visibility} Technically public, but referencing this82   *     outside this package is strongly discouraged.83   */84  this.propagationStopped_ = false;8586  /**87   * Whether the default action has been prevented.88   * This is a property to match the W3C specification at89   * {@link http://www.w3.org/TR/DOM-Level-3-Events/90   * #events-event-type-defaultPrevented}.91   * Must be treated as read-only outside the class.92   * @type {boolean}93   */94  this.defaultPrevented = false;9596  /**97   * Return value for in internal capture/bubble processing for IE.98   * @type {boolean}99   * @public100   * @suppress {underscore|visibility} Technically public, but referencing this101   *     outside this package is strongly discouraged.102   */103  this.returnValue_ = true;104};105106107/**108 * For backwards compatibility (goog.events.Event used to inherit109 * goog.Disposable).110 * @deprecated Events don't need to be disposed.111 */112goog.events.Event.prototype.disposeInternal = function() {113};114115116/**117 * For backwards compatibility (goog.events.Event used to inherit118 * goog.Disposable).119 * @deprecated Events don't need to be disposed.120 */121goog.events.Event.prototype.dispose = function() {122};123124125/**126 * Stops event propagation.127 */128goog.events.Event.prototype.stopPropagation = function() {129  this.propagationStopped_ = true;130};131132133/**134 * Prevents the default action, for example a link redirecting to a url.135 */136goog.events.Event.prototype.preventDefault = function() {137  this.defaultPrevented = true;138  this.returnValue_ = false;139};140141142/**143 * Stops the propagation of the event. It is equivalent to144 * {@code e.stopPropagation()}, but can be used as the callback argument of145 * {@link goog.events.listen} without declaring another function.146 * @param {!goog.events.Event} e An event.147 */148goog.events.Event.stopPropagation = function(e) {149  e.stopPropagation();150};151152153/**154 * Prevents the default action. It is equivalent to155 * {@code e.preventDefault()}, but can be used as the callback argument of156 * {@link goog.events.listen} without declaring another function.157 * @param {!goog.events.Event} e An event.158 */159goog.events.Event.preventDefault = function(e) {160  e.preventDefault();161};