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 5347e026b7a..78598898bf0 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.toFixed(0) ); + return this; + }, + _setOption: function( key, value ) { if ( key === "value" ) { this.options.value = value; @@ -78,14 +88,27 @@ $.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 + ' (' + percentage.toFixed(0) + '%)' + } + this.valueDiv .toggleClass( "ui-corner-right", value === this.max ) - .width( value + "%" ); + .width( percentage.toFixed(0) + "%" ) + .html( display ); this.element.attr( "aria-valuenow", value ); } });