From 0f9bcfeee6b47e6206b062d2affd0862209820f3 Mon Sep 17 00:00:00 2001 From: Jacek Kowalski <Jacek@jacekk.info> Date: Tue, 13 Dec 2016 22:49:26 +0000 Subject: [PATCH] Use navbar for loading indication --- index.js | 25 +++++++++++++++++++++++-- 1 files changed, 23 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index f6c900c..af4dacb 100644 --- a/index.js +++ b/index.js @@ -30,6 +30,8 @@ var alert_text = document.getElementById('alert-text'); var alert_close = document.getElementById('alert-close'); +var nav = document.getElementsByTagName('nav')[0]; + var parseStatusBoarding = '>>>'; function parseStatus(status) { switch(status.status) { @@ -101,7 +103,6 @@ } function fail(message, more) { - if(refresh_timer) clearInterval(refresh_timer); if(times_timer) clearTimeout(times_timer); setText(alert_text, message); @@ -124,6 +125,18 @@ } } +function fail_hide() { + alert.style.display = 'none'; +} + +function loading_start() { + nav.className += ' loading'; +} + +function loading_end() { + nav.className = nav.className.replace(' loading', ''); +} + function loadTimes(stopId = null, clearRoute = false) { if(!stopId) stopId = stop_id; if(!stopId) return; @@ -133,6 +146,7 @@ refresh_button.removeAttribute('disabled'); + loading_start(); times_xhr = $.get( ttss_base + '/passageInfo/stopPassages/stop' + '?stop=' + encodeURIComponent(stopId) @@ -232,9 +246,10 @@ } startTimer(new Date()); + fail_hide(); times_timer = setTimeout(function(){ loadTimes(); }, ttss_refresh); - }).fail(fail_ajax); + }).fail(fail_ajax).always(loading_end); } function declinate(num, singular, plural) { @@ -314,6 +329,7 @@ e.preventDefault(); if(!stop_name_autocomplete.value) return; stop_id = stop_name_autocomplete.value; + window.location.hash = '#!' + stop_id; loadTimes(stop_id, true); }); @@ -324,6 +340,11 @@ alert_close.addEventListener('click', function(e) { alert.style.display = 'none'; }); + + if(window.location.hash.match(/^#![0-9]+$/)) { + stop_id = parseInt(window.location.hash.slice(2)); + loadTimes(stop_id); + } } init(); -- Gitblit v1.9.1