From 750bcebbd4d8710c6960bd204042d90b2f7f0fc1 Mon Sep 17 00:00:00 2001 From: Thierry Carrez Date: Thu, 21 Dec 2017 14:51:33 +0100 Subject: [PATCH] Select current day tab by default On the room tables, preselect the tabs corresponding to the current day, rather than always Monday. If the day doesn't exist, find the first available day tab and select those. Change-Id: I3c0bc58f35cd39a8c5291d1d6da4547283479e2d --- html/ptg.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/html/ptg.js b/html/ptg.js index f2d3259..0612dc6 100644 --- a/html/ptg.js +++ b/html/ptg.js @@ -18,9 +18,22 @@ Handlebars.registerHelper('hashtag', function(options) { return new Handlebars.SafeString(sentence); }); +// What is the day today ? +var now = new Date(); +var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']; +var day = days[ now.getDay() ]; + $.getJSON("ptg.json", function(json) { - console.log(json); document.getElementById("PTGsessions").innerHTML = template(json); - $('#stMonday').tab('show'); - $('#atMonday').tab('show'); + // if the current day doesn't exist, default to first existing one + if ($('#st'+day).length == 0) { + for (var i = 0; i < days.length; i++) { + if ($('#st'+days[i]).length) { + day = days[i]; + break; + } + } + } + $('#st'+day).tab('show'); + $('#at'+day).tab('show'); });