(function () {
if (typeof document === "undefined" || window.__rcmsPreviewGuard) return;
window.__rcmsPreviewGuard = true;
function sameDocHash(a) {
var raw = a.getAttribute("href") || "";
if (raw.charAt(0) === "#") return a.hash.length > 1;
return !!a.hash && a.pathname === location.pathname && a.search === location.search;
}
function flashDisabled() {
try {
var id = "__rcms-preview-toast";
if (document.getElementById(id) || !document.body) return;
var t = document.createElement("div");
t.id = id;
t.textContent = "Links are disabled in preview";
t.setAttribute("role", "status");
t.style.cssText =
"position:fixed;left:50%;bottom:16px;transform:translateX(-50%);" +
"z-index:2147483647;pointer-events:none;background:rgba(17,24,39,.92);" +
"color:#fff;font:500 13px/1.4 system-ui,-apple-system,sans-serif;" +
"padding:8px 14px;border-radius:8px;box-shadow:0 4px 16px rgba(0,0,0,.25);" +
"opacity:0;transition:opacity .15s ease";
document.body.appendChild(t);
requestAnimationFrame(function () { t.style.opacity = "1"; });
setTimeout(function () {
t.style.opacity = "0";
setTimeout(function () { t.remove(); }, 200);
}, 1500);
} catch (_) { }
}
function onActivate(e) {
var a = e.target && e.target.closest ? e.target.closest("a[href]") : null;
if (!a) return;
e.preventDefault();
e.stopPropagation();
if (sameDocHash(a)) {
var key = decodeURIComponent(a.hash.slice(1));
var target = null;
try {
target =
(key && document.getElementById(key)) ||
(key && document.querySelector(
'a[name="' + (window.CSS && CSS.escape ? CSS.escape(key) : key) + '"]'
));
} catch (_) { }
if (target) target.scrollIntoView({ behavior: "smooth", block: "start" });
return;
}
flashDisabled();
}
document.addEventListener("click", onActivate, true);
document.addEventListener("auxclick", onActivate, true);
document.addEventListener(
"submit",
function (e) { e.preventDefault(); e.stopPropagation(); },
true
);
})();