0
1
Fork 0
hedera-web-mindshore/js/hedera/module.js

86 lines
1.6 KiB
JavaScript
Raw Normal View History

2022-06-06 16:19:43 +00:00
module.exports = new Class({
basePath: null
,path: null
,moduleName: null
,callbacks: []
,localeReady: false
,jsReady: false
,uiReady: false
,error: false
,ready: false
2022-11-16 01:46:44 +00:00
,initialize(basePath, path) {
var absPath = basePath +'/'+ path;
2022-06-06 16:19:43 +00:00
var aux = path.split('/');
var moduleName = aux[aux.length - 1];
2022-06-06 16:19:43 +00:00
Vn.Locale.load(absPath,
this.onLocaleReady.bind(this));
Vn.includeJs(absPath +'/'+ moduleName +'.js',
this.onJsReady.bind(this));
Vn.loadXml(absPath +'/ui.xml',
this.onUiReady.bind(this));
this.basePath = basePath;
this.path = path;
this.moduleName = moduleName;
}
2022-11-16 01:46:44 +00:00
,addCallback(callback) {
if (!this.ready)
2022-06-06 16:19:43 +00:00
this.callbacks.push(callback);
else
2022-06-06 16:19:43 +00:00
callback(this);
}
2022-11-16 01:46:44 +00:00
,onLocaleReady() {
this.localeReady = true;
2022-06-06 16:19:43 +00:00
this.onReady();
}
2022-11-16 01:46:44 +00:00
,onJsReady(success) {
this.jsReady = true;
this.error = !success;
2022-06-06 16:19:43 +00:00
this.onReady();
}
2022-11-16 01:46:44 +00:00
,onUiReady(success) {
this.uiReady = true;
this.error = !success;
2022-06-06 16:19:43 +00:00
this.onReady();
}
2022-11-16 01:46:44 +00:00
,onReady() {
if (!(this.localeReady && this.jsReady && this.uiReady))
return;
2015-11-09 08:14:33 +00:00
this.ready = true;
2022-06-06 16:19:43 +00:00
var klassName = this.toCamelCase(this.moduleName);
try {
2016-09-26 09:28:47 +00:00
this.klass = Hedera[klassName];
2022-06-06 16:19:43 +00:00
} catch (e) {
this.error = true;
2022-06-06 16:19:43 +00:00
console.error(e);
}
var callbacks = this.callbacks;
this.callbacks = null;
for (var i = 0; i < callbacks.length; i++)
2022-06-06 16:19:43 +00:00
callbacks[i](this);
}
2022-11-16 01:46:44 +00:00
,toCamelCase(dashedName) {
2022-06-06 16:19:43 +00:00
var camelCase = dashedName.charAt(0).toUpperCase();
camelCase += dashedName.substr(1).replace(/\w-\w/g, function(token) {
return token.charAt(0) + token.charAt(2).toUpperCase();
});
return camelCase;
}
});