diff options
author | Humberto Alfonso Díaz <humberto.alfonso@asvito.es> | 2019-12-09 11:43:22 +0100 |
---|---|---|
committer | Lorenzo Tilve <ltilve@igalia.com> | 2020-02-04 19:03:18 +0100 |
commit | aa8165f9173cf95c18deaaf0ce4e685d2cce3775 (patch) | |
tree | 2cb15dd8be01b9c8b18c7f69d39f2a82de1b6ee0 /src/js | |
parent | 12caee8305924b9dcaf23dc71f36129d3993c5ca (diff) |
STRUCT First structure for the repo
Diffstat (limited to 'src/js')
-rw-r--r-- | src/js/app.js | 21 | ||||
-rw-r--r-- | src/js/templates.js | 19 |
2 files changed, 40 insertions, 0 deletions
diff --git a/src/js/app.js b/src/js/app.js new file mode 100644 index 0000000..9269de5 --- /dev/null +++ b/src/js/app.js @@ -0,0 +1,21 @@ +import { load as load_template } from './templates'; +import Mustache from 'mustache'; + +var template; +var page = { + +}; + +export function show() { + document.body.innerHTML = Mustache.render(template, page); +} + +export function init() { + load_template('main.template.html').then(function(result) { + template = result; + Mustache.parse(template); + show(); + }, function(error) { + console.error('ERRROR loading main template', error); + }); +}
\ No newline at end of file diff --git a/src/js/templates.js b/src/js/templates.js new file mode 100644 index 0000000..2513722 --- /dev/null +++ b/src/js/templates.js @@ -0,0 +1,19 @@ +export function load(template) { + return new Promise(function(resolve, reject){ + var xhr = new XMLHttpRequest(); + + xhr.open('GET', '/templates/'+template); + + xhr.send(); + + xhr.onload = function() { + if (xhr.status != 200) { + console.error('Error loading template', xhr.status, xhr.statusText); + reject(xhr.status); + } else { + console.log(xhr.responseType); + resolve(xhr.responseText); + } + }; + }); +}
\ No newline at end of file |