From 6d8916c58d823b13b89477f59bf05373e87f3a98 Mon Sep 17 00:00:00 2001 From: Humberto Alfonso Díaz Date: Wed, 11 Dec 2019 08:39:27 +0100 Subject: RESTRUCT Upadate homescreen layout --- src/js/time.js | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'src/js/time.js') diff --git a/src/js/time.js b/src/js/time.js index 55165c7..1757257 100644 --- a/src/js/time.js +++ b/src/js/time.js @@ -1,9 +1,25 @@ +import { load as load_template } from './templates'; import Mustache from 'mustache'; var template; +var root; +var page = { + date: { + day: '', + hour: '' + }, + weather: { + icon: 'fas fa-cloud-sun-rain', + temperature: '20ºC' + } +} var days = ['SUNDAY', 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY']; +function show() { + root.innerHTML = Mustache.render(template, page); +} + function formatAMPM(date) { var hours = date.getHours(); var minutes = date.getMinutes(); @@ -18,16 +34,19 @@ function formatAMPM(date) { function initInterval() { setInterval(function() { var date = new Date(); - document.getElementById('timeContainer').innerHTML = Mustache.render(template, { - day: days[date.getDay()], - hour: formatAMPM(date) - }); + page.date.day = days[date.getDay()], + page.date.hour = formatAMPM(date); + show(); }, 1000); } -export function init() { - template = document.getElementById('time-template').innerHTML; - Mustache.parse(template); - - initInterval(); +export function init(node) { + load_template('time.template.html').then(function(result) { + template = result; + root = node; + Mustache.parse(template); + initInterval(); + }, function(error) { + console.error('ERRROR loading main template', error); + }); } \ No newline at end of file -- cgit 1.2.3-korg