@@ -26,9 +26,13 @@ angular.module('material.components.progressCircular', [
26
26
* not necessary to expose what's happening behind the scenes and how long it will take, use an
27
27
* indeterminate indicator.
28
28
*
29
- * @param {string } md-mode Select from one of two modes: **'determinate'** and **'indeterminate'**.<br/>
30
- * Note: if the `md-mode` value is undefined or not 1 of the two (2) valid modes, then `.ng-hide`
29
+ * @param {string } md-mode Select from one of two modes: **'determinate'** and **'indeterminate'**.
30
+ *
31
+ * Note: if the `md-mode` value is set as undefined or specified as not 1 of the two (2) valid modes, then `.ng-hide`
31
32
* will be auto-applied as a style to the component.
33
+ *
34
+ * Note: if not configured, the `md-mode="indeterminate"` will be auto injected as an attribute.
35
+ * If `value=""` is also specified, however, then `md-mode="determinate"` would be auto-injected instead.
32
36
* @param {number= } value In determinate mode, this number represents the percentage of the
33
37
* circular progress. Default: 0
34
38
* @param {number= } md-diameter This specifies the diamter of the circular progress. The value
@@ -46,7 +50,7 @@ angular.module('material.components.progressCircular', [
46
50
* <md-progress-circular md-mode="indeterminate"></md-progress-circular>
47
51
* </hljs>
48
52
*/
49
- function MdProgressCircularDirective ( $mdConstant , $mdTheming , $mdUtil ) {
53
+ function MdProgressCircularDirective ( $mdTheming , $mdUtil , $log ) {
50
54
var DEFAULT_PROGRESS_SIZE = 100 ;
51
55
var DEFAULT_SCALING = 0.5 ;
52
56
@@ -87,43 +91,68 @@ function MdProgressCircularDirective($mdConstant, $mdTheming, $mdUtil) {
87
91
function postLink ( scope , element , attr ) {
88
92
$mdTheming ( element ) ;
89
93
90
- var circle = element [ 0 ] ;
94
+ var circle = element ;
91
95
var spinnerWrapper = angular . element ( element . children ( ) [ 0 ] ) ;
92
-
93
96
var lastMode , toVendorCSS = $mdUtil . dom . animator . toCss ;
94
97
95
- // Update size/scaling of the progress indicator
96
- // Watch the "value" and "md-mode" attributes
98
+ updateScale ( ) ;
99
+ validateMode ( ) ;
100
+ watchAttributes ( ) ;
97
101
98
- circle . style [ $mdConstant . CSS . TRANSFORM ] = 'scale(' + getDiameterRatio ( ) + ')' ;
99
-
100
- attr . $observe ( 'value' , function ( value ) {
101
- var percentValue = clamp ( value ) ;
102
- element . attr ( 'aria-valuenow' , percentValue ) ;
103
-
104
- if ( attr . mdMode == "determinate" ) {
105
- animateIndicator ( percentValue ) ;
106
- }
107
- } ) ;
102
+ /**
103
+ * Watch the value and md-mode attributes
104
+ */
105
+ function watchAttributes ( ) {
106
+ attr . $observe ( 'value' , function ( value ) {
107
+ var percentValue = clamp ( value ) ;
108
+ element . attr ( 'aria-valuenow' , percentValue ) ;
109
+
110
+ if ( mode ( ) == MODE_DETERMINATE ) {
111
+ animateIndicator ( percentValue ) ;
112
+ }
113
+ } ) ;
114
+ attr . $observe ( 'mdMode' , function ( mode ) {
115
+ switch ( mode ) {
116
+ case MODE_DETERMINATE :
117
+ case MODE_INDETERMINATE :
118
+ spinnerWrapper . removeClass ( 'ng-hide' ) ;
119
+ spinnerWrapper . removeClass ( lastMode ) ;
120
+ spinnerWrapper . addClass ( lastMode = "md-mode-" + mode ) ;
121
+ break ;
122
+ default :
123
+ spinnerWrapper . removeClass ( lastMode ) ;
124
+ spinnerWrapper . addClass ( 'ng-hide' ) ;
125
+ lastMode = undefined ;
126
+ break ;
127
+ }
128
+ } ) ;
129
+ }
108
130
109
- attr . $observe ( 'mdMode' , function ( mode ) {
110
- switch ( mode ) {
111
- case MODE_DETERMINATE :
112
- case MODE_INDETERMINATE :
113
- spinnerWrapper . removeClass ( 'ng-hide' ) ;
131
+ /**
132
+ * Update size/scaling of the progress indicator
133
+ * Watch the "value" and "md-mode" attributes
134
+ */
135
+ function updateScale ( ) {
136
+ circle . css ( toVendorCSS ( {
137
+ transform : $mdUtil . supplant ( 'scale( {0} )' , [ getDiameterRatio ( ) ] )
138
+ } ) ) ;
139
+ }
114
140
115
- // Inject class selector instead of attribute selector
116
- // (@see layout.js changes for IE performance issues)
141
+ /**
142
+ * Auto-defaults the mode to either `determinate` or `indeterminate` mode; if not specified
143
+ */
144
+ function validateMode ( ) {
145
+ if ( angular . isUndefined ( attr . mdMode ) ) {
146
+ var hasValue = angular . isDefined ( attr . value ) ;
147
+ var mode = hasValue ? MODE_DETERMINATE : MODE_INDETERMINATE ;
148
+ var info = "Auto-adding the missing md-mode='{0}' to the ProgressCircular element" ;
117
149
118
- if ( lastMode ) spinnerWrapper . removeClass ( lastMode ) ;
119
- lastMode = "md-mode-" + mode ;
120
- if ( lastMode ) spinnerWrapper . addClass ( lastMode ) ;
150
+ $log . debug ( $mdUtil . supplant ( info , [ mode ] ) ) ;
121
151
122
- break ;
123
- default :
124
- spinnerWrapper . addClass ( 'ng-hide' ) ;
152
+ element . attr ( "md-mode" , mode ) ;
153
+ attr [ 'mdMode' ] = mode ;
125
154
}
126
- } ) ;
155
+ }
127
156
128
157
var leftC , rightC , gap ;
129
158
@@ -136,6 +165,8 @@ function MdProgressCircularDirective($mdConstant, $mdTheming, $mdUtil) {
136
165
* - use attribute selectors which had poor performances in IE
137
166
*/
138
167
function animateIndicator ( value ) {
168
+ if ( ! mode ( ) ) return ;
169
+
139
170
leftC = leftC || angular . element ( element [ 0 ] . querySelector ( '.md-left > .md-half-circle' ) ) ;
140
171
rightC = rightC || angular . element ( element [ 0 ] . querySelector ( '.md-right > .md-half-circle' ) ) ;
141
172
gap = gap || angular . element ( element [ 0 ] . querySelector ( '.md-gap' ) ) ;
@@ -146,7 +177,7 @@ function MdProgressCircularDirective($mdConstant, $mdTheming, $mdUtil) {
146
177
} ) ,
147
178
leftStyles = removeEmptyValues ( {
148
179
transition : ( value <= 50 ) ? "transform 0.1s linear" : "" ,
149
- transform : $mdUtil . supplant ( "rotate({0}deg)" , [ value <= 50 ? 135 : ( ( ( ( value - 50 ) / 50 ) * 180 ) + 135 ) ] )
180
+ transform : $mdUtil . supplant ( "rotate({0}deg)" , [ value <= 50 ? 135 : ( ( ( value - 50 ) / 50 * 180 ) + 135 ) ] )
150
181
} ) ,
151
182
rightStyles = removeEmptyValues ( {
152
183
transition : ( value >= 50 ) ? "transform 0.1s linear" : "" ,
@@ -174,6 +205,25 @@ function MdProgressCircularDirective($mdConstant, $mdTheming, $mdUtil) {
174
205
// should return ratio; DEFAULT_PROGRESS_SIZE === 100px is default size
175
206
return ( value > 1 ) ? value / DEFAULT_PROGRESS_SIZE : value ;
176
207
}
208
+
209
+ /**
210
+ * Is the md-mode a valid option?
211
+ */
212
+ function mode ( ) {
213
+ var value = attr . mdMode ;
214
+ if ( value ) {
215
+ switch ( value ) {
216
+ case MODE_DETERMINATE :
217
+ case MODE_INDETERMINATE :
218
+ break ;
219
+ default :
220
+ value = undefined ;
221
+ break ;
222
+ }
223
+ }
224
+ return value ;
225
+ }
226
+
177
227
}
178
228
179
229
/**
0 commit comments