jquery-ui/ui/jquery.ui.progressbar.js

107 lines
2.2 KiB
JavaScript
Raw Normal View History

/*
* jQuery UI Progressbar @VERSION
*
2011-01-17 14:13:18 +00:00
* Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*
* http://docs.jquery.com/UI/Progressbar
*
* Depends:
* jquery.ui.core.js
* jquery.ui.widget.js
*/
(function( $, undefined ) {
$.widget( "ui.progressbar", {
options: {
value: 0,
max: 100
},
2010-07-29 09:38:24 +00:00
min: 0,
_create: function() {
this.element
.addClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" )
.attr({
role: "progressbar",
2010-07-29 09:38:24 +00:00
"aria-valuemin": this.min,
"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 );
2008-12-05 13:35:11 +00:00
this.oldValue = this._value();
2008-12-05 13:35:11 +00:00
this._refreshValue();
},
2008-09-20 11:22:54 +00:00
_destroy: function() {
2008-11-21 04:12:18 +00:00
this.element
.removeClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" )
.removeAttr( "role" )
.removeAttr( "aria-valuemin" )
.removeAttr( "aria-valuemax" )
.removeAttr( "aria-valuenow" );
2008-12-05 13:35:11 +00:00
this.valueDiv.remove();
},
value: function( newValue ) {
if ( newValue === undefined ) {
return this._value();
}
this._setOption( "value", newValue );
return this;
2008-12-05 13:35:11 +00:00
},
_setOption: function( key, value ) {
2010-07-29 09:38:24 +00:00
if ( key === "value" ) {
this.options.value = value;
this._refreshValue();
if ( this._value() === this.options.max ) {
this._trigger( "complete" );
}
2008-09-20 11:22:54 +00:00
}
2008-12-05 13:35:11 +00:00
this._super( "_setOption", key, value );
},
_value: function() {
var val = this.options.value;
// normalize invalid value
if ( typeof val !== "number" ) {
val = 0;
}
return Math.min( this.options.max, Math.max( this.min, val ) );
},
_percentage: function() {
return 100 * this._value() / this.options.max;
},
2008-12-05 13:35:11 +00:00
_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.options.max )
.width( percentage.toFixed(0) + "%" );
this.element.attr( "aria-valuenow", value );
}
});
$.extend( $.ui.progressbar, {
version: "@VERSION"
});
})( jQuery );