hccss.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. define([
  2. "require", // require, require.toUrl
  3. "./_base/config", // config.blankGif
  4. "./dom-class", // domClass.add
  5. "./dom-style", // domStyle.getComputedStyle
  6. "./has",
  7. "./domReady",
  8. "./_base/window" // win.body
  9. ], function(require, config, domClass, domStyle, has, domReady, win){
  10. // module:
  11. // dojo/hccss
  12. /*=====
  13. return function(){
  14. // summary:
  15. // Test if computer is in high contrast mode (i.e. if browser is not displaying background images).
  16. // Defines `has("highcontrast")` and sets `dj_a11y` CSS class on `<body>` if machine is in high contrast mode.
  17. // Returns `has()` method;
  18. };
  19. =====*/
  20. // Has() test for when background images aren't displayed. Don't call has("highcontrast") before dojo/domReady!.
  21. has.add("highcontrast", function(){
  22. // note: if multiple documents, doesn't matter which one we use
  23. var div = win.doc.createElement("div");
  24. div.style.cssText = "border: 1px solid; border-color:red green; position: absolute; height: 5px; top: -999px;" +
  25. "background-image: url(\"" + (config.blankGif || require.toUrl("./resources/blank.gif")) + "\");";
  26. win.body().appendChild(div);
  27. var cs = domStyle.getComputedStyle(div),
  28. bkImg = cs.backgroundImage,
  29. hc = (cs.borderTopColor == cs.borderRightColor) ||
  30. (bkImg && (bkImg == "none" || bkImg == "url(invalid-url:)" ));
  31. if(has("ie") <= 8){
  32. div.outerHTML = ""; // prevent mixed-content warning, see http://support.microsoft.com/kb/925014
  33. }else{
  34. win.body().removeChild(div);
  35. }
  36. return hc;
  37. });
  38. domReady(function(){
  39. if(has("highcontrast")){
  40. domClass.add(win.body(), "dj_a11y");
  41. }
  42. });
  43. return has;
  44. });