2020-06-28 14:22:57 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// std.js
|
|
|
|
//
|
|
|
|
// Common routines. Defines LIB object which contains the API, as well as
|
|
|
|
// a global DBG function.
|
|
|
|
//
|
2020-07-19 21:19:33 +00:00
|
|
|
// References:
|
2020-06-28 14:22:57 +00:00
|
|
|
// * https://github.com/redskyit/wsh-appjs
|
|
|
|
// * https://github.com/JSman-/JS-Framework
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
2020-07-19 21:19:33 +00:00
|
|
|
// Polyfills
|
2020-06-28 14:22:57 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
2020-07-19 21:19:33 +00:00
|
|
|
if (!Function.prototype.GetResource) {
|
2020-06-28 16:37:15 +00:00
|
|
|
Function.prototype.GetResource = function(ResourceName) {
|
2020-07-03 09:15:23 +00:00
|
|
|
if (!this.Resources) {
|
|
|
|
var UnNamedResourceIndex = 0,
|
|
|
|
_this = this;
|
2020-06-28 16:37:15 +00:00
|
|
|
this.Resources = {};
|
2020-07-03 09:15:23 +00:00
|
|
|
|
|
|
|
function f(match, resType, Content) {
|
|
|
|
_this.Resources[(resType == "[[") ? UnNamedResourceIndex++ : resType.slice(1, -1)] = Content;
|
2020-06-28 16:37:15 +00:00
|
|
|
}
|
|
|
|
this.toString().replace(/\/\*(\[(?:[^\[]+)?\[)((?:[\r\n]|.)*?)\]\]\*\//gi, f);
|
2020-06-28 14:22:57 +00:00
|
|
|
}
|
2020-07-03 09:15:23 +00:00
|
|
|
|
2020-06-28 16:37:15 +00:00
|
|
|
return this.Resources[ResourceName];
|
2020-06-28 14:22:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-19 21:19:33 +00:00
|
|
|
// ECMAScript 5 compatibility shims for legacy (and modern) JavaScript engines
|
2020-07-21 10:10:20 +00:00
|
|
|
require("app/assets/js/es5-shim-4.5.14.min");
|
|
|
|
require("app/assets/js/es5-sham-4.5.14.min");
|
2020-07-19 21:19:33 +00:00
|
|
|
|
2020-07-19 22:05:42 +00:00
|
|
|
// JSON 3 was a JSON polyfill for older JavaScript platforms
|
2020-07-21 10:10:20 +00:00
|
|
|
require("app/assets/js/json3-3.3.2.min");
|
2020-07-19 22:05:42 +00:00
|
|
|
|
2020-07-19 21:19:33 +00:00
|
|
|
// ECMAScript 6 compatibility shims for legacy JS engines
|
2020-07-21 10:10:20 +00:00
|
|
|
require("app/assets/js/es6-shim-0.35.5.min");
|
|
|
|
require("app/assets/js/es6-sham-0.35.5.min");
|
2020-07-19 21:19:33 +00:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Global APIs
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2020-06-28 16:37:15 +00:00
|
|
|
global.GetResource = function(ResourceName) {
|
2020-06-28 14:22:57 +00:00
|
|
|
return arguments.callee.caller.GetResource(ResourceName);
|
|
|
|
}
|
|
|
|
|
|
|
|
global.sleep = function(ms, callback) {
|
2020-07-03 09:15:23 +00:00
|
|
|
if (typeof(WScript) !== "undefined") {
|
2020-06-28 16:37:15 +00:00
|
|
|
WScript.Sleep(ms);
|
2020-07-03 09:15:23 +00:00
|
|
|
if (typeof(callback) === "function") {
|
2020-06-28 16:37:15 +00:00
|
|
|
callback();
|
|
|
|
}
|
|
|
|
} else {
|
2020-07-03 09:15:23 +00:00
|
|
|
if (typeof(callback) === "function") {
|
2020-06-28 16:37:15 +00:00
|
|
|
setTimeout(callback, ms);
|
|
|
|
}
|
2020-06-28 14:22:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-26 12:01:05 +00:00
|
|
|
global.CHR = function(ord) {
|
2020-11-04 07:30:52 +00:00
|
|
|
return String.fromCharCode(ord);
|
2020-10-26 12:01:05 +00:00
|
|
|
}
|
|
|
|
|
2020-06-28 14:22:57 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Private APIs / Utility functions
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2020-07-20 18:57:53 +00:00
|
|
|
exports.VERSIONINFO = "Standard Lib (std.js) version 0.2";
|
|
|
|
exports.global = global;
|
|
|
|
exports.require = global.require;
|
2020-06-28 14:22:57 +00:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Emulate Server.CreateObject
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2020-10-20 05:18:00 +00:00
|
|
|
exports.CreateObject = function(progId, serverName) {
|
|
|
|
var progIds = [];
|
|
|
|
var _CreateObject = function(p, s) {
|
|
|
|
if (typeof(WScript) !== "undefined") {
|
|
|
|
return WScript.CreateObject(p, s);
|
|
|
|
} else {
|
|
|
|
return new ActiveXObject(p, s);
|
|
|
|
}
|
|
|
|
};
|
2020-10-20 02:41:26 +00:00
|
|
|
|
2020-10-20 05:18:00 +00:00
|
|
|
if (typeof(progId) == "object") {
|
|
|
|
progIds = progId;
|
2020-10-20 02:41:26 +00:00
|
|
|
} else {
|
2020-10-20 05:18:00 +00:00
|
|
|
progIds.push(progId);
|
2020-10-20 02:41:26 +00:00
|
|
|
}
|
|
|
|
|
2020-10-20 05:18:00 +00:00
|
|
|
for (var i = 0; i < progIds.length; i++) {
|
|
|
|
try {
|
2020-11-04 07:30:52 +00:00
|
|
|
return _CreateObject(progIds[i], serverName);
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e.message);
|
|
|
|
};
|
2020-10-20 02:41:26 +00:00
|
|
|
}
|
2020-07-03 09:15:23 +00:00
|
|
|
};
|
2020-06-28 14:22:57 +00:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|