From 0eddaed6a14bb65c32591c6996b4d74da578d5a1 Mon Sep 17 00:00:00 2001 From: Niko Date: Sat, 12 Feb 2022 00:59:37 +0100 Subject: [PATCH] Added "template" function for /app to async load of templates (html) --- web/src/app/js/app.js | 15 +++++++++++++++ web/src/app/js/templates/.gitkeep | 0 2 files changed, 15 insertions(+) create mode 100644 web/src/app/js/templates/.gitkeep diff --git a/web/src/app/js/app.js b/web/src/app/js/app.js index 122da9d..cf05740 100644 --- a/web/src/app/js/app.js +++ b/web/src/app/js/app.js @@ -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) { diff --git a/web/src/app/js/templates/.gitkeep b/web/src/app/js/templates/.gitkeep new file mode 100644 index 0000000..e69de29