1 define("dijit/_base/wai", [
2 "dojo/dom-attr", // domAttr.attr
3 "dojo/_base/lang", // lang.mixin
4 "..", // export symbols to dijit
5 "../hccss" // not using this module directly, but loading it sets CSS flag on <html>
6 ], function(domAttr, lang, dijit){
11 // Deprecated methods for setting/getting wai roles and states.
12 // New code should call setAttribute()/getAttribute() directly.
14 // Also loads hccss to apply dijit_a11y class to root node if machine is in high-contrast mode.
17 hasWaiRole: function(/*Element*/ elem, /*String?*/ role){
19 // Determines if an element has a particular role.
21 // True if elem has the specific role attribute and false if not.
22 // For backwards compatibility if role parameter not provided,
23 // returns true if has a role
24 var waiRole = this.getWaiRole(elem);
25 return role ? (waiRole.indexOf(role) > -1) : (waiRole.length > 0);
28 getWaiRole: function(/*Element*/ elem){
30 // Gets the role for an element (which should be a wai role).
32 // The role of elem or an empty string if elem
33 // does not have a role.
34 return lang.trim((domAttr.get(elem, "role") || "").replace("wairole:",""));
37 setWaiRole: function(/*Element*/ elem, /*String*/ role){
39 // Sets the role on an element.
41 // Replace existing role attribute with new role.
43 domAttr.set(elem, "role", role);
46 removeWaiRole: function(/*Element*/ elem, /*String*/ role){
48 // Removes the specified role from an element.
49 // Removes role attribute if no specific role provided (for backwards compat.)
51 var roleValue = domAttr.get(elem, "role");
52 if(!roleValue){ return; }
54 var t = lang.trim((" " + roleValue + " ").replace(" " + role + " ", " "));
55 domAttr.set(elem, "role", t);
57 elem.removeAttribute("role");
61 hasWaiState: function(/*Element*/ elem, /*String*/ state){
63 // Determines if an element has a given state.
65 // Checks for an attribute called "aria-"+state.
67 // true if elem has a value for the given state and
68 // false if it does not.
70 return elem.hasAttribute ? elem.hasAttribute("aria-"+state) : !!elem.getAttribute("aria-"+state);
73 getWaiState: function(/*Element*/ elem, /*String*/ state){
75 // Gets the value of a state on an element.
77 // Checks for an attribute called "aria-"+state.
79 // The value of the requested state on elem
80 // or an empty string if elem has no value for state.
82 return elem.getAttribute("aria-"+state) || "";
85 setWaiState: function(/*Element*/ elem, /*String*/ state, /*String*/ value){
87 // Sets a state on an element.
89 // Sets an attribute called "aria-"+state.
91 elem.setAttribute("aria-"+state, value);
94 removeWaiState: function(/*Element*/ elem, /*String*/ state){
96 // Removes a state from an element.
98 // Sets an attribute called "aria-"+state.
100 elem.removeAttribute("aria-"+state);