Skip to content

Commit d9d077f

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 d9d077f

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

static/loading-bar.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,41 @@
11
function LoadingBar(color, parent) {
2-
this.meter = $('<span>', {style: 'transition: width 1s ease; width:0%;'});
2+
this.meter = $('<span>', {style: 'transition: width 0.5s ease; width:0%;'});
33
this.elem = $('<div>', {style: 'display:none', class: 'meter animate ' + color}).append(
44
this.meter.append($('<span>'))
55
);
6+
this.progress = 5;
67

78
parent = parent || $('body');
89
parent.prepend(this.elem);
910

1011
return this;
1112
}
1213

13-
LoadingBar.prototype.start = function(percentage) {
14-
percentage = percentage || 0;
15-
this.meter.css('width', percentage + '%');
14+
LoadingBar.prototype.start = function(progress) {
15+
if(progress) {
16+
this.progress = progress;
17+
}
18+
console.log('start', this.progress);
19+
this.meter.css('width', this.progress + '%');
1620
this.elem.show();
1721
};
1822

1923
LoadingBar.prototype.end = function() {
20-
this.elem.hide();
24+
console.log('end', this.progress);
25+
this.update(100);
26+
this.progress = 0;
2127
};
2228

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

2741
module.exports = LoadingBar;

0 commit comments

Comments
 (0)