forked from dojo/dojo-oldmirror
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hccss.js
45 lines (38 loc) · 1.58 KB
/
hccss.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
define([
"require", // require.toUrl
"./_base/config", // config.blankGif
"./dom-class", // domClass.add
"./dom-construct", // domConstruct.destroy
"./dom-style", // domStyle.getComputedStyle
"./has",
"./ready", // ready
"./_base/window" // win.body
], function(require, config, domClass, domConstruct, domStyle, has, ready, win){
// module:
// dojo/hccss
// summary:
// Test if computer is in high contrast mode (i.e. if browser is not displaying background images).
// Defines has("highcontrast") and sets dj_a11y CSS class on <body> if machine is in high contrast mode.
// Has() test for when background images aren't displayed. Don't call has("highcontrast") before dojo/domReady!.
has.add("highcontrast", function(){
// note: if multiple documents, doesn't matter which one we use
var div = win.doc.createElement("div");
div.style.cssText = "border: 1px solid; border-color:red green; position: absolute; height: 5px; top: -999px;" +
"background-image: url(" + (config.blankGif || require.toUrl("./resources/blank.gif")) + ");";
win.body().appendChild(div);
var cs = domStyle.getComputedStyle(div),
bkImg = cs.backgroundImage,
hc = (cs.borderTopColor == cs.borderRightColor) ||
(bkImg && (bkImg == "none" || bkImg == "url(invalid-url:)" ));
domConstruct.destroy(div);
return hc;
});
// Priority is 90 to run ahead of parser priority of 100. For 2.0, remove the ready() call and instead
// change this module to depend on dojo/domReady!
ready(90, function(){
if(has("highcontrast")){
domClass.add(win.body(), "dj_a11y");
}
});
return has;
});