123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- if (!dojo._hasResource["dijit._base.wai"]) { // _hasResource checks added by
- // build. Do not use
- // _hasResource directly in your
- // code.
- dojo._hasResource["dijit._base.wai"] = true;
- dojo.provide("dijit._base.wai");
- dijit.wai = {
- onload : function() {
- // summary:
- // Function that detects if we are in high-contrast mode or not,
- // and sets up a timer to periodically confirm the value.
- // figure out the background-image style property
- // and apply that to the image.src property.
- // description:
- // This must be a named function and not an anonymous
- // function, so that the widget parsing code can make sure it
- // registers its onload function after this function.
- // DO NOT USE "this" within this function.
- // create div for testing if high contrast mode is on or images are
- // turned off
- var div = document.createElement("div");
- div.id = "a11yTestNode";
- div.style.cssText = 'border: 1px solid;'
- + 'border-color:red green;' + 'position: absolute;'
- + 'height: 5px;' + 'top: -999px;'
- + 'background-image: url("'
- + dojo.moduleUrl("dijit", "form/templates/blank.gif")
- + '");';
- dojo.body().appendChild(div);
- // test it
- function check() {
- var cs = dojo.getComputedStyle(div);
- if (cs) {
- var bkImg = cs.backgroundImage;
- var needsA11y = (cs.borderTopColor == cs.borderRightColor)
- || (bkImg != null && (bkImg == "none" || bkImg == "url(invalid-url:)"));
- dojo[needsA11y ? "addClass" : "removeClass"](dojo.body(),
- "dijit_a11y");
- }
- }
- check();
- if (dojo.isIE) {
- setInterval(check, 4000);
- }
- }
- };
- // Test if computer is in high contrast mode.
- // Make sure the a11y test runs first, before widgets are instantiated.
- if (dojo.isIE || dojo.isMoz) { // NOTE: checking in Safari messes things up
- dojo._loaders.unshift(dijit.wai.onload);
- }
- dojo.mixin(dijit, {
- hasWaiRole : function(/* Element */elem) {
- // Summary: Return true if elem has a role attribute and false if
- // not.
- if (elem.hasAttribute) {
- return elem.hasAttribute("role");
- } else {
- return elem.getAttribute("role") ? true : false;
- }
- },
- getWaiRole : function(/* Element */elem) {
- // Summary: Return the role of elem or an empty string if
- // elem does not have a role.
- var value = elem.getAttribute("role");
- if (value) {
- var prefixEnd = value.indexOf(":");
- return prefixEnd == -1 ? value : value.substring(prefixEnd + 1);
- } else {
- return "";
- }
- },
- setWaiRole : function(/* Element */elem, /* String */role) {
- // Summary: Set the role on elem. On Firefox 2 and below, "wairole:"
- // is
- // prepended to the provided role value.
- if (dojo.isFF && dojo.isFF < 3) {
- elem.setAttribute("role", "wairole:" + role);
- } else {
- elem.setAttribute("role", role);
- }
- },
- removeWaiRole : function(/* Element */elem) {
- // Summary: Removes the role attribute from elem.
- elem.removeAttribute("role");
- },
- hasWaiState : function(/* Element */elem, /* String */state) {
- // Summary: Return true if elem has a value for the given state and
- // false if it does not.
- // On Firefox 2 and below, we check for an attribute in namespace
- // "http://www.w3.org/2005/07/aaa" with a name of the given state.
- // On all other browsers, we check for an attribute called
- // "aria-"+state.
- if (dojo.isFF && dojo.isFF < 3) {
- return elem.hasAttributeNS("http://www.w3.org/2005/07/aaa",
- state);
- } else {
- if (elem.hasAttribute) {
- return elem.hasAttribute("aria-" + state);
- } else {
- return elem.getAttribute("aria-" + state) ? true : false;
- }
- }
- },
- getWaiState : function(/* Element */elem, /* String */state) {
- // Summary: Return the value of the requested state on elem
- // or an empty string if elem has no value for state.
- // On Firefox 2 and below, we check for an attribute in namespace
- // "http://www.w3.org/2005/07/aaa" with a name of the given state.
- // On all other browsers, we check for an attribute called
- // "aria-"+state.
- if (dojo.isFF && dojo.isFF < 3) {
- return elem.getAttributeNS("http://www.w3.org/2005/07/aaa",
- state);
- } else {
- var value = elem.getAttribute("aria-" + state);
- return value ? value : "";
- }
- },
- setWaiState : function(/* Element */elem, /* String */state, /* String */
- value) {
- // Summary: Set state on elem to value.
- // On Firefox 2 and below, we set an attribute in namespace
- // "http://www.w3.org/2005/07/aaa" with a name of the given state.
- // On all other browsers, we set an attribute called
- // "aria-"+state.
- if (dojo.isFF && dojo.isFF < 3) {
- elem.setAttributeNS("http://www.w3.org/2005/07/aaa", "aaa:"
- + state, value);
- } else {
- elem.setAttribute("aria-" + state, value);
- }
- },
- removeWaiState : function(/* Element */elem, /* String */state) {
- // Summary: Removes the given state from elem.
- // On Firefox 2 and below, we remove the attribute in namespace
- // "http://www.w3.org/2005/07/aaa" with a name of the given state.
- // On all other browsers, we remove the attribute called
- // "aria-"+state.
- if (dojo.isFF && dojo.isFF < 3) {
- elem.removeAttributeNS("http://www.w3.org/2005/07/aaa", state);
- } else {
- elem.removeAttribute("aria-" + state);
- }
- }
- });
- }
|