@robotlegsjs/core
Version:
An architecture-based IoC framework for JavaScript/TypeScript
270 lines • 11.4 kB
JavaScript
"use strict";
//////////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014-present, Egret Technology.
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the Egret nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
Object.defineProperty(exports, "__esModule", { value: true });
exports.Event = void 0;
/**
* The Event class is used as the base class for the creation of Event objects, which are passed as parameters to event
* listeners when an event occurs.The properties of the Event class carry basic information about an event, such as
* the event's type or whether the event's default behavior can be canceled. For many events, such as the events represented
* by the Event class constants, this basic information is sufficient. Other events, however, may require more detailed
* information. Events associated with a touch tap, for example, need to include additional information about the
* location of the touch event. You can pass such additional information to event listeners by extending the Event class,
* which is what the TouchEvent class does. Egret API defines several Event subclasses for common events that require
* additional information. Events associated with each of the Event subclasses are described in the documentation for
* each class.The methods of the Event class can be used in event listener functions to affect the behavior of the event
* object. Some events have an associated default behavior. Your event listener can cancel this behavior by calling the
* preventDefault() method. You can also make the current event listener the last one to process an event by calling
* the stopPropagation() or stopImmediatePropagation() method.
*
* @see egret.EventDispatcher
* @version Egret 2.4
* @platform Web,Native
* @includeExample egret/events/Event.ts
* @see http://edn.egret.com/cn/docs/page/798 取消触摸事件
* @language en_US
*/
var Event = /** @class */ (function () {
/**
* Creates an Event object to pass as a parameter to event listeners.
*
* @param type The type of the event, accessible as Event.type.
* @param bubbles Determines whether the Event object participates in the bubbling stage of the event flow. The default value is false.
* @param cancelable Determines whether the Event object can be canceled. The default values is false.
* @param data the optional data associated with this event
* @version Egret 2.4
* @platform Web,Native
* @language en_US
*/
function Event(type, bubbles, cancelable, data) {
/**
* @private
*/
this._isDefaultPrevented = false;
/**
* @private
*/
this._isPropagationStopped = false;
/**
* @private
*/
this._isPropagationImmediateStopped = false;
this._type = type;
this._bubbles = !!bubbles;
this._cancelable = !!cancelable;
this._data = data;
}
/**
* Cancels an event's default behavior if that behavior can be canceled.Many events have associated behaviors that
* are carried out by default. For example, if a user types a character into a text input, the default behavior
* is that the character is displayed in the text input. Because the TextEvent.TEXT_INPUT event's default behavior
* can be canceled, you can use the preventDefault() method to prevent the character from appearing.
* You can use the Event.cancelable property to check whether you can prevent the default behavior associated with
* a particular event. If the value of Event.cancelable is true, then preventDefault() can be used to cancel the event;
* otherwise, preventDefault() has no effect.
*
* @see #cancelable
* @see #isDefaultPrevented
* @version Egret 2.4
* @platform Web,Native
* @language en_US
*/
Event.prototype.preventDefault = function () {
if (this._cancelable) {
this._isDefaultPrevented = true;
}
};
/**
* Prevents processing of any event listeners in nodes subsequent to the current node in the event flow. This method
* does not affect any event listeners in the current node (currentTarget). In contrast, the stopImmediatePropagation()
* method prevents processing of event listeners in both the current node and subsequent nodes. Additional calls to this
* method have no effect. This method can be called in any phase of the event flow.<br/>
* Note: This method does not cancel the behavior associated with this event; see preventDefault() for that functionality.
*
* @see #stopImmediatePropagation()
* @see #preventDefault()
* @version Egret 2.4
* @platform Web,Native
* @language en_US
*/
Event.prototype.stopPropagation = function () {
if (this._bubbles) {
this._isPropagationStopped = true;
}
};
/**
* Prevents processing of any event listeners in the current node and any subsequent nodes in the event flow.
* This method takes effect immediately, and it affects event listeners in the current node. In contrast, the
* stopPropagation() method doesn't take effect until all the event listeners in the current node finish processing.<br/>
* Note: This method does not cancel the behavior associated with this event; see preventDefault() for that functionality.
*
* @see #stopPropagation()
* @see #preventDefault()
* @version Egret 2.4
* @platform Web,Native
* @language en_US
*/
Event.prototype.stopImmediatePropagation = function () {
if (this._bubbles) {
this._isPropagationImmediateStopped = true;
}
};
Object.defineProperty(Event.prototype, "type", {
/**
* The type of event. The type is case-sensitive.
*
* @version Egret 2.4
* @platform Web,Native
* @language en_US
*/
get: function () {
return this._type;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Event.prototype, "bubbles", {
/**
* Indicates whether an event is a bubbling event.
*
* @version Egret 2.4
* @platform Web,Native
* @language en_US
*/
get: function () {
return this._bubbles;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Event.prototype, "cancelable", {
/**
* Indicates whether the behavior associated with the event can be prevented. If the behavior can be
* canceled, this value is true; otherwise it is false.
*
* @see #preventDefault()
* @version Egret 2.4
* @platform Web,Native
* @language en_US
*/
get: function () {
return this._cancelable;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Event.prototype, "isDefaultPrevented", {
/**
* Checks whether the preventDefault() method has been called on the event. If the preventDefault() method has been
* called, returns true; otherwise, returns false.
*
* @returns If preventDefault() has been called, returns true; otherwise, returns false.
* @see #preventDefault()
* @version Egret 2.4
* @platform Web,Native
* @language en_US
*/
get: function () {
return this._isDefaultPrevented;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Event.prototype, "isPropagationStopped", {
get: function () {
return this._isPropagationStopped;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Event.prototype, "isPropagationImmediateStopped", {
get: function () {
return this._isPropagationImmediateStopped;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Event.prototype, "currentTarget", {
/**
* The object that is actively processing the Event object with an event listener. For example, if a
* user clicks an OK button, the current target could be the node containing that button or one of its ancestors
* that has registered an event listener for that event.
*
* @version Egret 2.4
* @platform Web,Native
* @language en_US
*/
get: function () {
return this._currentTarget;
},
set: function (value) {
this._currentTarget = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Event.prototype, "target", {
/**
* The event target. This property contains the target node. For example, if a user clicks an OK button,
* the target node is the display list node containing that button.
*
* @version Egret 2.4
* @platform Web,Native
* @language en_US
*/
get: function () {
return this._target;
},
set: function (value) {
this._target = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Event.prototype, "data", {
/**
* the optional data associated with this event
*
* @version Egret 2.4
* @platform Web,Native
* @language en_US
*/
get: function () {
return this._data;
},
set: function (value) {
this._data = value;
},
enumerable: false,
configurable: true
});
return Event;
}());
exports.Event = Event;
//# sourceMappingURL=Event.js.map