diff --git a/lib/std.js b/lib/std.js index 5f31a64..0f4f4c3 100644 --- a/lib/std.js +++ b/lib/std.js @@ -59,11 +59,11 @@ global.sleep = function(ms, callback) { setTimeout(callback, ms); } } -} +}; global.CHR = function(ord) { return String.fromCharCode(ord); -} +}; ///////////////////////////////////////////////////////////////////////////////// // Private APIs / Utility functions @@ -104,6 +104,57 @@ exports.CreateObject = function(progId, serverName, callback) { ///////////////////////////////////////////////////////////////////////////////// -exports.VERSIONINFO = "Standard Lib (std.js) version 0.2"; +var stdEvent = function(eventName) { + this.bubbles = false; // Not supported + this.cancelable = false; // Not supported + this.composed = false; // Not supported + this.currentTarget = null; // Not supported + this.defaultPrevented = false; + this.eventPhase = null; + this.isTrusted = true; // Not supported + this.timeStamp = new Date(); + + this.eventName = eventName; + this.target = null; + + // Not supported + this.composedPath = function() { + return null; + }; + + this.preventDefault = function() { + this.defaultPrevented = true; + }; + + // Not supported + this.stopImmediatePropagation = function() { + return null; + }; + + // Not supported + this.setPropagation = function() { + return null; + }; +}; + +var stdEventableObject = function() { + this.dispatchEvent = function(event) { + event.target = this; + if(eventName in this) this['on' + event.eventName](event); + }; + + this.addEventListener = function(eventName, fn) { + if (typeof(fn) == "function") { + this['on' + eventName] = fn; + } else { + throw new TypeError("EventListener must be a function"); + } + }; +}; + +exports.VERSIONINFO = "Standard Lib (std.js) version 0.3"; exports.global = global; exports.require = global.require; + +exports.Event = stdEvent; +exports.EventableObject = stdEventableObject;