From f88c60ae1500d4003db9bfe815eee6dcc914bcd6 Mon Sep 17 00:00:00 2001 From: rolux Date: Sat, 14 Apr 2012 13:49:22 +0200 Subject: [PATCH] fix bugs in progress bar --- source/Ox.UI/js/Bar/Ox.Progressbar.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/source/Ox.UI/js/Bar/Ox.Progressbar.js b/source/Ox.UI/js/Bar/Ox.Progressbar.js index 5d43a9cb..742e7dfb 100644 --- a/source/Ox.UI/js/Bar/Ox.Progressbar.js +++ b/source/Ox.UI/js/Bar/Ox.Progressbar.js @@ -8,7 +8,7 @@ Ox.Progressbar Progress Bar options Options object cancelled If true, progress bar is cancelled paused If true, progress bar is paused - progress Progress, float between 0 and 1 + progress Progress, float between 0 and 1, or -1 for indeterminate showCancelButton If true, show cancel button showPauseButton If true, show pause button showPercent 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; - self.options.progress = 0; + 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');