123456789101112131415161718192021222324252627282930313233343536373839404142 |
- const EVENT_TEMPLATES_LOADED = "templates:loaded";
- const templateNames = [
- "class",
- "home",
- "species"
- ];
- const partialNames = [
- "nav"
- ];
- const loadCount = templateNames.length + partialNames.length;
- var templates = {};
- var contentElement = document.getElementById("content");
- var ready = false;
- function checkLoad(target) {
- if (Object.keys(templates).length === loadCount) {
- ready = true;
- target.dispatchEvent(new Event(EVENT_TEMPLATES_LOADED));
- }
- }
- templateNames.forEach(function (name) {
- const path = "templates/" + name + ".hbs";
- $.get(path, function (data) {
- templates[name] = Handlebars.compile(data);
- checkLoad(contentElement);
- }, "html");
- });
- partialNames.forEach(function (name) {
- const path = "templates/" + name + ".hbs";
- $.get(path, function (data) {
- templates[name] = Handlebars.compile(data);
- Handlebars.registerPartial(name, templates[name]);
- checkLoad(contentElement);
- }, "html");
- });
|