hedera-web/js/hedera/module.js

116 lines
2.0 KiB
JavaScript
Raw Normal View History

2016-09-26 09:28:47 +00:00
module.exports = new Class
({
basePath: null
,path: null
,moduleName: null
,callbacks: []
,localeReady: false
,jsReady: false
,uiReady: false
,error: false
,ready: false
,initialize: function (basePath, path)
{
var absPath = basePath +'/'+ path;
var aux = path.split ('/');
var moduleName = aux[aux.length - 1];
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;
}
2017-03-23 16:20:51 +00:00
,getCssPath: function ()
{
return this.basePath +'/'+ this.path +'/style.css';
}
,includeCss: function ()
{
Vn.includeCss (this.getCssPath ());
}
,unload: function ()
{
Vn.excludeCss (this.getCssPath ());
}
2017-03-23 16:20:51 +00:00
,load: function (callback)
{
2017-03-23 16:20:51 +00:00
if (this.ready)
{
this.includeCss ();
callback (this);
2017-03-23 16:20:51 +00:00
}
else
this.callbacks.push (callback);
}
,onLocaleReady: function (success)
{
this.localeReady = true;
this.onReady ();
}
,onJsReady: function (success)
{
this.jsReady = true;
this.error = !success;
this.onReady ();
}
,onUiReady: function (success)
{
this.uiReady = true;
this.error = !success;
this.onReady ();
}
,onReady: function ()
{
if (!(this.localeReady && this.jsReady && this.uiReady))
return;
2015-11-09 08:14:33 +00:00
this.ready = true;
var klassName = this.toCamelCase (this.moduleName);
try {
2016-09-26 09:28:47 +00:00
this.klass = Hedera[klassName];
}
catch (e)
{
this.error = true;
console.error (e);
}
var callbacks = this.callbacks;
this.callbacks = null;
2017-03-23 16:20:51 +00:00
this.includeCss ();
for (var i = 0; i < callbacks.length; i++)
callbacks[i] (this);
}
,toCamelCase: function (dashedName)
{
2016-08-22 10:41:05 +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;
}
});