Files
site/WESP_REL/static/js/wesp-lab-access.js
T
2026-07-17 12:57:18 +03:00

41 lines
1.1 KiB
JavaScript

/**
* Видимость Lab-элементов на zootech-страницах (components и др.).
*/
(function (global) {
const HIDDEN_CLASS = "wesp-lab-access-hidden";
function ensureStyle() {
if (document.getElementById("wespLabAccessStyle")) return;
const style = document.createElement("style");
style.id = "wespLabAccessStyle";
style.textContent = `.${HIDDEN_CLASS}{display:none !important;}`;
document.head.appendChild(style);
}
function setHidden(el, hidden) {
if (!el) return;
el.classList.toggle(HIDDEN_CLASS, hidden);
if (hidden) {
el.setAttribute("aria-hidden", "true");
} else {
el.removeAttribute("aria-hidden");
}
}
function apply(canLab) {
ensureStyle();
global.WESP_CAN_LAB = Boolean(canLab);
document.documentElement.classList.toggle("wesp-no-lab", !canLab);
document.querySelectorAll("[data-wesp-lab-gated]").forEach((el) => {
setHidden(el, !canLab);
});
if (canLab) {
global.WespLabComponentsNutrients?.init?.();
}
}
global.WespLabAccess = { apply };
})(window);