85 lines
3.3 KiB
JavaScript
85 lines
3.3 KiB
JavaScript
(function () {
|
|
"use strict";
|
|
|
|
function text(value) {
|
|
return (value || "").replace(/\s+/g, " ").trim();
|
|
}
|
|
|
|
function isNativeControl(element) {
|
|
return /^(A|BUTTON|INPUT|SELECT|TEXTAREA)$/.test(element.tagName);
|
|
}
|
|
|
|
function accessibleName(element) {
|
|
var title = text(element.getAttribute("title"));
|
|
if (title) return title;
|
|
|
|
var widget = element.closest ? element.closest(".widget") : null;
|
|
var caption = widget ? widget.querySelector(".lblcontainer") : null;
|
|
if (caption) return text(caption.textContent);
|
|
|
|
var id = element.id || "";
|
|
var names = {
|
|
btnfirst: "First record",
|
|
btnprev: "Previous record",
|
|
btnnext: "Next record",
|
|
btnlast: "Last record",
|
|
close: "Refresh"
|
|
};
|
|
return names[id] || "";
|
|
}
|
|
|
|
function enhance(root) {
|
|
var scope = root && root.querySelectorAll ? root : document;
|
|
|
|
scope.querySelectorAll("img:not([alt])").forEach(function (image) {
|
|
image.alt = text(image.getAttribute("title"));
|
|
});
|
|
|
|
scope.querySelectorAll(".linkbutton[onclick], .customLink[onclick], img[onclick]").forEach(function (control) {
|
|
if (isNativeControl(control)) return;
|
|
if (!control.hasAttribute("role")) control.setAttribute("role", "button");
|
|
if (!control.hasAttribute("tabindex")) control.tabIndex = 0;
|
|
var name = accessibleName(control) || text(control.textContent);
|
|
if (name && !control.hasAttribute("aria-label")) control.setAttribute("aria-label", name);
|
|
});
|
|
|
|
scope.querySelectorAll("input, select, textarea").forEach(function (control) {
|
|
if (control.type === "hidden" || control.hasAttribute("aria-label") || control.hasAttribute("aria-labelledby")) return;
|
|
if (control.id && document.querySelector('label[for="' + CSS.escape(control.id) + '"]')) return;
|
|
var name = accessibleName(control);
|
|
if (name) control.setAttribute("aria-label", name);
|
|
});
|
|
|
|
scope.querySelectorAll('input[type="button"], input[type="submit"], input[type="reset"]').forEach(function (control) {
|
|
if (text(control.value) || control.hasAttribute("aria-label")) return;
|
|
var name = accessibleName(control);
|
|
if (name) {
|
|
control.setAttribute("aria-label", name);
|
|
if (!control.title) control.title = name;
|
|
}
|
|
});
|
|
}
|
|
|
|
document.addEventListener("keydown", function (event) {
|
|
var control = event.target.closest ? event.target.closest('[role="button"]') : null;
|
|
if (!control || (event.key !== "Enter" && event.key !== " ")) return;
|
|
event.preventDefault();
|
|
control.click();
|
|
});
|
|
|
|
function start() {
|
|
enhance(document);
|
|
if (!window.MutationObserver) return;
|
|
new MutationObserver(function (mutations) {
|
|
mutations.forEach(function (mutation) {
|
|
mutation.addedNodes.forEach(function (node) {
|
|
if (node.nodeType === 1) enhance(node);
|
|
});
|
|
});
|
|
}).observe(document.body, {childList: true, subtree: true});
|
|
}
|
|
|
|
if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", start);
|
|
else start();
|
|
}());
|