Update std.js

This commit is contained in:
Namhyeon Go 2022-05-10 11:45:02 +09:00 committed by GitHub
parent cc22c44489
commit 51389c7780
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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");
}