From c8e62e3610ef4cc8fdf3b27200f8c405aaae13e4 Mon Sep 17 00:00:00 2001 From: Tobias Johansson Date: Tue, 23 Oct 2018 13:57:02 +0200 Subject: [PATCH] Loading bar: Introduced two event listeners on window 'pillar:workStart' and 'pillar:workStop' that (de)activates the loading bar. Reason: * To decouple code * Have the loading bar active until whole page stopped working * Have local loading info Usage: $.('.myClass') .on('pillar:workStart', function(){ ... do stuff locally while loading ... }) .on('pillar:workStop', function(){ ... stop do stuff locally while loading ... }) $.('.myClass .mySubClass').trigger('pillar:workStart') ... do stuff ... $.('.myClass .mySubClass').trigger('pillar:workStop') --- src/scripts/tutti/0_navbar.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/scripts/tutti/0_navbar.js b/src/scripts/tutti/0_navbar.js index f32dea06..a80484f3 100644 --- a/src/scripts/tutti/0_navbar.js +++ b/src/scripts/tutti/0_navbar.js @@ -104,13 +104,31 @@ function statusBarSet(classes, html, icon_name, time){ * loading an asset or performing actions. */ function loadingBarShow(){ + /* NEVER call this directly! Trigger pillar:workStart event instead */ $('.loading-bar').addClass('active'); } function loadingBarHide(){ + /* NEVER call this directly! Trigger pillar:workStop event instead */ $('.loading-bar').removeClass('active'); } +(function loadingbar () { + var busyCounter = 0; + + $(window) + .on('pillar:workStart', function(e) { + busyCounter += 1; + loadingBarShow(); + }) + .on('pillar:workStop', function() { + busyCounter -= 1; + if(busyCounter === 0) { + loadingBarHide(); + } + }) +})(); + $(document).ready(function() {