Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 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");
4
 
5
dijit.wai = {
6
	onload: function(){
7
		// summary:
8
		//		Function that detects if we are in high-contrast mode or not,
9
		//		and sets up a timer to periodically confirm the value.
10
		//		figure out the background-image style property
11
		//		and apply that to the image.src property.
12
		// description:
13
		//		This must be a named function and not an anonymous
14
		//		function, so that the widget parsing code can make sure it
15
		//		registers its onload function after this function.
16
		//		DO NOT USE "this" within this function.
17
 
18
		// create div for testing if high contrast mode is on or images are turned off
19
		var div = document.createElement("div");
20
		div.id = "a11yTestNode";
21
		div.style.cssText = 'border: 1px solid;'
22
			+ 'border-color:red green;'
23
			+ 'position: absolute;'
24
			+ 'height: 5px;'
25
			+ 'top: -999px;'
26
			+ 'background-image: url("' + dojo.moduleUrl("dijit", "form/templates/blank.gif") + '");';
27
		dojo.body().appendChild(div);
28
 
29
		// test it
30
		function check(){
31
			var cs = dojo.getComputedStyle(div);
32
			if(cs){
33
				var bkImg = cs.backgroundImage;
34
				var needsA11y = (cs.borderTopColor==cs.borderRightColor) || (bkImg != null && (bkImg == "none" || bkImg == "url(invalid-url:)" ));
35
				dojo[needsA11y ? "addClass" : "removeClass"](dojo.body(), "dijit_a11y");
36
			}
37
		}
38
		check();
39
		if(dojo.isIE){
40
			setInterval(check, 4000);
41
		}
42
	}
43
};
44
 
45
// Test if computer is in high contrast mode.
46
// Make sure the a11y test runs first, before widgets are instantiated.
47
if(dojo.isIE || dojo.isMoz){	// NOTE: checking in Safari messes things up
48
	dojo._loaders.unshift(dijit.wai.onload);
49
}
50
 
51
dojo.mixin(dijit,
52
{
53
	hasWaiRole: function(/*Element*/ elem){
54
		// Summary: Return true if elem has a role attribute and false if not.
55
		if(elem.hasAttribute){
56
			return elem.hasAttribute("role");
57
		}else{
58
			return elem.getAttribute("role") ? true : false;
59
		}
60
	},
61
 
62
	getWaiRole: function(/*Element*/ elem){
63
		// Summary: Return the role of elem or an empty string if
64
		//		elem does not have a role.
65
		var value = elem.getAttribute("role");
66
		if(value){
67
			var prefixEnd = value.indexOf(":");
68
			return prefixEnd == -1 ? value : value.substring(prefixEnd+1);
69
		}else{
70
			return "";
71
		}
72
	},
73
 
74
	setWaiRole: function(/*Element*/ elem, /*String*/ role){
75
		// Summary: Set the role on elem. On Firefox 2 and below, "wairole:" is
76
		//		prepended to the provided role value.
77
		if(dojo.isFF && dojo.isFF < 3){
78
			elem.setAttribute("role", "wairole:"+role);
79
		}else{
80
			elem.setAttribute("role", role);
81
		}
82
	},
83
 
84
	removeWaiRole: function(/*Element*/ elem){
85
		// Summary: Removes the role attribute from elem.
86
		elem.removeAttribute("role");
87
	},
88
 
89
	hasWaiState: function(/*Element*/ elem, /*String*/ state){
90
		// Summary: Return true if elem has a value for the given state and
91
		//		false if it does not.
92
		//		On Firefox 2 and below, we check for an attribute in namespace
93
		//		"http://www.w3.org/2005/07/aaa" with a name of the given state.
94
		//		On all other browsers, we check for an attribute called
95
		//		"aria-"+state.
96
		if(dojo.isFF && dojo.isFF < 3){
97
			return elem.hasAttributeNS("http://www.w3.org/2005/07/aaa", state);
98
		}else{
99
			if(elem.hasAttribute){
100
				return elem.hasAttribute("aria-"+state);
101
			}else{
102
				return elem.getAttribute("aria-"+state) ? true : false;
103
			}
104
		}
105
	},
106
 
107
	getWaiState: function(/*Element*/ elem, /*String*/ state){
108
		// Summary: Return the value of the requested state on elem
109
		//		or an empty string if elem has no value for state.
110
		//		On Firefox 2 and below, we check for an attribute in namespace
111
		//		"http://www.w3.org/2005/07/aaa" with a name of the given state.
112
		//		On all other browsers, we check for an attribute called
113
		//		"aria-"+state.
114
		if(dojo.isFF && dojo.isFF < 3){
115
			return elem.getAttributeNS("http://www.w3.org/2005/07/aaa", state);
116
		}else{
117
			var value =  elem.getAttribute("aria-"+state);
118
			return value ? value : "";
119
		}
120
	},
121
 
122
	setWaiState: function(/*Element*/ elem, /*String*/ state, /*String*/ value){
123
		// Summary: Set state on elem to value.
124
		//		On Firefox 2 and below, we set an attribute in namespace
125
		//		"http://www.w3.org/2005/07/aaa" with a name of the given state.
126
		//		On all other browsers, we set an attribute called
127
		//		"aria-"+state.
128
		if(dojo.isFF && dojo.isFF < 3){
129
			elem.setAttributeNS("http://www.w3.org/2005/07/aaa",
130
				"aaa:"+state, value);
131
		}else{
132
			elem.setAttribute("aria-"+state, value);
133
		}
134
	},
135
 
136
	removeWaiState: function(/*Element*/ elem, /*String*/ state){
137
		// Summary: Removes the given state from elem.
138
		//		On Firefox 2 and below, we remove the attribute in namespace
139
		//		"http://www.w3.org/2005/07/aaa" with a name of the given state.
140
		//		On all other browsers, we remove the attribute called
141
		//		"aria-"+state.
142
		if(dojo.isFF && dojo.isFF < 3){
143
			elem.removeAttributeNS("http://www.w3.org/2005/07/aaa", state);
144
		}else{
145
			elem.removeAttribute("aria-"+state);
146
		}
147
	}
148
});
149
 
150
}