Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Template:18PlusDisclaimer: Difference between revisions

Template page
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 match = document.cookie.match(new RegExp('(?:^|; )' + name + '=([^;]*)'));
       const nameEq = name + "=";
       return match ? decodeURIComponent(match[1]) : null;
      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 overlay if not yet confirmed
       // 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() {
         // redirect to Main_Page via mw.config
         // 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;
       });
       });


       // keep focus inside popup
       // 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

Advertising: