From 7e1b6b46c82519a186850d2b3ef8b7022486d848 Mon Sep 17 00:00:00 2001 From: Marian Rudzynski Date: Fri, 15 Oct 2010 15:38:44 +0200 Subject: [PATCH 1/2] moved min/max to options and allowed for dynamic values and displaying the value within the progressbar --- ui/jquery.ui.progressbar.js | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/ui/jquery.ui.progressbar.js b/ui/jquery.ui.progressbar.js index 5347e026b7a..49ea8a0ab2e 100644 --- a/ui/jquery.ui.progressbar.js +++ b/ui/jquery.ui.progressbar.js @@ -15,19 +15,19 @@ $.widget( "ui.progressbar", { options: { - value: 0 + value: 0, + min: 0, + max: 100, + display: 'all' // value, values, percentage, all }, - min: 0, - max: 100, - _create: function() { this.element .addClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" ) .attr({ role: "progressbar", - "aria-valuemin": this.min, - "aria-valuemax": this.max, + "aria-valuemin": this.options.min, + "aria-valuemax": this.options.max, "aria-valuenow": this._value() }); @@ -59,6 +59,16 @@ $.widget( "ui.progressbar", { return this; }, + percentage: function( newPercentage ) { + if ( newPercentage === undefined ) { + return this._percentage(); + } + + newValue = ((this.options.max/100)*newPercentage); + this._setOption( "value", newValue ); + return this; + }, + _setOption: function( key, value ) { if ( key === "value" ) { this.options.value = value; @@ -78,14 +88,25 @@ $.widget( "ui.progressbar", { if ( typeof val !== "number" ) { val = 0; } - return Math.min( this.max, Math.max( this.min, val ) ); + return Math.min( this.options.max, Math.max( this.options.min, val ) ); + }, + + _percentage: function() { + return ((this._value()/this.options.max)*100); }, _refreshValue: function() { var value = this.value(); + var percentage = this.percentage(); + var display = ''; + switch(this.options.display.toLowerCase()) { + case 'all': + display = value + '/' + this.options.max + ' (' + this.percentage() + '%)' + } this.valueDiv .toggleClass( "ui-corner-right", value === this.max ) - .width( value + "%" ); + .width( percentage + "%" ) + .html(display); this.element.attr( "aria-valuenow", value ); } }); From 5b95f179ecdc1d6a066f918da946e98f26989f3c Mon Sep 17 00:00:00 2001 From: Marian Rudzynski Date: Fri, 15 Oct 2010 16:00:03 +0200 Subject: [PATCH 2/2] zeroed float precision and moved display value to an own span inside the valueDiv that is absolutely positioned within --- themes/base/jquery.ui.progressbar.css | 3 ++- ui/jquery.ui.progressbar.js | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/themes/base/jquery.ui.progressbar.css b/themes/base/jquery.ui.progressbar.css index 50fe84a6f4a..f8cab5007a9 100644 --- a/themes/base/jquery.ui.progressbar.css +++ b/themes/base/jquery.ui.progressbar.css @@ -8,4 +8,5 @@ * http://docs.jquery.com/UI/Progressbar#theming */ .ui-progressbar { height:2em; text-align: left; } -.ui-progressbar .ui-progressbar-value {margin: -1px; height:100%; } \ No newline at end of file +.ui-progressbar .ui-progressbar-value { margin: -1px; height:100%; position: relative; } +.ui-progressbar .ui-progressbar-display { position: absolute; } \ No newline at end of file diff --git a/ui/jquery.ui.progressbar.js b/ui/jquery.ui.progressbar.js index 49ea8a0ab2e..78598898bf0 100644 --- a/ui/jquery.ui.progressbar.js +++ b/ui/jquery.ui.progressbar.js @@ -65,7 +65,7 @@ $.widget( "ui.progressbar", { } newValue = ((this.options.max/100)*newPercentage); - this._setOption( "value", newValue ); + this._setOption( "value", newValue.toFixed(0) ); return this; }, @@ -99,14 +99,16 @@ $.widget( "ui.progressbar", { var value = this.value(); var percentage = this.percentage(); var display = ''; + switch(this.options.display.toLowerCase()) { case 'all': - display = value + '/' + this.options.max + ' (' + this.percentage() + '%)' + display = "" + value + '/' + this.options.max + ' (' + percentage.toFixed(0) + '%)' } + this.valueDiv .toggleClass( "ui-corner-right", value === this.max ) - .width( percentage + "%" ) - .html(display); + .width( percentage.toFixed(0) + "%" ) + .html( display ); this.element.attr( "aria-valuenow", value ); } });