source: Dev/branches/rest-dojo-ui/client/dijit/_base/wai.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 3.2 KB
Line 
1define([
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){
7
8        // module:
9        //              dijit/_base/wai
10        // summary:
11        //              Deprecated methods for setting/getting wai roles and states.
12        //              New code should call setAttribute()/getAttribute() directly.
13        //
14        //              Also loads hccss to apply dijit_a11y class to root node if machine is in high-contrast mode.
15
16        lang.mixin(dijit, {
17                hasWaiRole: function(/*Element*/ elem, /*String?*/ role){
18                        // summary:
19                        //              Determines if an element has a particular role.
20                        // returns:
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);
26                },
27
28                getWaiRole: function(/*Element*/ elem){
29                        // summary:
30                        //              Gets the role for an element (which should be a wai role).
31                        // returns:
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:",""));
35                },
36
37                setWaiRole: function(/*Element*/ elem, /*String*/ role){
38                        // summary:
39                        //              Sets the role on an element.
40                        // description:
41                        //              Replace existing role attribute with new role.
42
43                        domAttr.set(elem, "role", role);
44                },
45
46                removeWaiRole: function(/*Element*/ elem, /*String*/ role){
47                        // summary:
48                        //              Removes the specified role from an element.
49                        //              Removes role attribute if no specific role provided (for backwards compat.)
50
51                        var roleValue = domAttr.get(elem, "role");
52                        if(!roleValue){ return; }
53                        if(role){
54                                var t = lang.trim((" " + roleValue + " ").replace(" " + role + " ", " "));
55                                domAttr.set(elem, "role", t);
56                        }else{
57                                elem.removeAttribute("role");
58                        }
59                },
60
61                hasWaiState: function(/*Element*/ elem, /*String*/ state){
62                        // summary:
63                        //              Determines if an element has a given state.
64                        // description:
65                        //              Checks for an attribute called "aria-"+state.
66                        // returns:
67                        //              true if elem has a value for the given state and
68                        //              false if it does not.
69
70                        return elem.hasAttribute ? elem.hasAttribute("aria-"+state) : !!elem.getAttribute("aria-"+state);
71                },
72
73                getWaiState: function(/*Element*/ elem, /*String*/ state){
74                        // summary:
75                        //              Gets the value of a state on an element.
76                        // description:
77                        //              Checks for an attribute called "aria-"+state.
78                        // returns:
79                        //              The value of the requested state on elem
80                        //              or an empty string if elem has no value for state.
81
82                        return elem.getAttribute("aria-"+state) || "";
83                },
84
85                setWaiState: function(/*Element*/ elem, /*String*/ state, /*String*/ value){
86                        // summary:
87                        //              Sets a state on an element.
88                        // description:
89                        //              Sets an attribute called "aria-"+state.
90
91                        elem.setAttribute("aria-"+state, value);
92                },
93
94                removeWaiState: function(/*Element*/ elem, /*String*/ state){
95                        // summary:
96                        //              Removes a state from an element.
97                        // description:
98                        //              Sets an attribute called "aria-"+state.
99
100                        elem.removeAttribute("aria-"+state);
101                }
102        });
103
104        return dijit;
105});
Note: See TracBrowser for help on using the repository browser.