fix bugs in progress bar
This commit is contained in:
parent
e790571f2c
commit
f88c60ae15
1 changed files with 13 additions and 4 deletions
|
@ -8,7 +8,7 @@ Ox.Progressbar <f> Progress Bar
|
|||
options <o|{}> Options object
|
||||
cancelled <b|false> If true, progress bar is cancelled
|
||||
paused <b|false> If true, progress bar is paused
|
||||
progress <n|0> Progress, float between 0 and 1
|
||||
progress <n|0> Progress, float between 0 and 1, or -1 for indeterminate
|
||||
showCancelButton <b|false> If true, show cancel button
|
||||
showPauseButton <b|false> If true, show pause button
|
||||
showPercent <b|false> If true, show progress in percent
|
||||
|
@ -41,6 +41,8 @@ Ox.Progressbar = function(options, self) {
|
|||
.addClass('OxProgressbar')
|
||||
.css({width: self.options.width - 2 + 'px'});
|
||||
|
||||
self.indeterminate = self.options.progress == -1;
|
||||
|
||||
self.trackWidth = self.options.width
|
||||
- self.options.showPercent * 36
|
||||
- self.options.showTime * 60
|
||||
|
@ -86,7 +88,6 @@ Ox.Progressbar = function(options, self) {
|
|||
.appendTo(that);
|
||||
}
|
||||
|
||||
|
||||
if (self.options.showCancelButton) {
|
||||
self.$cancelButton = Ox.Button(Ox.extend({
|
||||
style: 'symbol',
|
||||
|
@ -105,6 +106,8 @@ Ox.Progressbar = function(options, self) {
|
|||
.appendTo(that);
|
||||
}
|
||||
|
||||
setProgress();
|
||||
|
||||
!self.options.paused && resume();
|
||||
|
||||
function cancel() {
|
||||
|
@ -135,7 +138,9 @@ Ox.Progressbar = function(options, self) {
|
|||
|
||||
function restart() {
|
||||
self.options.cancelled = false;
|
||||
if (!self.indeterminate) {
|
||||
self.options.progress = 0;
|
||||
}
|
||||
delete self.startTime;
|
||||
self.$pauseButton && self.$pauseButton.options({disabled: false});
|
||||
setProgress();
|
||||
|
@ -167,7 +172,7 @@ Ox.Progressbar = function(options, self) {
|
|||
self.options.progress ? Ox.formatDuration(that.status().remaining) : 'unknown'
|
||||
);
|
||||
self.$progress.stop().animate({
|
||||
width: Math.round(14 + self.options.progress * (self.trackWidth - 16)) + 'px'
|
||||
width: Math.round(14 + Math.abs(self.options.progress) * (self.trackWidth - 16)) + 'px'
|
||||
}, animate ? 250 : 0, function() {
|
||||
self.options.progress == 1 && complete();
|
||||
});
|
||||
|
@ -189,6 +194,8 @@ Ox.Progressbar = function(options, self) {
|
|||
function toggleCancelled(e) {
|
||||
if (e) {
|
||||
self.options.cancelled = !self.options.cancelled;
|
||||
} else if (self.$cancelButton) {
|
||||
self.$cancelButton.toggle();
|
||||
}
|
||||
self.options.cancelled ? cancel() : restart();
|
||||
that.triggerEvent(self.options.cancelled ? 'cancel' : 'restart');
|
||||
|
@ -197,6 +204,8 @@ Ox.Progressbar = function(options, self) {
|
|||
function togglePaused(e) {
|
||||
if (e) {
|
||||
self.options.paused = !self.options.paused;
|
||||
} else if (self.$pauseButton) {
|
||||
self.$pauseButton.toggle();
|
||||
}
|
||||
self.options.paused ? pause() : resume();
|
||||
that.triggerEvent(self.options.paused ? 'pause' : 'resume');
|
||||
|
|
Loading…
Reference in a new issue