12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- const EVENT_TEMPLATES_LOADED = "templates:loaded";
- const templateNames = [
- "class",
- "home",
- "species"
- ];
- const partialNames = [
- "nav"
- ];
- var templates = {};
- var $content = null;
- function checkLoad($target) {
- if (Object.keys(templates).length === templateNames.length + partialNames.length) {
- $target.trigger(EVENT_TEMPLATES_LOADED);
- }
- }
- $(document).ready(function () {
- $content = $("#content");
- templateNames.forEach(function (name) {
- const path = "templates/" + name + ".hbs";
- $.get(path, function (data) {
- templates[name] = Handlebars.compile(data);
- checkLoad($content);
- }, "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($content);
- }, "html");
- });
- $content.on(EVENT_TEMPLATES_LOADED, {}, function () {
- $(this).html(templates.home());
- });
- });
|