mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-02-06 15:04:58 +00:00
Update std.js
This commit is contained in:
parent
cc22c44489
commit
51389c7780
40
lib/std.js
40
lib/std.js
|
@ -310,26 +310,54 @@ function alert(msg) {
|
|||
// Standard Event Object
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function StdEvent(eventName) {
|
||||
// https://developer.mozilla.org/ko/docs/Web/API/Event
|
||||
|
||||
function StdEvent(type) {
|
||||
this.defaultPrevented = false;
|
||||
this.timeStamp = new Date();
|
||||
this.eventName = eventName;
|
||||
this.type = type;
|
||||
this.isTrusted = true;
|
||||
this.cancelable = true;
|
||||
this.target = null;
|
||||
this.currentTarget = null;
|
||||
this.eventPhase = StdEvent.NONE;
|
||||
this.bubbles = false; // Not used but to be compatible
|
||||
this.composed = false; // Not used but to be compatible
|
||||
|
||||
this.preventDefault = function() {
|
||||
this.defaultPrevented = true;
|
||||
};
|
||||
|
||||
// Not used but to be compatible
|
||||
this.initEvent(type, bubbles, cancelable) {
|
||||
this.type = type;
|
||||
this.bubbles = bubbles;
|
||||
this.cancelable = cancelable;
|
||||
};
|
||||
|
||||
// Not used but to be compatible
|
||||
this.stopImmediatePropagation = function() {};
|
||||
|
||||
// Not used but to be compatible
|
||||
this.stopPropagation = function() {};
|
||||
};
|
||||
StdEvent.NONE = 0;
|
||||
StdEvent.CAPTURING_PHASE = 1; // Not used but to be compatible
|
||||
StdEvent.AT_TARGET = 2;
|
||||
StdEvent.BUBBLING_PHASE = 3; // Not used but to be compatible
|
||||
|
||||
function StdEventableObject() {
|
||||
this.dispatchEvent = function(event) {
|
||||
event.target = this;
|
||||
if(('on' + event.eventName) in this) this['on' + event.eventName](event);
|
||||
event.isTrusted = false;
|
||||
event.eventPhase = StdEvent.AT_TARGET;
|
||||
event.currentTarget = event.target;
|
||||
if(('on' + event.type) in this) this['on' + event.type](event);
|
||||
};
|
||||
|
||||
this.addEventListener = function(eventName, fn) {
|
||||
if (typeof fn === "function") {
|
||||
this['on' + eventName] = fn;
|
||||
this.addEventListener = function(type, f) {
|
||||
if (typeof f === "function") {
|
||||
this['on' + type] = f;
|
||||
} else {
|
||||
throw new TypeError("EventListener must be a function");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user