1 |
/*! |
2 |
* jQuery UI Progressbar 1.10.3 |
3 |
* http://jqueryui.com |
4 |
* |
5 |
* Copyright 2013 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 ) { |
16 |
|
17 |
$.widget( "ui.progressbar", { |
18 |
version: "1.10.3", |
19 |
options: { |
20 |
max: 100, |
21 |
value: 0, |
22 |
|
23 |
change: null, |
24 |
complete: null |
25 |
}, |
26 |
|
27 |
min: 0, |
28 |
|
29 |
_create: function() { |
30 |
// Constrain initial value |
31 |
this.oldValue = this.options.value = this._constrainedValue(); |
32 |
|
33 |
this.element |
34 |
.addClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" ) |
35 |
.attr({ |
36 |
// Only set static values, aria-valuenow and aria-valuemax are |
37 |
// set inside _refreshValue() |
38 |
role: "progressbar", |
39 |
"aria-valuemin": this.min |
40 |
}); |
41 |
|
42 |
this.valueDiv = $( "<div class='ui-progressbar-value ui-widget-header ui-corner-left'></div>" ) |
43 |
.appendTo( this.element ); |
44 |
|
45 |
this._refreshValue(); |
46 |
}, |
47 |
|
48 |
_destroy: function() { |
49 |
this.element |
50 |
.removeClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" ) |
51 |
.removeAttr( "role" ) |
52 |
.removeAttr( "aria-valuemin" ) |
53 |
.removeAttr( "aria-valuemax" ) |
54 |
.removeAttr( "aria-valuenow" ); |
55 |
|
56 |
this.valueDiv.remove(); |
57 |
}, |
58 |
|
59 |
value: function( newValue ) { |
60 |
if ( newValue === undefined ) { |
61 |
return this.options.value; |
62 |
} |
63 |
|
64 |
this.options.value = this._constrainedValue( newValue ); |
65 |
this._refreshValue(); |
66 |
}, |
67 |
|
68 |
_constrainedValue: function( newValue ) { |
69 |
if ( newValue === undefined ) { |
70 |
newValue = this.options.value; |
71 |
} |
72 |
|
73 |
this.indeterminate = newValue === false; |
74 |
|
75 |
// sanitize value |
76 |
if ( typeof newValue !== "number" ) { |
77 |
newValue = 0; |
78 |
} |
79 |
|
80 |
return this.indeterminate ? false : |
81 |
Math.min( this.options.max, Math.max( this.min, newValue ) ); |
82 |
}, |
83 |
|
84 |
_setOptions: function( options ) { |
85 |
// Ensure "value" option is set after other values (like max) |
86 |
var value = options.value; |
87 |
delete options.value; |
88 |
|
89 |
this._super( options ); |
90 |
|
91 |
this.options.value = this._constrainedValue( value ); |
92 |
this._refreshValue(); |
93 |
}, |
94 |
|
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 ); |
99 |
} |
100 |
|
101 |
this._super( key, value ); |
102 |
}, |
103 |
|
104 |
_percentage: function() { |
105 |
return this.indeterminate ? 100 : 100 * ( this.options.value - this.min ) / ( this.options.max - this.min ); |
106 |
}, |
107 |
|
108 |
_refreshValue: function() { |
109 |
var value = this.options.value, |
110 |
percentage = this._percentage(); |
111 |
|
112 |
this.valueDiv |
113 |
.toggle( this.indeterminate || value > this.min ) |
114 |
.toggleClass( "ui-corner-right", value === this.options.max ) |
115 |
.width( percentage.toFixed(0) + "%" ); |
116 |
|
117 |
this.element.toggleClass( "ui-progressbar-indeterminate", this.indeterminate ); |
118 |
|
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 ); |
123 |
} |
124 |
} else { |
125 |
this.element.attr({ |
126 |
"aria-valuemax": this.options.max, |
127 |
"aria-valuenow": value |
128 |
}); |
129 |
if ( this.overlayDiv ) { |
130 |
this.overlayDiv.remove(); |
131 |
this.overlayDiv = null; |
132 |
} |
133 |
} |
134 |
|
135 |
if ( this.oldValue !== value ) { |
136 |
this.oldValue = value; |
137 |
this._trigger( "change" ); |
138 |
} |
139 |
if ( value === this.options.max ) { |
140 |
this._trigger( "complete" ); |
141 |
} |
142 |
} |
143 |
}); |
144 |
|
145 |
})( jQuery ); |