From 0b2a3c99ce5bb7fbd49af064d20174851c77b85a 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/tagged_assets.js | 6 ++++-- src/templates/projects/view.pug | 18 ++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/scripts/tagged_assets.js b/src/scripts/tagged_assets.js index 1c95fec..e06d80d 100644 --- a/src/scripts/tagged_assets.js +++ b/src/scripts/tagged_assets.js @@ -25,7 +25,7 @@ if (!node.picture) { warnNoPicture(); } else { - loadingBarShow(); + $(window).trigger('pillar:workStart'); // TODO: show 'loading' thingy $.get('/api/files/' + node.picture) @@ -34,7 +34,6 @@ console.log(msg); }) .done(function(resp) { - loadingBarHide(); // Render the picture if it has the proper size. var show_variation = null; @@ -57,6 +56,9 @@ .attr('width', variation.width) .attr('height', variation.height); thumbnail_container.append(img); + }) + .always(function(){ + $(window).trigger('pillar:workStop'); }); } diff --git a/src/templates/projects/view.pug b/src/templates/projects/view.pug index 551c1f7..b3cb826 100644 --- a/src/templates/projects/view.pug +++ b/src/templates/projects/view.pug @@ -378,32 +378,34 @@ script. function loadNodeContent(url, nodeId) { - loadingBarShow(); + var $projectContext = $('#project_context') + $projectContext.trigger('pillar:workStart') $.get(url, function(dataHtml) { // Update the DOM injecting the generate HTML into the page - $('#project_context').html(dataHtml); + $projectContext.html(dataHtml); }) .done(function(){ updateUi(nodeId, 'view'); }) .fail(function(dataResponse) { - $('#project_context').html($('