/**************************************************************************** Copyright (c) 2013-2016 Chukong Technologies Inc. http://www.cocos.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated engine source code (the "Software"), a limited, worldwide, royalty-free, non-assignable, revocable and non-exclusive license to use Cocos Creator solely to develop games on your target platforms. You shall not use Cocos Creator software for developing other software or tools that's used for developing games. You are not granted to publish, distribute, sublicense, and/or sell copies of Cocos Creator. The software or tools in this License Agreement are licensed, not sold. Chukong Aipu reserves all rights not expressly granted to you. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ var JS = require("../platform/js"); /** * !#en Base class of all kinds of events. * !#zh 包含事件相关信息的对象。 * @class Event * @constructor */ /** * @method Event * @param {String} type - The name of the event (case-sensitive), e.g. "click", "fire", or "submit" * @param {Boolean} bubbles - A boolean indicating whether the event bubbles up through the tree or not * @return {Event} */ cc.Event = function(type, bubbles) { /** * !#en The name of the event (case-sensitive), e.g. "click", "fire", or "submit". * !#zh 事件类型。 * @property type * @type {String} */ this.type = type; /** * !#en Indicate whether the event bubbles up through the tree or not. * !#zh 表示该事件是否进行冒泡。 * @property bubbles * @type {Boolean} */ this.bubbles = !!bubbles; /** * !#en A reference to the target to which the event was originally dispatched. * !#zh 最初事件触发的目标 * @property target * @type {Object} */ this.target = null; /** * !#en A reference to the currently registered target for the event. * !#zh 当前目标 * @property currentTarget * @type {Object} */ this.currentTarget = null; /** * !#en * Indicates which phase of the event flow is currently being evaluated. * Returns an integer value represented by 4 constants: * - Event.NONE = 0 * - Event.CAPTURING_PHASE = 1 * - Event.AT_TARGET = 2 * - Event.BUBBLING_PHASE = 3 * The phases are explained in the [section 3.1, Event dispatch and DOM event flow] * (http://www.w3.org/TR/DOM-Level-3-Events/#event-flow), of the DOM Level 3 Events specification. * !#zh 事件阶段 * @property eventPhase * @type {Number} */ this.eventPhase = 0; /* * Indicates whether or not event.stopPropagation() has been called on the event. * @property _propagationStopped * @type {Boolean} * @private */ this._propagationStopped = false; /* * Indicates whether or not event.stopPropagationImmediate() has been called on the event. * @property _propagationImmediateStopped * @type {Boolean} * @private */ this._propagationImmediateStopped = false; }; cc.Event.prototype = { constructor: cc.Event, /** * !#en Reset the event for being stored in the object pool. * !#zh 重置对象池中存储的事件。 * @method unuse * @returns {String} */ unuse: function () { this.type = cc.Event.NO_TYPE; this.target = null; this.currentTarget = null; this.eventPhase = cc.Event.NONE; this._propagationStopped = false; this._propagationImmediateStopped = false; }, /** * !#en Reuse the event for being used again by the object pool. * !#zh 用于对象池再次使用的事件。 * @method reuse * @returns {String} */ reuse: function (type, bubbles) { this.type = type; this.bubbles = bubbles || false; }, /** * !#en Stops propagation for current event. * !#zh 停止传递当前事件。 * @method stopPropagation */ stopPropagation: function () { this._propagationStopped = true; }, /** * !#en Stops propagation for current event immediately, * the event won't even be dispatched to the listeners attached in the current target. * !#zh 立即停止当前事件的传递,事件甚至不会被分派到所连接的当前目标。 * @method stopPropagationImmediate */ stopPropagationImmediate: function () { this._propagationImmediateStopped = true; }, /** * !#en Checks whether the event has been stopped. * !#zh 检查该事件是否已经停止传递. * @method isStopped * @returns {Boolean} */ isStopped: function () { return this._propagationStopped || this._propagationImmediateStopped; }, /** * !#en *
* Gets current target of the event
* note: It only be available when the event listener is associated with node.
* It returns 0 when the listener is associated with fixed priority.
*