]> git.wh0rd.org Git - tt-rss.git/blob - lib/dijit/_base/wai.js
upgrade Dojo to 1.6.1
[tt-rss.git] / lib / dijit / _base / wai.js
1 /*
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
5 */
6
7
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");
11
12
13 dijit.wai = {
14         onload: function(){
15                 // summary:
16                 //              Detects if we are in high-contrast mode or not
17
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.
22
23                 // create div for testing if high contrast mode is on or images are turned off
24                 var div = dojo.create("div",{
25                         id: "a11yTestNode",
26                         style:{
27                                 cssText:'border: 1px solid;'
28                                         + 'border-color:red green;'
29                                         + 'position: absolute;'
30                                         + 'height: 5px;'
31                                         + 'top: -999px;'
32                                         + 'background-image: url("' + (dojo.config.blankGif || dojo.moduleUrl("dojo", "resources/blank.gif")) + '");'
33                         }
34                 }, dojo.body());
35
36                 // test it
37                 var cs = dojo.getComputedStyle(div);
38                 if(cs){
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");
42                         if(dojo.isIE){
43                                 div.outerHTML = "";             // prevent mixed-content warning, see http://support.microsoft.com/kb/925014
44                         }else{
45                                 dojo.body().removeChild(div);
46                         }
47                 }
48         }
49 };
50
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);
55 }
56
57 dojo.mixin(dijit, {
58         hasWaiRole: function(/*Element*/ elem, /*String?*/ role){
59                 // summary:
60                 //              Determines if an element has a particular role.
61                 // returns:
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);
67         },
68
69         getWaiRole: function(/*Element*/ elem){
70                 // summary:
71                 //              Gets the role for an element (which should be a wai role).
72                 // returns:
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:",""));
76         },
77
78         setWaiRole: function(/*Element*/ elem, /*String*/ role){
79                 // summary:
80                 //              Sets the role on an element.
81                 // description:
82                 //              Replace existing role attribute with new role.
83
84                         dojo.attr(elem, "role", role);
85         },
86
87         removeWaiRole: function(/*Element*/ elem, /*String*/ role){
88                 // summary:
89                 //              Removes the specified role from an element.
90                 //              Removes role attribute if no specific role provided (for backwards compat.)
91
92                 var roleValue = dojo.attr(elem, "role");
93                 if(!roleValue){ return; }
94                 if(role){
95                         var t = dojo.trim((" " + roleValue + " ").replace(" " + role + " ", " "));
96                         dojo.attr(elem, "role", t);
97                 }else{
98                         elem.removeAttribute("role");
99                 }
100         },
101
102         hasWaiState: function(/*Element*/ elem, /*String*/ state){
103                 // summary:
104                 //              Determines if an element has a given state.
105                 // description:
106                 //              Checks for an attribute called "aria-"+state.
107                 // returns:
108                 //              true if elem has a value for the given state and
109                 //              false if it does not.
110
111                 return elem.hasAttribute ? elem.hasAttribute("aria-"+state) : !!elem.getAttribute("aria-"+state);
112         },
113
114         getWaiState: function(/*Element*/ elem, /*String*/ state){
115                 // summary:
116                 //              Gets the value of a state on an element.
117                 // description:
118                 //              Checks for an attribute called "aria-"+state.
119                 // returns:
120                 //              The value of the requested state on elem
121                 //              or an empty string if elem has no value for state.
122
123                 return elem.getAttribute("aria-"+state) || "";
124         },
125
126         setWaiState: function(/*Element*/ elem, /*String*/ state, /*String*/ value){
127                 // summary:
128                 //              Sets a state on an element.
129                 // description:
130                 //              Sets an attribute called "aria-"+state.
131
132                 elem.setAttribute("aria-"+state, value);
133         },
134
135         removeWaiState: function(/*Element*/ elem, /*String*/ state){
136                 // summary:
137                 //              Removes a state from an element.
138                 // description:
139                 //              Sets an attribute called "aria-"+state.
140
141                 elem.removeAttribute("aria-"+state);
142         }
143 });
144
145 }