aboutsummaryrefslogtreecommitdiffstats
path: root/ui/jquery.ui.progressbar.js
diff options
context:
space:
mode:
authorMarian Rudzynski <mr@impaled.org>2010-11-22 08:49:47 -0500
committerScott González <scott.gonzalez@gmail.com>2010-11-22 08:49:47 -0500
commitd23fe49ae814f677fedd55cddd97768bddeffa12 (patch)
treebab611d61d01e2e177ec6b47c3358fe835807517 /ui/jquery.ui.progressbar.js
parentd69f2ecb1273f382d83b13c349a8c76b17bee2a6 (diff)
downloadjquery-ui-d23fe49ae814f677fedd55cddd97768bddeffa12.tar.gz
jquery-ui-d23fe49ae814f677fedd55cddd97768bddeffa12.zip
Progressbar: Added max option. Fixes #6681 - Progressbar: add max option.
Diffstat (limited to 'ui/jquery.ui.progressbar.js')
-rw-r--r--ui/jquery.ui.progressbar.js27
1 files changed, 19 insertions, 8 deletions
diff --git a/ui/jquery.ui.progressbar.js b/ui/jquery.ui.progressbar.js
index 5347e026b..009049d27 100644
--- a/ui/jquery.ui.progressbar.js
+++ b/ui/jquery.ui.progressbar.js
@@ -15,11 +15,11 @@
$.widget( "ui.progressbar", {
options: {
- value: 0
+ value: 0,
+ max: 100
},
min: 0,
- max: 100,
_create: function() {
this.element
@@ -27,13 +27,14 @@ $.widget( "ui.progressbar", {
.attr({
role: "progressbar",
"aria-valuemin": this.min,
- "aria-valuemax": this.max,
+ "aria-valuemax": this.options.max,
"aria-valuenow": this._value()
});
this.valueDiv = $( "<div class='ui-progressbar-value ui-widget-header ui-corner-left'></div>" )
.appendTo( this.element );
+ this.oldValue = this._value();
this._refreshValue();
},
@@ -63,8 +64,7 @@ $.widget( "ui.progressbar", {
if ( key === "value" ) {
this.options.value = value;
this._refreshValue();
- this._trigger( "change" );
- if ( this._value() === this.max ) {
+ if ( this._value() === this.options.max ) {
this._trigger( "complete" );
}
}
@@ -78,14 +78,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.min, val ) );
+ },
+
+ _percentage: function() {
+ return 100 * this._value() / this.options.max;
},
_refreshValue: function() {
var value = this.value();
+ var percentage = this._percentage();
+
+ if ( this.oldValue !== value ) {
+ this.oldValue = value;
+ this._trigger( "change" );
+ }
+
this.valueDiv
- .toggleClass( "ui-corner-right", value === this.max )
- .width( value + "%" );
+ .toggleClass( "ui-corner-right", value === this.options.max )
+ .width( percentage.toFixed(0) + "%" );
this.element.attr( "aria-valuenow", value );
}
});