UNPKG

carbon-components-angular

Version:
112 lines (109 loc) 3.75 kB
/*! * * Neutrino v0.0.0 | a11y.js * * Copyright 2014, 2018 IBM * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ function findSiblingElem(target, direction) { if (target[direction]) { if (target[direction].classList.contains("disabled")) { return findSiblingElem(target[direction], direction); } return target[direction]; } } export function findNextElem(target) { return findSiblingElem(target, "nextElementSibling"); } export function findPrevElem(target) { return findSiblingElem(target, "previousElementSibling"); } // check for Hight contrast mode export function HcModeChecker() { var colorTest = "rgb(255, 0, 0)"; var htmlChecker = document.createElement("div"); htmlChecker.classList.add("hc-checker"); document.body.appendChild(htmlChecker); if (window.getComputedStyle(htmlChecker).backgroundColor.toString() !== colorTest) { document.body.classList.add("a11y"); } document.body.removeChild(htmlChecker); } export function focusNextTree(elem, rootElem) { if (rootElem === void 0) { rootElem = null; } if (elem) { var focusable = elem.querySelector("[tabindex='0']"); if (focusable) { focusable.focus(); } else { focusNextElem(elem, rootElem); } } } export function focusNextElem(elem, rootElem) { if (rootElem === void 0) { rootElem = null; } if (elem) { var nextElem = elem.nextElementSibling; if (nextElem) { var focusableElem = nextElem.querySelector("[tabindex='0']"); if (focusableElem) { focusableElem.focus(); } else { focusNextElem(nextElem, rootElem); } } else { if (rootElem) { var nextRootElem = rootElem.nextElementSibling; if (nextRootElem) { focusNextTree(nextRootElem, rootElem); } } } } } export function focusPrevElem(elem, parentRef) { if (parentRef === void 0) { parentRef = null; } if (elem) { var prevElem = elem.previousElementSibling; if (prevElem) { var focusableElem = prevElem.querySelector("[tabindex='0']"); if (focusableElem) { if (focusableElem.getAttribute("aria-expanded") === "true") { var lastFocElms = prevElem.querySelectorAll("[tabindex='0']"); var arrLen = lastFocElms.length - 1; for (var i = arrLen; i >= 0; i--) { if (!!(lastFocElms[i].offsetWidth || lastFocElms[i].offsetHeight || lastFocElms[i].getClientRects().length)) { focusableElem = lastFocElms[i]; break; } } } focusableElem.focus(); } else { focusPrevElem(prevElem, parentRef); } } else { if (parentRef) { parentRef.querySelector("[tabindex='0']").focus(); } } } } //# sourceMappingURL=a11y.js.map