Added "template" function for /app to async load of templates (html)

This commit is contained in:
Niko 2022-02-12 00:59:37 +01:00
parent 8967289631
commit 0eddaed6a1
2 changed files with 15 additions and 0 deletions

View File

@ -7,6 +7,21 @@ app.script = function(name, cback) {
loadScript(name, file, cback);
}
app.template = function(name, cback) {
if (window.__cache_templates === undefined)
window.__cache_templates = {};
file = app.vars.js_dir + '/templates/' +
name.replaceAll('.', '/') + '.html';
name = 'template__'+name.replaceAll('.', '-');
if (window.__cache_templates[name] !== undefined)
return cback(window.__cache_templates[name]);
http.get(file, {}, function(html) {
html = html.trim();
window.__cache_templates[name] = html;
return cback(html);
});
}
function scriptPageHandler(modname, cfg) {
cfg['callback'] = function(args) {
app.script(modname, function(ok) {

View File