hccss.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. define("dijit/hccss", [
  2. "require", // require.toUrl
  3. "dojo/_base/config", // config.blankGif
  4. "dojo/dom-class", // domClass.add domConstruct.create domStyle.getComputedStyle
  5. "dojo/dom-construct", // domClass.add domConstruct.create domStyle.getComputedStyle
  6. "dojo/dom-style", // domClass.add domConstruct.create domStyle.getComputedStyle
  7. "dojo/ready", // ready
  8. "dojo/_base/sniff", // has("ie") has("mozilla")
  9. "dojo/_base/window" // win.body
  10. ], function(require, config, domClass, domConstruct, domStyle, ready, has, win){
  11. // module:
  12. // dijit/hccss
  13. // summary:
  14. // Test if computer is in high contrast mode, and sets dijit_a11y flag on <body> if it is.
  15. if(has("ie") || has("mozilla")){ // NOTE: checking in Safari messes things up
  16. // priority is 90 to run ahead of parser priority of 100
  17. ready(90, function(){
  18. // summary:
  19. // Detects if we are in high-contrast mode or not
  20. // create div for testing if high contrast mode is on or images are turned off
  21. var div = domConstruct.create("div",{
  22. id: "a11yTestNode",
  23. style:{
  24. cssText:'border: 1px solid;'
  25. + 'border-color:red green;'
  26. + 'position: absolute;'
  27. + 'height: 5px;'
  28. + 'top: -999px;'
  29. + 'background-image: url("' + (config.blankGif || require.toUrl("dojo/resources/blank.gif")) + '");'
  30. }
  31. }, win.body());
  32. // test it
  33. var cs = domStyle.getComputedStyle(div);
  34. if(cs){
  35. var bkImg = cs.backgroundImage;
  36. var needsA11y = (cs.borderTopColor == cs.borderRightColor) || (bkImg != null && (bkImg == "none" || bkImg == "url(invalid-url:)" ));
  37. if(needsA11y){
  38. domClass.add(win.body(), "dijit_a11y");
  39. }
  40. if(has("ie")){
  41. div.outerHTML = ""; // prevent mixed-content warning, see http://support.microsoft.com/kb/925014
  42. }else{
  43. win.body().removeChild(div);
  44. }
  45. }
  46. });
  47. }
  48. });