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");
8 // Detects if we are in high-contrast mode or not
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.
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;'
23 + 'background-image: url("' + dojo.moduleUrl("dojo", "resources/blank.gif") + '");';
24 dojo.body().appendChild(div);
27 var cs = dojo.getComputedStyle(div);
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);
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);
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");
51 getWaiRole: function(/*Element*/ elem){
52 // summary: Gets the role for an element.
54 // The role of elem or an empty string if elem
55 // does not have a role.
56 var value = elem.getAttribute("role");
58 var prefixEnd = value.indexOf(":");
59 return prefixEnd == -1 ? value : value.substring(prefixEnd+1);
65 setWaiRole: function(/*Element*/ elem, /*String*/ role){
66 // summary: Sets the role on an element.
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);
73 removeWaiRole: function(/*Element*/ elem){
74 // summary: Removes the role from an element.
75 elem.removeAttribute("role");
78 hasWaiState: function(/*Element*/ elem, /*String*/ state){
79 // summary: Determines if an element has a given state.
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.
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);
91 return elem.hasAttribute ? elem.hasAttribute("aria-"+state) : !!elem.getAttribute("aria-"+state);
95 getWaiState: function(/*Element*/ elem, /*String*/ state){
96 // summary: Gets the value of a state on an element.
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
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);
108 var value = elem.getAttribute("aria-"+state);
109 return value ? value : "";
113 setWaiState: function(/*Element*/ elem, /*String*/ state, /*String*/ value){
114 // summary: Sets a state on an element.
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
120 if(dojo.isFF && dojo.isFF < 3){
121 elem.setAttributeNS("http://www.w3.org/2005/07/aaa",
122 "aaa:"+state, value);
124 elem.setAttribute("aria-"+state, value);
128 removeWaiState: function(/*Element*/ elem, /*String*/ state){
129 // summary: Removes a state from an element.
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
135 if(dojo.isFF && dojo.isFF < 3){
136 elem.removeAttributeNS("http://www.w3.org/2005/07/aaa", state);
138 elem.removeAttribute("aria-"+state);