-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
1 changed file
with
23 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,43 @@ | ||
var starting = 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>')) | ||
); | ||
this.progress = starting; | ||
|
||
parent = parent || $('body'); | ||
parent.prepend(this.elem); | ||
|
||
return this; | ||
} | ||
|
||
LoadingBar.prototype.start = function(percentage) { | ||
percentage = percentage || 0; | ||
this.meter.css('width', percentage + '%'); | ||
LoadingBar.prototype.start = function(progress) { | ||
if(progress) { | ||
this.progress = progress; | ||
} | ||
console.log('start', this.progress); | ||
this.meter.css('width', this.progress + '%'); | ||
this.elem.show(); | ||
}; | ||
|
||
LoadingBar.prototype.end = function() { | ||
this.elem.hide(); | ||
console.log('end', this.progress); | ||
this.update(100); | ||
this.progress = starting; | ||
}; | ||
|
||
LoadingBar.prototype.update = function(percentage) { | ||
this.meter.css('width', percentage + '%'); | ||
LoadingBar.prototype.update = function(progress) { | ||
this.progress = progress; | ||
console.log('update', this.progress); | ||
this.meter.css('width', this.progress + '%'); | ||
if(this.progress === 100){ | ||
setTimeout(function(){ | ||
console.log('hide'); | ||
this.elem.hide(); | ||
}.bind(this), 500); | ||
} | ||
}; | ||
|
||
module.exports = LoadingBar; |