52
52
var ngAriaModule = angular . module ( 'ngAria' , [ 'ng' ] ) .
53
53
provider ( '$aria' , $AriaProvider ) ;
54
54
55
+ /**
56
+ * Internal Utilities
57
+ */
58
+ var nodeBlackList = [ 'BUTTON' , 'A' , 'INPUT' , 'TEXTAREA' , 'SELECT' , 'DETAILS' , 'SUMMARY' ] ;
59
+
60
+ var isNodeOneOf = function ( elem , nodeTypeArray ) {
61
+ if ( nodeTypeArray . indexOf ( elem [ 0 ] . nodeName ) !== - 1 ) {
62
+ return true ;
63
+ }
64
+ }
55
65
/**
56
66
* @ngdoc provider
57
67
* @name $ariaProvider
@@ -113,10 +123,10 @@ function $AriaProvider() {
113
123
config = angular . extend ( config , newConfig ) ;
114
124
} ;
115
125
116
- function watchExpr ( attrName , ariaAttr , negate ) {
126
+ function watchExpr ( attrName , ariaAttr , nodeBlackList , negate ) {
117
127
return function ( scope , elem , attr ) {
118
128
var ariaCamelName = attr . $normalize ( ariaAttr ) ;
119
- if ( config [ ariaCamelName ] && ! attr [ ariaCamelName ] ) {
129
+ if ( config [ ariaCamelName ] && ! isNodeOneOf ( elem , nodeBlackList ) && ! attr [ ariaCamelName ] ) {
120
130
scope . $watch ( attr [ attrName ] , function ( boolVal ) {
121
131
// ensure boolean value
122
132
boolVal = negate ? ! boolVal : ! ! boolVal ;
@@ -125,7 +135,6 @@ function $AriaProvider() {
125
135
}
126
136
} ;
127
137
}
128
-
129
138
/**
130
139
* @ngdoc service
131
140
* @name $aria
@@ -184,10 +193,10 @@ function $AriaProvider() {
184
193
185
194
186
195
ngAriaModule . directive ( 'ngShow' , [ '$aria' , function ( $aria ) {
187
- return $aria . $$watchExpr ( 'ngShow' , 'aria-hidden' , true ) ;
196
+ return $aria . $$watchExpr ( 'ngShow' , 'aria-hidden' , [ ] , true ) ;
188
197
} ] )
189
198
. directive ( 'ngHide' , [ '$aria' , function ( $aria ) {
190
- return $aria . $$watchExpr ( 'ngHide' , 'aria-hidden' , false ) ;
199
+ return $aria . $$watchExpr ( 'ngHide' , 'aria-hidden' , [ ] , false ) ;
191
200
} ] )
192
201
. directive ( 'ngModel' , [ '$aria' , function ( $aria ) {
193
202
@@ -261,6 +270,9 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) {
261
270
scope . $watch ( ngAriaWatchModelValue , shape === 'radio' ?
262
271
getRadioReaction ( ) : ngAriaCheckboxReaction ) ;
263
272
}
273
+ if ( needsTabIndex ) {
274
+ elem . attr ( 'tabindex' , 0 ) ;
275
+ }
264
276
break ;
265
277
case 'range' :
266
278
if ( shouldAttachRole ( shape , elem ) ) {
@@ -289,6 +301,9 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) {
289
301
} ) ;
290
302
}
291
303
}
304
+ if ( needsTabIndex ) {
305
+ elem . attr ( 'tabindex' , 0 ) ;
306
+ }
292
307
break ;
293
308
case 'multiline' :
294
309
if ( shouldAttachAttr ( 'aria-multiline' , 'ariaMultiline' , elem ) ) {
@@ -297,10 +312,6 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) {
297
312
break ;
298
313
}
299
314
300
- if ( needsTabIndex ) {
301
- elem . attr ( 'tabindex' , 0 ) ;
302
- }
303
-
304
315
if ( ngModel . $validators . required && shouldAttachAttr ( 'aria-required' , 'ariaRequired' , elem ) ) {
305
316
scope . $watch ( function ngAriaRequiredWatch ( ) {
306
317
return ngModel . $error . required ;
@@ -322,7 +333,7 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) {
322
333
} ;
323
334
} ] )
324
335
. directive ( 'ngDisabled' , [ '$aria' , function ( $aria ) {
325
- return $aria . $$watchExpr ( 'ngDisabled' , 'aria-disabled' ) ;
336
+ return $aria . $$watchExpr ( 'ngDisabled' , 'aria-disabled' , [ ] ) ;
326
337
} ] )
327
338
. directive ( 'ngMessages' , function ( ) {
328
339
return {
@@ -342,43 +353,36 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) {
342
353
var fn = $parse ( attr . ngClick , /* interceptorFn */ null , /* expensiveChecks */ true ) ;
343
354
return function ( scope , elem , attr ) {
344
355
345
- var nodeBlackList = [ 'BUTTON' , 'A' , 'INPUT' , 'TEXTAREA' ] ;
356
+ if ( ! isNodeOneOf ( elem , nodeBlackList ) ) {
346
357
347
- function isNodeOneOf ( elem , nodeTypeArray ) {
348
- if ( nodeTypeArray . indexOf ( elem [ 0 ] . nodeName ) !== - 1 ) {
349
- return true ;
358
+ if ( $aria . config ( 'bindRoleForClick' ) && ! elem . attr ( 'role' ) ) {
359
+ elem . attr ( 'role' , 'button' ) ;
350
360
}
351
- }
352
361
353
- if ( $aria . config ( 'bindRoleForClick' )
354
- && ! elem . attr ( 'role' )
355
- && ! isNodeOneOf ( elem , nodeBlackList ) ) {
356
- elem . attr ( 'role' , 'button' ) ;
357
- }
358
-
359
- if ( $aria . config ( 'tabindex' ) && ! elem . attr ( 'tabindex' ) ) {
360
- elem . attr ( 'tabindex' , 0 ) ;
361
- }
362
+ if ( $aria . config ( 'tabindex' ) && ! elem . attr ( 'tabindex' ) ) {
363
+ elem . attr ( 'tabindex' , 0 ) ;
364
+ }
362
365
363
- if ( $aria . config ( 'bindKeypress' ) && ! attr . ngKeypress && ! isNodeOneOf ( elem , nodeBlackList ) ) {
364
- elem . on ( 'keypress' , function ( event ) {
365
- var keyCode = event . which || event . keyCode ;
366
- if ( keyCode === 32 || keyCode === 13 ) {
367
- scope . $apply ( callback ) ;
368
- }
366
+ if ( $aria . config ( 'bindKeypress' ) && ! attr . ngKeypress ) {
367
+ elem . on ( 'keypress' , function ( event ) {
368
+ var keyCode = event . which || event . keyCode ;
369
+ if ( keyCode === 32 || keyCode === 13 ) {
370
+ scope . $apply ( callback ) ;
371
+ }
369
372
370
- function callback ( ) {
371
- fn ( scope , { $event : event } ) ;
372
- }
373
- } ) ;
373
+ function callback ( ) {
374
+ fn ( scope , { $event : event } ) ;
375
+ }
376
+ } ) ;
377
+ }
374
378
}
375
379
} ;
376
380
}
377
381
} ;
378
382
} ] )
379
383
. directive ( 'ngDblclick' , [ '$aria' , function ( $aria ) {
380
384
return function ( scope , elem , attr ) {
381
- if ( $aria . config ( 'tabindex' ) && ! elem . attr ( 'tabindex' ) ) {
385
+ if ( $aria . config ( 'tabindex' ) && ! elem . attr ( 'tabindex' ) && ! isNodeOneOf ( elem , nodeBlackList ) ) {
382
386
elem . attr ( 'tabindex' , 0 ) ;
383
387
}
384
388
} ;
0 commit comments