2 * jQuery UI Progressbar 1.10.4
5 * Copyright 2014 jQuery Foundation and other contributors
6 * Released under the MIT license.
7 * http://jquery.org/license
9 * http://api.jqueryui.com/progressbar/
15 (function( $, undefined ) {
17 $.widget( "ui.progressbar", {
30 // Constrain initial value
31 this.oldValue = this.options.value = this._constrainedValue();
34 .addClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" )
36 // Only set static values, aria-valuenow and aria-valuemax are
37 // set inside _refreshValue()
39 "aria-valuemin": this.min
42 this.valueDiv = $( "<div class='ui-progressbar-value ui-widget-header ui-corner-left'></div>" )
43 .appendTo( this.element );
48 _destroy: function() {
50 .removeClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" )
52 .removeAttr( "aria-valuemin" )
53 .removeAttr( "aria-valuemax" )
54 .removeAttr( "aria-valuenow" );
56 this.valueDiv.remove();
59 value: function( newValue ) {
60 if ( newValue === undefined ) {
61 return this.options.value;
64 this.options.value = this._constrainedValue( newValue );
68 _constrainedValue: function( newValue ) {
69 if ( newValue === undefined ) {
70 newValue = this.options.value;
73 this.indeterminate = newValue === false;
76 if ( typeof newValue !== "number" ) {
80 return this.indeterminate ? false :
81 Math.min( this.options.max, Math.max( this.min, newValue ) );
84 _setOptions: function( options ) {
85 // Ensure "value" option is set after other values (like max)
86 var value = options.value;
89 this._super( options );
91 this.options.value = this._constrainedValue( value );
95 _setOption: function( key, value ) {
96 if ( key === "max" ) {
97 // Don't allow a max less than min
98 value = Math.max( this.min, value );
101 this._super( key, value );
104 _percentage: function() {
105 return this.indeterminate ? 100 : 100 * ( this.options.value - this.min ) / ( this.options.max - this.min );
108 _refreshValue: function() {
109 var value = this.options.value,
110 percentage = this._percentage();
113 .toggle( this.indeterminate || value > this.min )
114 .toggleClass( "ui-corner-right", value === this.options.max )
115 .width( percentage.toFixed(0) + "%" );
117 this.element.toggleClass( "ui-progressbar-indeterminate", this.indeterminate );
119 if ( this.indeterminate ) {
120 this.element.removeAttr( "aria-valuenow" );
121 if ( !this.overlayDiv ) {
122 this.overlayDiv = $( "<div class='ui-progressbar-overlay'></div>" ).appendTo( this.valueDiv );
126 "aria-valuemax": this.options.max,
127 "aria-valuenow": value
129 if ( this.overlayDiv ) {
130 this.overlayDiv.remove();
131 this.overlayDiv = null;
135 if ( this.oldValue !== value ) {
136 this.oldValue = value;
137 this._trigger( "change" );
139 if ( value === this.options.max ) {
140 this._trigger( "complete" );