2 Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
3 Available via Academic Free License >= 2.1 OR the modified BSD license.
4 see: http://dojotoolkit.org/license for details
8 if(!dojo._hasResource["dijit._base.wai"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
9 dojo._hasResource["dijit._base.wai"] = true;
10 dojo.provide("dijit._base.wai");
16 // Detects if we are in high-contrast mode or not
18 // This must be a named function and not an anonymous
19 // function, so that the widget parsing code can make sure it
20 // registers its onload function after this function.
21 // DO NOT USE "this" within this function.
23 // create div for testing if high contrast mode is on or images are turned off
24 var div = dojo.create("div",{
27 cssText:'border: 1px solid;'
28 + 'border-color:red green;'
29 + 'position: absolute;'
32 + 'background-image: url("' + (dojo.config.blankGif || dojo.moduleUrl("dojo", "resources/blank.gif")) + '");'
37 var cs = dojo.getComputedStyle(div);
39 var bkImg = cs.backgroundImage;
40 var needsA11y = (cs.borderTopColor == cs.borderRightColor) || (bkImg != null && (bkImg == "none" || bkImg == "url(invalid-url:)" ));
41 dojo[needsA11y ? "addClass" : "removeClass"](dojo.body(), "dijit_a11y");
43 div.outerHTML = ""; // prevent mixed-content warning, see http://support.microsoft.com/kb/925014
45 dojo.body().removeChild(div);
51 // Test if computer is in high contrast mode.
52 // Make sure the a11y test runs first, before widgets are instantiated.
53 if(dojo.isIE || dojo.isMoz){ // NOTE: checking in Safari messes things up
54 dojo._loaders.unshift(dijit.wai.onload);
58 hasWaiRole: function(/*Element*/ elem, /*String?*/ role){
60 // Determines if an element has a particular role.
62 // True if elem has the specific role attribute and false if not.
63 // For backwards compatibility if role parameter not provided,
64 // returns true if has a role
65 var waiRole = this.getWaiRole(elem);
66 return role ? (waiRole.indexOf(role) > -1) : (waiRole.length > 0);
69 getWaiRole: function(/*Element*/ elem){
71 // Gets the role for an element (which should be a wai role).
73 // The role of elem or an empty string if elem
74 // does not have a role.
75 return dojo.trim((dojo.attr(elem, "role") || "").replace("wairole:",""));
78 setWaiRole: function(/*Element*/ elem, /*String*/ role){
80 // Sets the role on an element.
82 // Replace existing role attribute with new role.
84 dojo.attr(elem, "role", role);
87 removeWaiRole: function(/*Element*/ elem, /*String*/ role){
89 // Removes the specified role from an element.
90 // Removes role attribute if no specific role provided (for backwards compat.)
92 var roleValue = dojo.attr(elem, "role");
93 if(!roleValue){ return; }
95 var t = dojo.trim((" " + roleValue + " ").replace(" " + role + " ", " "));
96 dojo.attr(elem, "role", t);
98 elem.removeAttribute("role");
102 hasWaiState: function(/*Element*/ elem, /*String*/ state){
104 // Determines if an element has a given state.
106 // Checks for an attribute called "aria-"+state.
108 // true if elem has a value for the given state and
109 // false if it does not.
111 return elem.hasAttribute ? elem.hasAttribute("aria-"+state) : !!elem.getAttribute("aria-"+state);
114 getWaiState: function(/*Element*/ elem, /*String*/ state){
116 // Gets the value of a state on an element.
118 // Checks for an attribute called "aria-"+state.
120 // The value of the requested state on elem
121 // or an empty string if elem has no value for state.
123 return elem.getAttribute("aria-"+state) || "";
126 setWaiState: function(/*Element*/ elem, /*String*/ state, /*String*/ value){
128 // Sets a state on an element.
130 // Sets an attribute called "aria-"+state.
132 elem.setAttribute("aria-"+state, value);
135 removeWaiState: function(/*Element*/ elem, /*String*/ state){
137 // Removes a state from an element.
139 // Sets an attribute called "aria-"+state.
141 elem.removeAttribute("aria-"+state);