(function () {
if (typeof window === "undefined") return;
function runAxe() {
if (typeof window.axe === "undefined") {
setTimeout(runAxe, 200);
return;
}
window.axe
.run(document, {
resultTypes: ["violations"],
})
.then(function (results) {
var violations = (results.violations || []).map(function (v) {
return {
id: v.id,
impact: v.impact, help: v.help,
helpUrl: v.helpUrl,
description: v.description,
nodes: (v.nodes || []).map(function (n) {
return {
target: Array.isArray(n.target) ? n.target.join(" ") : String(n.target || ""),
html: typeof n.html === "string" ? n.html.slice(0, 240) : "",
failureSummary: n.failureSummary || "",
};
}),
};
});
try {
window.parent.postMessage(
{
type: "cms-axe-results",
violations: violations,
previewUrl: location.href,
ranAt: Date.now(),
},
location.origin === "null" ? "*" : location.origin
);
} catch (e) {
console.warn("[cms-axe-preview] postMessage failed:", e);
}
})
.catch(function (err) {
try {
window.parent.postMessage(
{
type: "cms-axe-results",
violations: [],
error: String(err && err.message ? err.message : err),
previewUrl: location.href,
ranAt: Date.now(),
},
location.origin
);
} catch (_) {
}
});
}
if (document.readyState === "complete") {
setTimeout(runAxe, 0);
} else {
window.addEventListener("load", function () {
setTimeout(runAxe, 0);
});
}
window.addEventListener("message", function (event) {
if (event.origin !== location.origin) return;
var data = event.data;
if (!data || data.type !== "cms-axe-scroll-to" || typeof data.selector !== "string") {
return;
}
var el = null;
try {
el = document.querySelector(data.selector);
} catch (_) {
}
if (el) {
el.scrollIntoView({ behavior: "smooth", block: "center" });
var prev = el.style.outline;
var prevOffset = el.style.outlineOffset;
el.style.outline = "3px solid #d92d20";
el.style.outlineOffset = "2px";
setTimeout(function () {
el.style.outline = prev;
el.style.outlineOffset = prevOffset;
}, 1800);
}
});
})();