Skip to content

Commit b733daf

Browse files
authored
Merge pull request #393 from canjs/391-fix-loading-indicator
Fix bug preventing loading indicator from showing
2 parents 96aa55d + 2e51408 commit b733daf

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,5 +1,5 @@
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
);
@@ -10,18 +10,32 @@ function LoadingBar(color, parent) {
1010
return this;
1111
}
1212

13-
LoadingBar.prototype.start = function(percentage) {
14-
percentage = percentage || 0;
15-
this.meter.css('width', percentage + '%');
13+
LoadingBar.prototype.start = function(progress) {
14+
progress = progress || 5;
15+
this.clearTimer();
16+
this.meter.css('width', progress + '%');
1617
this.elem.show();
1718
};
1819

1920
LoadingBar.prototype.end = function() {
20-
this.elem.hide();
21+
this.update(100);
2122
};
2223

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

2741
module.exports = LoadingBar;

0 commit comments

Comments
 (0)