Import: Handle uploads with sha1 starting with 0 properly
[mediawiki.git] / resources / lib / jquery.ui / jquery.ui.progressbar.js
blob4aa19d83b06d03cce134f466b95dc0529c5d0981
1 /*!
2  * jQuery UI Progressbar 1.9.2
3  * http://jqueryui.com
4  *
5  * Copyright 2012 jQuery Foundation and other contributors
6  * Released under the MIT license.
7  * http://jquery.org/license
8  *
9  * http://api.jqueryui.com/progressbar/
10  *
11  * Depends:
12  *   jquery.ui.core.js
13  *   jquery.ui.widget.js
14  */
15 (function( $, undefined ) {
17 $.widget( "ui.progressbar", {
18         version: "1.9.2",
19         options: {
20                 value: 0,
21                 max: 100
22         },
24         min: 0,
26         _create: function() {
27                 this.element
28                         .addClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" )
29                         .attr({
30                                 role: "progressbar",
31                                 "aria-valuemin": this.min,
32                                 "aria-valuemax": this.options.max,
33                                 "aria-valuenow": this._value()
34                         });
36                 this.valueDiv = $( "<div class='ui-progressbar-value ui-widget-header ui-corner-left'></div>" )
37                         .appendTo( this.element );
39                 this.oldValue = this._value();
40                 this._refreshValue();
41         },
43         _destroy: function() {
44                 this.element
45                         .removeClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" )
46                         .removeAttr( "role" )
47                         .removeAttr( "aria-valuemin" )
48                         .removeAttr( "aria-valuemax" )
49                         .removeAttr( "aria-valuenow" );
51                 this.valueDiv.remove();
52         },
54         value: function( newValue ) {
55                 if ( newValue === undefined ) {
56                         return this._value();
57                 }
59                 this._setOption( "value", newValue );
60                 return this;
61         },
63         _setOption: function( key, value ) {
64                 if ( key === "value" ) {
65                         this.options.value = value;
66                         this._refreshValue();
67                         if ( this._value() === this.options.max ) {
68                                 this._trigger( "complete" );
69                         }
70                 }
72                 this._super( key, value );
73         },
75         _value: function() {
76                 var val = this.options.value;
77                 // normalize invalid value
78                 if ( typeof val !== "number" ) {
79                         val = 0;
80                 }
81                 return Math.min( this.options.max, Math.max( this.min, val ) );
82         },
84         _percentage: function() {
85                 return 100 * this._value() / this.options.max;
86         },
88         _refreshValue: function() {
89                 var value = this.value(),
90                         percentage = this._percentage();
92                 if ( this.oldValue !== value ) {
93                         this.oldValue = value;
94                         this._trigger( "change" );
95                 }
97                 this.valueDiv
98                         .toggle( value > this.min )
99                         .toggleClass( "ui-corner-right", value === this.options.max )
100                         .width( percentage.toFixed(0) + "%" );
101                 this.element.attr( "aria-valuenow", value );
102         }
105 })( jQuery );