]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dijit/_base/wai.js
Comment class stub
[eow] / static / dojo-release-1.1.1 / dijit / _base / wai.js
1 if(!dojo._hasResource["dijit._base.wai"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dijit._base.wai"] = true;
3 dojo.provide("dijit._base.wai");
4
5 dijit.wai = {
6         onload: function(){
7                 // summary:
8                 //              Detects if we are in high-contrast mode or not
9
10                 // This must be a named function and not an anonymous
11                 // function, so that the widget parsing code can make sure it
12                 // registers its onload function after this function.
13                 // DO NOT USE "this" within this function.
14
15                 // create div for testing if high contrast mode is on or images are turned off
16                 var div = dojo.doc.createElement("div");
17                 div.id = "a11yTestNode";
18                 div.style.cssText = 'border: 1px solid;'
19                         + 'border-color:red green;'
20                         + 'position: absolute;'
21                         + 'height: 5px;'
22                         + 'top: -999px;'
23                         + 'background-image: url("' + dojo.moduleUrl("dojo", "resources/blank.gif") + '");';
24                 dojo.body().appendChild(div);
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                         dojo.body().removeChild(div);
33                 }
34         }
35 };
36
37 // Test if computer is in high contrast mode.
38 // Make sure the a11y test runs first, before widgets are instantiated.
39 if(dojo.isIE || dojo.isMoz){    // NOTE: checking in Safari messes things up
40         dojo._loaders.unshift(dijit.wai.onload);
41 }
42
43 dojo.mixin(dijit,
44 {
45         hasWaiRole: function(/*Element*/ elem){
46                 // summary: Determines if an element has a role.
47                 // returns: true if elem has a role attribute and false if not.
48                 return elem.hasAttribute ? elem.hasAttribute("role") : !!elem.getAttribute("role");
49         },
50
51         getWaiRole: function(/*Element*/ elem){
52                 // summary: Gets the role for an element.
53                 // returns:
54                 //              The role of elem or an empty string if elem
55                 //              does not have a role.
56                 var value = elem.getAttribute("role");
57                 if(value){
58                         var prefixEnd = value.indexOf(":");
59                         return prefixEnd == -1 ? value : value.substring(prefixEnd+1);
60                 }else{
61                         return "";
62                 }
63         },
64
65         setWaiRole: function(/*Element*/ elem, /*String*/ role){
66                 // summary: Sets the role on an element.
67                 // description:
68                 //              On Firefox 2 and below, "wairole:" is
69                 //              prepended to the provided role value.
70                 elem.setAttribute("role", (dojo.isFF && dojo.isFF < 3) ? "wairole:" + role : role);
71         },
72
73         removeWaiRole: function(/*Element*/ elem){
74                 // summary: Removes the role from an element.
75                 elem.removeAttribute("role");
76         },
77
78         hasWaiState: function(/*Element*/ elem, /*String*/ state){
79                 // summary: Determines if an element has a given state.
80                 // description:
81                 //              On Firefox 2 and below, we check for an attribute in namespace
82                 //              "http://www.w3.org/2005/07/aaa" with a name of the given state.
83                 //              On all other browsers, we check for an attribute
84                 //              called "aria-"+state.
85                 // returns:
86                 //              true if elem has a value for the given state and
87                 //              false if it does not.
88                 if(dojo.isFF && dojo.isFF < 3){
89                         return elem.hasAttributeNS("http://www.w3.org/2005/07/aaa", state);
90                 }else{
91                         return elem.hasAttribute ? elem.hasAttribute("aria-"+state) : !!elem.getAttribute("aria-"+state);
92                 }
93         },
94
95         getWaiState: function(/*Element*/ elem, /*String*/ state){
96                 // summary: Gets the value of a state on an element.
97                 // description:
98                 //              On Firefox 2 and below, we check for an attribute in namespace
99                 //              "http://www.w3.org/2005/07/aaa" with a name of the given state.
100                 //              On all other browsers, we check for an attribute called
101                 //              "aria-"+state.
102                 // returns:
103                 //              The value of the requested state on elem
104                 //              or an empty string if elem has no value for state.
105                 if(dojo.isFF && dojo.isFF < 3){
106                         return elem.getAttributeNS("http://www.w3.org/2005/07/aaa", state);
107                 }else{
108                         var value = elem.getAttribute("aria-"+state);
109                         return value ? value : "";
110                 }
111         },
112
113         setWaiState: function(/*Element*/ elem, /*String*/ state, /*String*/ value){
114                 // summary: Sets a state on an element.
115                 // description:
116                 //              On Firefox 2 and below, we set an attribute in namespace
117                 //              "http://www.w3.org/2005/07/aaa" with a name of the given state.
118                 //              On all other browsers, we set an attribute called
119                 //              "aria-"+state.
120                 if(dojo.isFF && dojo.isFF < 3){
121                         elem.setAttributeNS("http://www.w3.org/2005/07/aaa",
122                                 "aaa:"+state, value);
123                 }else{
124                         elem.setAttribute("aria-"+state, value);
125                 }
126         },
127
128         removeWaiState: function(/*Element*/ elem, /*String*/ state){
129                 // summary: Removes a state from an element.
130                 // description:
131                 //              On Firefox 2 and below, we remove the attribute in namespace
132                 //              "http://www.w3.org/2005/07/aaa" with a name of the given state.
133                 //              On all other browsers, we remove the attribute called
134                 //              "aria-"+state.
135                 if(dojo.isFF && dojo.isFF < 3){
136                         elem.removeAttributeNS("http://www.w3.org/2005/07/aaa", state);
137                 }else{
138                         elem.removeAttribute("aria-"+state);
139                 }
140         }
141 });
142
143 }