Skip to content

Commit cbe189c

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 cbe189c

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

static/loading-bar.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,43 @@
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
);
8+
this.progress = starting;
69

710
parent = parent || $('body');
811
parent.prepend(this.elem);
912

1013
return this;
1114
}
1215

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

1925
LoadingBar.prototype.end = function() {
20-
this.elem.hide();
26+
console.log('end', this.progress);
27+
this.update(100);
28+
this.progress = starting;
2129
};
2230

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

2743
module.exports = LoadingBar;

0 commit comments

Comments
 (0)