root / dijit / trunk / _base / wai.js

Revision 20570, 4.7 kB (checked in by bill, 4 months ago)

Remove trailing spaces from dijit files, refs #10048 !strict.

  • Property svn:eol-style set to native
Line 
1dojo.provide("dijit._base.wai");
2
3dijit.wai = {
4        onload: function(){
5                // summary:
6                //              Detects if we are in high-contrast mode or not
7
8                // This must be a named function and not an anonymous
9                // function, so that the widget parsing code can make sure it
10                // registers its onload function after this function.
11                // DO NOT USE "this" within this function.
12
13                // create div for testing if high contrast mode is on or images are turned off
14                var div = dojo.create("div",{
15                        id: "a11yTestNode",
16                        style:{
17                                cssText:'border: 1px solid;'
18                                        + 'border-color:red green;'
19                                        + 'position: absolute;'
20                                        + 'height: 5px;'
21                                        + 'top: -999px;'
22                                        + 'background-image: url("' + (dojo.config.blankGif || dojo.moduleUrl("dojo", "resources/blank.gif")) + '");'
23                        }
24                }, dojo.body());
25
26                // test it
27                var cs = dojo.getComputedStyle(div);
28                if(cs){
29                        var bkImg = cs.backgroundImage;
30                        var needsA11y = (cs.borderTopColor == cs.borderRightColor) || (bkImg != null && (bkImg == "none" || bkImg == "url(invalid-url:)" ));
31                        dojo[needsA11y ? "addClass" : "removeClass"](dojo.body(), "dijit_a11y");
32                        if(dojo.isIE){
33                                div.outerHTML = "";             // prevent mixed-content warning, see http://support.microsoft.com/kb/925014
34                        }else{
35                                dojo.body().removeChild(div);
36                        }
37                }
38        }
39};
40
41// Test if computer is in high contrast mode.
42// Make sure the a11y test runs first, before widgets are instantiated.
43if(dojo.isIE || dojo.isMoz){    // NOTE: checking in Safari messes things up
44        dojo._loaders.unshift(dijit.wai.onload);
45}
46
47dojo.mixin(dijit, {
48        _XhtmlRoles: /banner|contentinfo|definition|main|navigation|search|note|secondary|seealso/,
49
50        hasWaiRole: function(/*Element*/ elem, /*String*/ role){
51                // summary:
52                //              Determines if an element has a particular non-XHTML role.
53                // returns:
54                //              True if elem has the specific non-XHTML role attribute and false if not.
55                //              For backwards compatibility if role parameter not provided,
56                //              returns true if has non XHTML role
57                var waiRole = this.getWaiRole(elem);
58                return role ? (waiRole.indexOf(role) > -1) : (waiRole.length > 0);
59        },
60
61        getWaiRole: function(/*Element*/ elem){
62                // summary:
63                //              Gets the non-XHTML role for an element (which should be a wai role).
64                // returns:
65                //              The non-XHTML role of elem or an empty string if elem
66                //              does not have a role.
67                 return dojo.trim((dojo.attr(elem, "role") || "").replace(this._XhtmlRoles,"").replace("wairole:",""));
68        },
69
70        setWaiRole: function(/*Element*/ elem, /*String*/ role){
71                // summary:
72                //              Sets the role on an element.
73                // description:
74                //              Replace existing role attribute with new role.
75                //              If elem already has an XHTML role, append this role to XHTML role
76                //              and remove other ARIA roles.
77
78                var curRole = dojo.attr(elem, "role") || "";
79                if(!this._XhtmlRoles.test(curRole)){
80                        dojo.attr(elem, "role", role);
81                }else{
82                        if((" "+ curRole +" ").indexOf(" " + role + " ") < 0){
83                                var clearXhtml = dojo.trim(curRole.replace(this._XhtmlRoles, ""));
84                                var cleanRole = dojo.trim(curRole.replace(clearXhtml, ""));
85                                dojo.attr(elem, "role", cleanRole + (cleanRole ? ' ' : '') + role);
86                        }
87                }
88        },
89
90        removeWaiRole: function(/*Element*/ elem, /*String*/ role){
91                // summary:
92                //              Removes the specified non-XHTML role from an element.
93                //              Removes role attribute if no specific role provided (for backwards compat.)
94
95                var roleValue = dojo.attr(elem, "role");
96                if(!roleValue){ return; }
97                if(role){
98                        var t = dojo.trim((" " + roleValue + " ").replace(" " + role + " ", " "));
99                        dojo.attr(elem, "role", t);
100                }else{
101                        elem.removeAttribute("role");
102                }
103        },
104
105        hasWaiState: function(/*Element*/ elem, /*String*/ state){
106                // summary:
107                //              Determines if an element has a given state.
108                // description:
109                //              Checks for an attribute called "aria-"+state.
110                // returns:
111                //              true if elem has a value for the given state and
112                //              false if it does not.
113
114                return elem.hasAttribute ? elem.hasAttribute("aria-"+state) : !!elem.getAttribute("aria-"+state);
115        },
116
117        getWaiState: function(/*Element*/ elem, /*String*/ state){
118                // summary:
119                //              Gets the value of a state on an element.
120                // description:
121                //              Checks for an attribute called "aria-"+state.
122                // returns:
123                //              The value of the requested state on elem
124                //              or an empty string if elem has no value for state.
125
126                return elem.getAttribute("aria-"+state) || "";
127        },
128
129        setWaiState: function(/*Element*/ elem, /*String*/ state, /*String*/ value){
130                // summary:
131                //              Sets a state on an element.
132                // description:
133                //              Sets an attribute called "aria-"+state.
134
135                elem.setAttribute("aria-"+state, value);
136        },
137
138        removeWaiState: function(/*Element*/ elem, /*String*/ state){
139                // summary:
140                //              Removes a state from an element.
141                // description:
142                //              Sets an attribute called "aria-"+state.
143
144                elem.removeAttribute("aria-"+state);
145        }
146});
Note: See TracBrowser for help on using the browser.