Instead of the manual entry in the index.html this can also be done by a "Local script" in WebIQ. This has the advantage that it does not have to be inserted manually again and again. The attached example shows a module that exports 2 functions: which are imported into WebIQ and called via buttons HINTS: The module myModule.js is manualy copied into workspace/js/custom-libs/modules The module functions can be used, but when saving any script in WebIQ an error is always displayed, because even WebIQ script check seems not to support the module syntax. This happens in both cases, code added manually or be local script. Uncaught SyntaxError: Unexpected token 'export' - source: js/custom-libs/modules/myModule.js, line: 12 column: 1 Keep in mind that modules are only supported via http and https protocol. This means they are NOT working within WebIQ standard preview. But they are working within the browser preview of WebIQ. Example module const iTest = 10
function myLog1(sInfo) {
let dt = new Date()
shmi.notify(`myLog1:${sInfo} ${("" + dt.getSeconds()).padStart(2, "0")}`)
}
function myLog2(sInfo) {
let dt = new Date()
shmi.notify(`myLog2:${sInfo} ${("" + dt.getSeconds()).padStart(3, "0")}`)
}
export {iTest, myLog1, myLog2} Local script which adds the modul to WebIQ (function () {
var MODULE_NAME = "initModul",
ENABLE_LOGGING = false,
RECORD_LOG = false,
logger = shmi.requires("visuals.tools.logging").createLogger(MODULE_NAME,
ENABLE_LOGGING, RECORD_LOG),
fLog = logger.fLog,
log = logger.log,
module = shmi.pkg(MODULE_NAME);
/**
* loads a module into WebIQ...
*/
module.run = function (self) {
// create script and add it to section head of HTML document
let myScript = document.createElement("script")
myScript.type = "module"
myScript.text = `
import * as myModule from "./js/custom-libs/modules/myModule.js"
window.myModule = myModule`
document.getElementsByTagName("head")[0].appendChild(myScript)
/* called when this local-script is disabled */
self.onDisable = function () {
self.run = false; /* from original .onDisable function of LocalScript control */
};
};
// MODULE CODE - END
fLog("module loaded");
})();
... View more