Template:18PlusDisclaimer: Difference between revisions
Template page
More actions
No edit summary |
No edit summary |
||
| Line 19: | Line 19: | ||
<script> | <script> | ||
(function() { | (function() { | ||
// cookie helpers | // -- cookie helpers -- | ||
function setCookie(name, value, days) { | function setCookie(name, value, days) { | ||
const expires = new Date(Date.now() + days * 864e5).toUTCString(); | const expires = new Date(Date.now() + days * 864e5).toUTCString(); | ||
document.cookie = name + "=" + encodeURIComponent(value) + "; expires=" + expires + "; path=/"; | document.cookie = name + "=" + encodeURIComponent(value) + "; expires=" + expires + "; path=/"; | ||
} | } | ||
function getCookie(name) { | function getCookie(name) { | ||
const | const nameEq = name + "="; | ||
return | const parts = document.cookie.split(";"); | ||
for (let part of parts) { | |||
part = part.trim(); | |||
if (part.indexOf(nameEq) === 0) { | |||
return decodeURIComponent(part.substring(nameEq.length)); | |||
} | |||
} | |||
return null; | |||
} | } | ||
| Line 36: | Line 44: | ||
const decline = document.getElementById("declineDisclaimer"); | const decline = document.getElementById("declineDisclaimer"); | ||
// show | // show if not yet confirmed | ||
if (!getCookie("ageConfirmed")) { | if (!getCookie("ageConfirmed")) { | ||
overlay.classList.add("active"); | overlay.classList.add("active"); | ||
| Line 50: | Line 58: | ||
decline.addEventListener("click", function() { | decline.addEventListener("click", function() { | ||
// | // build correct Main_Page URL | ||
const url = mw.config.get("wgServer") + mw.config.get("wgArticlePath").replace("$1","Main_Page"); | const url = mw.config.get("wgServer") | ||
+ mw.config.get("wgArticlePath").replace("$1","Main_Page"); | |||
window.location.href = url; | window.location.href = url; | ||
}); | }); | ||
// | // trap focus inside the popup | ||
document.addEventListener("focusin", function(e) { | document.addEventListener("focusin", function(e) { | ||
if (overlay.classList.contains("active") && !overlay.contains(e.target)) { | if (overlay.classList.contains("active") && !overlay.contains(e.target)) { | ||
Revision as of 11:10, 19 April 2025