aboutsummaryrefslogtreecommitdiffstats
path: root/web/js
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2018-05-31 10:18:35 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2018-05-31 12:23:35 +0100
commit89b38145e0783cd9fb4c020b6c174bc4521ac3b8 (patch)
tree36fd4051a94a93f13059b1bf1875570dbd983df9 /web/js
parent557d1137f10f481a8fe8c723532b410096c6d965 (diff)
Improve handling of loading spinner display.
Going back to /around from /report/new can trigger loadend (and the spinner hiding function) twice (if the strategy activation starts a read), with triggerRead aborting that read and triggering the event itself. This means the spinner is not displayed, as the count falls below 0. We could pin the count above 0, but instead let’s log each layer ID while ‘active’ and switch off when they’re all gone.
Diffstat (limited to 'web/js')
-rw-r--r--web/js/map-OpenLayers.js22
1 files changed, 17 insertions, 5 deletions
diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js
index a96e65953..2e62336ed 100644
--- a/web/js/map-OpenLayers.js
+++ b/web/js/map-OpenLayers.js
@@ -1,3 +1,15 @@
+if (!Object.keys) {
+ Object.keys = function(obj) {
+ var result = [];
+ for (var prop in obj) {
+ if (Object.prototype.hasOwnProperty.call(obj, prop)) {
+ result.push(prop);
+ }
+ }
+ return result;
+ };
+}
+
var fixmystreet = fixmystreet || {};
fixmystreet.utils = fixmystreet.utils || {};
@@ -247,18 +259,18 @@ $.extend(fixmystreet.utils, {
* the spinner in the DOM.
*/
loading_spinner: {
- count: 0,
+ count: {},
show: function() {
- fixmystreet.maps.loading_spinner.count++;
- if (fixmystreet.maps.loading_spinner.count > 0) {
+ fixmystreet.maps.loading_spinner.count[this.id] = 1;
+ if (Object.keys(fixmystreet.maps.loading_spinner.count).length) {
// Show the loading indicator over the map
$('#loading-indicator').removeClass('hidden');
$('#loading-indicator').attr('aria-hidden', false);
}
},
hide: function() {
- fixmystreet.maps.loading_spinner.count--;
- if (fixmystreet.maps.loading_spinner.count <= 0) {
+ delete fixmystreet.maps.loading_spinner.count[this.id];
+ if (!Object.keys(fixmystreet.maps.loading_spinner.count).length) {
// Remove loading indicator
$('#loading-indicator').addClass('hidden');
$('#loading-indicator').attr('aria-hidden', true);