Skip to content

Commit f00c031

Browse files
committed
Progressbar: cleanup.
1 parent ee1f5b5 commit f00c031

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

tests/unit/progressbar/progressbar_options.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,18 @@ test("{ value : 5 }", function() {
1717
same( 5, $("#progressbar").progressbar("value") );
1818
});
1919

20+
test("{ value : -5 }", function() {
21+
$("#progressbar").progressbar({
22+
value: -5
23+
});
24+
same( 0, $("#progressbar").progressbar("value") );
25+
});
26+
27+
test("{ value : 105 }", function() {
28+
$("#progressbar").progressbar({
29+
value: 105
30+
});
31+
same( 100, $("#progressbar").progressbar("value") );
32+
});
33+
2034
})(jQuery);

ui/jquery.ui.progressbar.js

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@ $.widget( "ui.progressbar", {
1717
options: {
1818
value: 0
1919
},
20+
21+
min: 0,
22+
max: 100,
23+
2024
_create: function() {
2125
this.element
2226
.addClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" )
2327
.attr({
2428
role: "progressbar",
25-
"aria-valuemin": this._valueMin(),
26-
"aria-valuemax": this._valueMax(),
29+
"aria-valuemin": this.min,
30+
"aria-valuemax": this.max,
2731
"aria-valuenow": this._value()
2832
});
2933

@@ -56,12 +60,10 @@ $.widget( "ui.progressbar", {
5660
},
5761

5862
_setOption: function( key, value ) {
59-
switch ( key ) {
60-
case "value":
61-
this.options.value = value;
62-
this._refreshValue();
63-
this._trigger( "change" );
64-
break;
63+
if ( key === "value" ) {
64+
this.options.value = value;
65+
this._refreshValue();
66+
this._trigger( "change" );
6567
}
6668

6769
$.Widget.prototype._setOption.apply( this, arguments );
@@ -73,28 +75,13 @@ $.widget( "ui.progressbar", {
7375
if ( typeof val !== "number" ) {
7476
val = 0;
7577
}
76-
if ( val < this._valueMin() ) {
77-
val = this._valueMin();
78-
}
79-
if ( val > this._valueMax() ) {
80-
val = this._valueMax();
81-
}
82-
83-
return val;
84-
},
85-
86-
_valueMin: function() {
87-
return 0;
88-
},
89-
90-
_valueMax: function() {
91-
return 100;
78+
return Math.min( this.max, Math.max( this.min, val ) );
9279
},
9380

9481
_refreshValue: function() {
9582
var value = this.value();
9683
this.valueDiv
97-
[ value === this._valueMax() ? "addClass" : "removeClass"]( "ui-corner-right" )
84+
.toggleClass( "ui-corner-right", value === this.max )
9885
.width( value + "%" );
9986
this.element.attr( "aria-valuenow", value );
10087
}

0 commit comments

Comments
 (0)