Progressbar: Cleanup, byte shaving.

This commit is contained in:
Scott González 2012-12-06 10:10:07 -05:00
parent 9d0df53624
commit f7614706ab
2 changed files with 17 additions and 27 deletions

View File

@ -24,5 +24,5 @@ test( "accessibility", function() {
element.progressbar( "option", "value", false ); element.progressbar( "option", "value", false );
equal( element.attr( "aria-valuemin" ), 0, "aria-valuemin" ); equal( element.attr( "aria-valuemin" ), 0, "aria-valuemin" );
equal( element.attr( "aria-valuemax" ), 150, "aria-valuemax" ); equal( element.attr( "aria-valuemax" ), 150, "aria-valuemax" );
strictEqual( element.attr( "aria-valuenow" ), undefined, "aria-valuenow initially" ); strictEqual( element.attr( "aria-valuenow" ), undefined, "aria-valuenow" );
}); });

View File

@ -28,7 +28,7 @@ $.widget( "ui.progressbar", {
_create: function() { _create: function() {
// Constrain initial value // Constrain initial value
this.options.value = this._constrainedValue(); this.oldValue = this.options.value = this._constrainedValue();
this.element this.element
.addClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" ) .addClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" )
@ -42,7 +42,6 @@ $.widget( "ui.progressbar", {
this.valueDiv = $( "<div class='ui-progressbar-value ui-widget-header ui-corner-left'></div>" ) this.valueDiv = $( "<div class='ui-progressbar-value ui-widget-header ui-corner-left'></div>" )
.appendTo( this.element ); .appendTo( this.element );
this.oldValue = this.options.value;
this._refreshValue(); this._refreshValue();
}, },
@ -62,53 +61,44 @@ $.widget( "ui.progressbar", {
return this.options.value; return this.options.value;
} }
this._setOption( "value", this._constrainedValue( newValue ) ); this.options.value = this._constrainedValue( newValue );
return this; this._refreshValue();
}, },
_constrainedValue: function( newValue ) { _constrainedValue: function( newValue ) {
var val;
if ( newValue === undefined ) { if ( newValue === undefined ) {
val = this.options.value; newValue = this.options.value;
} else {
val = newValue;
} }
this.indeterminate = val === false; this.indeterminate = newValue === false;
// sanitize value // sanitize value
if ( typeof val !== "number" ) { if ( typeof newValue !== "number" ) {
val = 0; newValue = 0;
} }
return this.indeterminate ? false : Math.min( this.options.max, Math.max( this.min, val ) );
return this.indeterminate ? false :
Math.min( this.options.max, Math.max( this.min, newValue ) );
}, },
_setOptions: function( options ) { _setOptions: function( options ) {
var val = options.value;
// Ensure "value" option is set after other values (like max) // Ensure "value" option is set after other values (like max)
var value = options.value;
delete options.value; delete options.value;
this._super( options ); this._super( options );
if ( val !== undefined ) { this.options.value = this._constrainedValue( value );
this._setOption( "value", val ); this._refreshValue();
}
}, },
_setOption: function( key, value ) { _setOption: function( key, value ) {
if ( key === "max" ) { if ( key === "max" ) {
// Don't allow a max less than min // Don't allow a max less than min
this.options.max = Math.max( this.min, value ); value = Math.max( this.min, value );
this.options.value = this._constrainedValue();
}
if ( key === "value" ) {
this.options.value = this._constrainedValue( value );
}
else {
this._super( key, value );
} }
this._refreshValue(); this._super( key, value );
}, },
_percentage: function() { _percentage: function() {