Skip to content

Commit

Permalink
Fix bug preventing loading indicator from showing
Browse files Browse the repository at this point in the history
Since we have a CSS animation on the width of the bar, and on a fast network the progress event usaully only fires once (at 100%), hiding the loading indicator eminently after calling `.end()` would not allow the animation to complete before the bar hidden.

This PR adds a timer to wait for the CSS animation before hiding the bar.
  • Loading branch information
imaustink committed Sep 1, 2017
1 parent 96aa55d commit ab8284c
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions static/loading-bar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function LoadingBar(color, parent) {
this.meter = $('<span>', {style: 'transition: width 1s ease; width:0%;'});
this.meter = $('<span>', {style: 'transition: width 0.5s ease; width:0%;'});
this.elem = $('<div>', {style: 'display:none', class: 'meter animate ' + color}).append(
this.meter.append($('<span>'))
);
Expand All @@ -10,18 +10,32 @@ function LoadingBar(color, parent) {
return this;
}

LoadingBar.prototype.start = function(percentage) {
percentage = percentage || 0;
this.meter.css('width', percentage + '%');
LoadingBar.prototype.start = function(progress) {
progress = progress || 5;
this.clearTimer();
this.meter.css('width', progress + '%');
this.elem.show();
};

LoadingBar.prototype.end = function() {
this.elem.hide();
this.update(100);
};

LoadingBar.prototype.update = function(percentage) {
this.meter.css('width', percentage + '%');
LoadingBar.prototype.update = function(progress) {
this.clearTimer();
this.meter.css('width', progress + '%');
if(progress === 100){
this.timer = setTimeout(function(){
this.elem.hide();
}.bind(this), 500);
}
};

LoadingBar.prototype.clearTimer = function(){
if(this.timer){
clearTimeout(this.timer);
this.timer = null;
}
};

module.exports = LoadingBar;

0 comments on commit ab8284c

Please sign in to comment.