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

95 lines
2.0 KiB
JavaScript
Raw Normal View History

/*
* jQuery UI Progressbar @VERSION
*
* Copyright 2010, 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
},
2010-07-29 09:38:24 +00:00
min: 0,
max: 100,
_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.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._refreshValue();
},
2008-09-20 11:22:54 +00:00
2008-11-21 04:12:18 +00:00
destroy: function() {
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();
2008-11-21 04:12:18 +00:00
$.Widget.prototype.destroy.apply( this, arguments );
},
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();
this._trigger( "change" );
2008-09-20 11:22:54 +00:00
}
2008-12-05 13:35:11 +00:00
$.Widget.prototype._setOption.apply( this, arguments );
},
_value: function() {
var val = this.options.value;
// normalize invalid value
if ( typeof val !== "number" ) {
val = 0;
}
2010-07-29 09:38:24 +00:00
return Math.min( this.max, Math.max( this.min, val ) );
},
2008-12-05 13:35:11 +00:00
_refreshValue: function() {
var value = this.value();
this.valueDiv
2010-07-29 09:38:24 +00:00
.toggleClass( "ui-corner-right", value === this.max )
.width( value + "%" );
this.element.attr( "aria-valuenow", value );
}
});
$.extend( $.ui.progressbar, {
version: "@VERSION"
});
})( jQuery );