1
+ /**
2
+ * @ngdoc module
3
+ * @name material.core.aria
4
+ * @description
5
+ * Aria Expectations for ngMaterial components.
6
+ */
7
+ angular
8
+ . module ( 'material.core' )
9
+ . provider ( '$mdAria' , MdAriaProvider ) ;
10
+
11
+ /**
12
+ * @ngdoc service
13
+ * @name $mdAriaProvider
14
+ * @module material.core.aria
15
+ *
16
+ * @description
17
+ *
18
+ * Modify options of the `$mdAria` service, which will be used by most of the Angular Material components.
19
+ **
20
+ *
21
+ * You are able to disable `$mdAria` warnings, by using the following markup.
22
+ * <hljs lang="js">
23
+ * app.config(function($mdAriaProvider) {
24
+ * // Globally disables all ARIA warnings.
25
+ * $mdAriaProvider.disableWarnings();
26
+ * });
27
+ * </hljs>
28
+ *
29
+ */
30
+ function MdAriaProvider ( ) {
1
31
2
- angular . module ( 'material.core' )
3
- . service ( '$mdAria' , AriaService ) ;
32
+ var self = this ;
33
+
34
+ /**
35
+ * Whether we should show ARIA warnings in the console, if labels are missing on the element
36
+ * By default the warnings are enabled
37
+ */
38
+ self . showWarnings = true ;
39
+
40
+ return {
41
+ disableWarnings : disableWarnings ,
42
+ $get : function ( $$rAF , $log , $window , $interpolate ) {
43
+ return MdAriaService . apply ( self , arguments ) ;
44
+ }
45
+ } ;
46
+
47
+ /**
48
+ * @ngdoc method
49
+ * @name $mdAriaProvider#disableWarnings
50
+ */
51
+ function disableWarnings ( ) {
52
+ self . showWarnings = false ;
53
+ }
54
+ }
4
55
5
56
/*
6
57
* @ngInject
7
58
*/
8
- function AriaService ( $$rAF , $log , $window , $interpolate ) {
59
+ function MdAriaService ( $$rAF , $log , $window , $interpolate ) {
60
+
61
+ // Load the showWarnings option from the current context and store it inside of a scope variable,
62
+ // because the context will be probably lost in some function calls.
63
+ var showWarnings = this . showWarnings ;
9
64
10
65
return {
11
66
expect : expect ,
@@ -32,7 +87,7 @@ function AriaService($$rAF, $log, $window, $interpolate) {
32
87
defaultValue = angular . isString ( defaultValue ) ? defaultValue . trim ( ) : '' ;
33
88
if ( defaultValue . length ) {
34
89
element . attr ( attrName , defaultValue ) ;
35
- } else {
90
+ } else if ( showWarnings ) {
36
91
$log . warn ( 'ARIA: Attribute "' , attrName , '", required for accessibility, is missing on node:' , node ) ;
37
92
}
38
93
0 commit comments