17
17
$ . widget ( "ui.progressbar" , {
18
18
version : "@VERSION" ,
19
19
options : {
20
- value : false ,
20
+ value : 0 ,
21
21
max : 100
22
22
} ,
23
23
24
24
min : 0 ,
25
25
26
26
_create : function ( ) {
27
+ var val = this . _value ( ) ;
27
28
this . element
28
29
. addClass ( "ui-progressbar ui-widget ui-widget-content ui-corner-all" )
29
30
. attr ( {
30
31
role : "progressbar" ,
31
32
"aria-valuemin" : this . min ,
32
- "aria-valuemax" : this . options . max ,
33
- "aria-valuenow" : this . _value ( )
33
+ "aria-valuemax" : this . options . max
34
34
} ) ;
35
35
36
36
this . valueDiv = $ ( "<div class='ui-progressbar-value ui-widget-header ui-corner-left'></div>" )
37
37
. appendTo ( this . element ) ;
38
38
39
- if ( this . options . value !== false ) {
40
- this . oldValue = this . _value ( ) ;
41
- } else {
42
- this . oldValue = false ;
43
- this . valueDiv . addClass ( "ui-progressbar-animated" ) ;
44
- }
45
39
this . _refreshValue ( ) ;
46
40
} ,
47
41
@@ -68,11 +62,7 @@ $.widget( "ui.progressbar", {
68
62
_setOption : function ( key , value ) {
69
63
if ( key === "value" ) {
70
64
this . options . value = value ;
71
- if ( value !== false ) {
72
- this . valueDiv . removeClass ( "ui-progressbar-animated" ) ;
73
- } else {
74
- this . valueDiv . addClass ( "ui-progressbar-animated" ) ;
75
- }
65
+
76
66
this . _refreshValue ( ) ;
77
67
if ( this . _value ( ) === this . options . max ) {
78
68
this . _trigger ( "complete" ) ;
@@ -88,29 +78,36 @@ $.widget( "ui.progressbar", {
88
78
if ( typeof val !== "number" && val !== false ) {
89
79
val = 0 ;
90
80
} else if ( val === false ) {
91
- val = 100 ;
81
+ val = NaN ;
92
82
}
93
83
return Math . min ( this . options . max , Math . max ( this . min , val ) ) ;
94
84
} ,
95
85
96
86
_percentage : function ( ) {
97
- return 100 * this . _value ( ) / this . options . max ;
87
+ var val = this . _value ( ) ;
88
+ return isNaN ( val ) ? 100 : 100 * val / this . options . max ;
98
89
} ,
99
90
100
91
_refreshValue : function ( ) {
101
92
var value = this . value ( ) ,
102
93
percentage = this . _percentage ( ) ;
103
94
95
+ this . valueDiv . toggleClass ( "ui-progressbar-indeterminate" , isNaN ( value ) ) ;
96
+
104
97
if ( this . oldValue !== value ) {
105
98
this . oldValue = value ;
106
99
this . _trigger ( "change" ) ;
107
100
}
108
101
109
102
this . valueDiv
110
- . toggle ( value > this . min )
103
+ . toggle ( isNaN ( value ) || value > this . min )
111
104
. toggleClass ( "ui-corner-right" , value === this . options . max )
112
105
. width ( percentage . toFixed ( 0 ) + "%" ) ;
113
- this . element . attr ( "aria-valuenow" , value ) ;
106
+ if ( isNaN ( value ) ) {
107
+ this . element . removeAttr ( "aria-valuenow" ) ;
108
+ } else {
109
+ this . element . attr ( "aria-valuenow" , value ) ;
110
+ }
114
111
}
115
112
} ) ;
116
113
0 commit comments