From ac721dc18e5bf997afc016a486fa4788f094b148 Mon Sep 17 00:00:00 2001 From: Jacek Kowalski <Jacek@jacekk.info> Date: Thu, 08 Dec 2016 22:47:26 +0000 Subject: [PATCH] Add request in progress indicator --- index.js | 18 +++++++++++++++++- 1 files changed, 17 insertions(+), 1 deletions(-) diff --git a/index.js b/index.js index 9a1108b..e522ba4 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 progress = document.getElementById('progress'); + var parseStatusBoarding = '>>>'; function parseStatus(status) { switch(status.status) { @@ -123,6 +125,18 @@ } } +function fail_hide() { + alert.style.display = 'none'; +} + +function loading_start() { + progress.style.display = 'block'; +} + +function loading_end() { + progress.style.display = 'none'; +} + function loadTimes(stopId = null, clearRoute = false) { if(!stopId) stopId = stop_id; if(!stopId) return; @@ -132,6 +146,7 @@ refresh_button.removeAttribute('disabled'); + loading_start(); times_xhr = $.get( ttss_base + '/passageInfo/stopPassages/stop' + '?stop=' + encodeURIComponent(stopId) @@ -231,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) { -- Gitblit v1.9.1