Skip to content

Commit 37bf811

Browse files
committed
Fix bug preventing loading indicator from showing
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.
1 parent 96aa55d commit 37bf811

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

static/loading-bar.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
var starting = 5;
2+
13
function LoadingBar(color, parent) {
2-
this.meter = $('<span>', {style: 'transition: width 1s ease; width:0%;'});
4+
this.meter = $('<span>', {style: 'transition: width 0.5s ease; width:0%;'});
35
this.elem = $('<div>', {style: 'display:none', class: 'meter animate ' + color}).append(
46
this.meter.append($('<span>'))
57
);
@@ -10,18 +12,27 @@ function LoadingBar(color, parent) {
1012
return this;
1113
}
1214

13-
LoadingBar.prototype.start = function(percentage) {
14-
percentage = percentage || 0;
15-
this.meter.css('width', percentage + '%');
15+
LoadingBar.prototype.start = function(progress) {
16+
if(this.timer){
17+
clearTimeout(this.timer);
18+
this.timer = null;
19+
}
20+
this.meter.css('width', progress || starting + '%');
1621
this.elem.show();
1722
};
1823

1924
LoadingBar.prototype.end = function() {
20-
this.elem.hide();
25+
this.update(100);
2126
};
2227

23-
LoadingBar.prototype.update = function(percentage) {
24-
this.meter.css('width', percentage + '%');
28+
LoadingBar.prototype.update = function(progress) {
29+
this.meter.css('width', progress + '%');
30+
if(progress === 100){
31+
this.timer = setTimeout(function(){
32+
console.log('hide');
33+
this.elem.hide();
34+
}.bind(this), 500);
35+
}
2536
};
2637

2738
module.exports = LoadingBar;

0 commit comments

Comments
 (0)