mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-06-18 02:59:04 +00:00
Fix StdEventTarget object
This commit is contained in:
parent
441a87994b
commit
d17138a980
|
@ -16,7 +16,7 @@ var Toolkit = require("lib/toolkit");
|
||||||
var pageEventId = 0;
|
var pageEventId = 0;
|
||||||
|
|
||||||
var ChromeObject = function(interfaces) {
|
var ChromeObject = function(interfaces) {
|
||||||
STD.EventableObject.apply(this, arguments); // set this object to `eventable`
|
STD.EventTarget.apply(this, arguments); // Set event-attachable object
|
||||||
|
|
||||||
this.interfaces = (typeof interfaces !== "undefined" ? interfaces : []);
|
this.interfaces = (typeof interfaces !== "undefined" ? interfaces : []);
|
||||||
this.vendor = "Chrome";
|
this.vendor = "Chrome";
|
||||||
|
|
38
lib/std.js
38
lib/std.js
|
@ -346,23 +346,49 @@ StdEvent.CAPTURING_PHASE = 1; // Not used but to be compatible
|
||||||
StdEvent.AT_TARGET = 2;
|
StdEvent.AT_TARGET = 2;
|
||||||
StdEvent.BUBBLING_PHASE = 3; // Not used but to be compatible
|
StdEvent.BUBBLING_PHASE = 3; // Not used but to be compatible
|
||||||
|
|
||||||
function StdEventableObject() {
|
function StdEventTarget() {
|
||||||
|
this.__events__ = [];
|
||||||
|
|
||||||
this.dispatchEvent = function(event) {
|
this.dispatchEvent = function(event) {
|
||||||
event.target = this;
|
event.target = this;
|
||||||
event.isTrusted = false;
|
event.isTrusted = false;
|
||||||
event.eventPhase = StdEvent.AT_TARGET;
|
event.eventPhase = StdEvent.AT_TARGET;
|
||||||
event.currentTarget = event.target;
|
event.currentTarget = event.target;
|
||||||
if(('on' + event.type) in this) this['on' + event.type](event);
|
for (var i = 0; i < this.__events__.length; i++) {
|
||||||
|
var e = this.__events__[i];
|
||||||
|
if (e.type == event.type && typeof(e.listener) === "function") {
|
||||||
|
e.listener(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.addEventListener = function(type, f) {
|
this.addEventListener = function(type, listener) {
|
||||||
if (typeof f === "function") {
|
if (typeof f === "function") {
|
||||||
this['on' + type] = f;
|
this.__events__.push({
|
||||||
|
"type": type,
|
||||||
|
"listener": listener,
|
||||||
|
"counter": StdEventTarget.__counter__
|
||||||
|
});
|
||||||
|
StdEventTarget.__counter__++;
|
||||||
|
} else {
|
||||||
|
throw new TypeError("EventListener must be a function");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.removeEventListener = function(type, listener) {
|
||||||
|
if (typeof f === "function") {
|
||||||
|
for (var i = 0; i < this.__events__.length; i++) {
|
||||||
|
var e = this.__events__[i];
|
||||||
|
if (e.type == event.type && typeof(e.listener) === "function" && e.listener.toString() == listener.toString()) {
|
||||||
|
delete this.__events__[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new TypeError("EventListener must be a function");
|
throw new TypeError("EventListener must be a function");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
StdEventTarget.__counter__ = 0;
|
||||||
|
|
||||||
function AsyncFunction(f, _filename) {
|
function AsyncFunction(f, _filename) {
|
||||||
this.f = f;
|
this.f = f;
|
||||||
|
@ -424,12 +450,12 @@ global.splitLn = splitLn;
|
||||||
global.addslashes = addslashes;
|
global.addslashes = addslashes;
|
||||||
global.AsyncFunction = AsyncFunction;
|
global.AsyncFunction = AsyncFunction;
|
||||||
|
|
||||||
exports.VERSIONINFO = "Standard Library (std.js) version 0.7";
|
exports.VERSIONINFO = "Standard Library (std.js) version 0.7.1";
|
||||||
exports.global = global;
|
exports.global = global;
|
||||||
exports.require = global.require;
|
exports.require = global.require;
|
||||||
|
|
||||||
exports.Event = StdEvent;
|
exports.Event = StdEvent;
|
||||||
exports.EventableObject = StdEventableObject;
|
exports.EventTarget = StdEventTarget;
|
||||||
|
|
||||||
exports.alert = alert;
|
exports.alert = alert;
|
||||||
exports.cartesian = cartesian;
|
exports.cartesian = cartesian;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user