Template:18PlusDisclaimer: Difference between revisions
Template page
More actions
No edit summary |
No edit summary |
||
| Line 2: | Line 2: | ||
{{#tag:html| | {{#tag:html| | ||
<div id="ageDisclaimerOverlay" class="age-overlay"> | <div id="ageDisclaimerOverlay" class="age-overlay" style="display:none"> | ||
<div class="age-blur"></div> | <div class="age-blur"></div> | ||
<div class="age-popup slide-down"> | <div class="age-popup slide-down"> | ||
| Line 15: | Line 15: | ||
<script> | <script> | ||
// Load the MediaWiki user module so we can tell if someone is logged in | |||
mw.loader.using(['mediawiki.user', 'mediawiki.util']).then(function () { | |||
const overlay = document.getElementById("ageDisclaimerOverlay"); | |||
const body = document.body; | |||
const isLoggedIn = !mw.user.isAnon(); | |||
const cookieConfirmed = document.cookie | |||
.split('; ') | |||
.some(part => part.trim() === 'ageConfirmed=true'); | |||
function showOverlay() { | |||
overlay.style.display = 'flex'; | |||
body.style.overflow = 'hidden'; | |||
requestAnimationFrame(()=>{ | |||
overlay.querySelector(".age-popup").classList.add("slide-active"); | |||
}); | |||
} | |||
function hideOverlay() { | |||
overlay.style.display = 'none'; | |||
body.style.overflow = ''; | |||
} | } | ||
// Show to everyone on first visit (no cookie), | |||
// and even if they have a cookie, force-show again for logged-in users | |||
if (!cookieConfirmed || isLoggedIn) { | |||
showOverlay(); | |||
} | } | ||
document.addEventListener(" | document.getElementById("acceptDisclaimer").addEventListener("click", function () { | ||
// set 30‑day cookie | |||
document.cookie = "ageConfirmed=true;max-age=" + (30*24*60*60) + ";path=/"; | |||
hideOverlay(); | |||
}); | |||
document.getElementById("declineDisclaimer").addEventListener("click", function () { | |||
// send them back to Main Page; you can change this target | |||
window.location.href = mw.util.getUrl('Main_Page'); | |||
}); | }); | ||
}); | |||
</script> | </script> | ||
}} | }} | ||
Revision as of 10:50, 19 April 2025