Skip to content

Commit

Permalink
Progressbar: cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
scottgonzalez committed Jul 29, 2010
1 parent ee1f5b5 commit f00c031
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
14 changes: 14 additions & 0 deletions tests/unit/progressbar/progressbar_options.js
Expand Up @@ -17,4 +17,18 @@ test("{ value : 5 }", function() {
same( 5, $("#progressbar").progressbar("value") );
});

test("{ value : -5 }", function() {
$("#progressbar").progressbar({
value: -5
});
same( 0, $("#progressbar").progressbar("value") );
});

test("{ value : 105 }", function() {
$("#progressbar").progressbar({
value: 105
});
same( 100, $("#progressbar").progressbar("value") );
});

})(jQuery);
37 changes: 12 additions & 25 deletions ui/jquery.ui.progressbar.js
Expand Up @@ -17,13 +17,17 @@ $.widget( "ui.progressbar", {
options: {
value: 0
},

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._valueMin(),
"aria-valuemax": this._valueMax(),
"aria-valuemin": this.min,
"aria-valuemax": this.max,
"aria-valuenow": this._value()
});

Expand Down Expand Up @@ -56,12 +60,10 @@ $.widget( "ui.progressbar", {
},

_setOption: function( key, value ) {
switch ( key ) {
case "value":
this.options.value = value;
this._refreshValue();
this._trigger( "change" );
break;
if ( key === "value" ) {
this.options.value = value;
this._refreshValue();
this._trigger( "change" );
}

$.Widget.prototype._setOption.apply( this, arguments );
Expand All @@ -73,28 +75,13 @@ $.widget( "ui.progressbar", {
if ( typeof val !== "number" ) {
val = 0;
}
if ( val < this._valueMin() ) {
val = this._valueMin();
}
if ( val > this._valueMax() ) {
val = this._valueMax();
}

return val;
},

_valueMin: function() {
return 0;
},

_valueMax: function() {
return 100;
return Math.min( this.max, Math.max( this.min, val ) );
},

_refreshValue: function() {
var value = this.value();
this.valueDiv
[ value === this._valueMax() ? "addClass" : "removeClass"]( "ui-corner-right" )
.toggleClass( "ui-corner-right", value === this.max )
.width( value + "%" );
this.element.attr( "aria-valuenow", value );
}
Expand Down

0 comments on commit f00c031

Please sign in to comment.