Skip to content

Commit 0de9a18

Browse files
committed
Progressbar: Rename indeterminate class, return default value to 0, use NaN for the indeterminate value, replace animated gif and DRY code by moving much of it to _refreshValue
1 parent a6a1c43 commit 0de9a18

File tree

4 files changed

+16
-19
lines changed

4 files changed

+16
-19
lines changed

themes/base/images/pbar-ani.gif

7.78 KB
Loading
Binary file not shown.

themes/base/jquery.ui.progressbar.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
*/
1111
.ui-progressbar { height:2em; text-align: left; overflow: hidden; }
1212
.ui-progressbar .ui-progressbar-value { margin: -1px; height:100%; }
13-
.ui-progressbar .ui-progressbar-animated { background: url("images/ui-bg_animated_progress_50x50.gif"); }
13+
.ui-progressbar .ui-progressbar-indeterminate { background: url("images/pbar-ani.gif"); }

ui/jquery.ui.progressbar.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,25 @@
1717
$.widget( "ui.progressbar", {
1818
version: "@VERSION",
1919
options: {
20-
value: false,
20+
value: 0,
2121
max: 100
2222
},
2323

2424
min: 0,
2525

2626
_create: function() {
27+
var val = this._value();
2728
this.element
2829
.addClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" )
2930
.attr({
3031
role: "progressbar",
3132
"aria-valuemin": this.min,
32-
"aria-valuemax": this.options.max,
33-
"aria-valuenow": this._value()
33+
"aria-valuemax": this.options.max
3434
});
3535

3636
this.valueDiv = $( "<div class='ui-progressbar-value ui-widget-header ui-corner-left'></div>" )
3737
.appendTo( this.element );
3838

39-
if ( this.options.value !== false ) {
40-
this.oldValue = this._value();
41-
} else {
42-
this.oldValue = false;
43-
this.valueDiv.addClass( "ui-progressbar-animated" );
44-
}
4539
this._refreshValue();
4640
},
4741

@@ -68,11 +62,7 @@ $.widget( "ui.progressbar", {
6862
_setOption: function( key, value ) {
6963
if ( key === "value" ) {
7064
this.options.value = value;
71-
if ( value !== false ) {
72-
this.valueDiv.removeClass( "ui-progressbar-animated" );
73-
} else {
74-
this.valueDiv.addClass( "ui-progressbar-animated" );
75-
}
65+
7666
this._refreshValue();
7767
if ( this._value() === this.options.max ) {
7868
this._trigger( "complete" );
@@ -88,29 +78,36 @@ $.widget( "ui.progressbar", {
8878
if ( typeof val !== "number" && val !== false ) {
8979
val = 0;
9080
} else if( val === false ) {
91-
val = 100;
81+
val = NaN;
9282
}
9383
return Math.min( this.options.max, Math.max( this.min, val ) );
9484
},
9585

9686
_percentage: function() {
97-
return 100 * this._value() / this.options.max;
87+
var val = this._value();
88+
return isNaN( val ) ? 100 : 100 * val / this.options.max;
9889
},
9990

10091
_refreshValue: function() {
10192
var value = this.value(),
10293
percentage = this._percentage();
10394

95+
this.valueDiv.toggleClass( "ui-progressbar-indeterminate", isNaN( value ) );
96+
10497
if ( this.oldValue !== value ) {
10598
this.oldValue = value;
10699
this._trigger( "change" );
107100
}
108101

109102
this.valueDiv
110-
.toggle( value > this.min )
103+
.toggle( isNaN( value ) || value > this.min )
111104
.toggleClass( "ui-corner-right", value === this.options.max )
112105
.width( percentage.toFixed(0) + "%" );
113-
this.element.attr( "aria-valuenow", value );
106+
if ( isNaN( value ) ) {
107+
this.element.removeAttr( "aria-valuenow" );
108+
} else {
109+
this.element.attr( "aria-valuenow", value );
110+
}
114111
}
115112
});
116113

0 commit comments

Comments
 (0)