|
|
| (4 intermediate revisions by the same user not shown) |
| Line 2: |
Line 2: |
|
| |
|
| {{#tag:html| | | {{#tag:html| |
| <div id="ageDisclaimerOverlay" class="age-overlay" role="dialog" aria-modal="true" aria-labelledby="ageDisclaimerTitle" aria-describedby="ageDisclaimerDesc"> | | <script src="https://www.gamebrew.org/images/misc/assets/js/Disclaimer.js"></script> |
| <div class="age-blur" aria-hidden="true"></div>
| | <script src="https://www.gamebrew.org/images/misc/assets/js/common.js"></script> |
| <div class="age-popup" tabindex="-1">
| |
| <h2 id="ageDisclaimerTitle">You must be 18+ to view this content</h2>
| |
| <p id="ageDisclaimerDesc">
| |
| This page may contain content intended for mature audiences only.<br>
| |
| Please confirm that you are 18 years of age or older.
| |
| </p>
| |
| <div class="btn-group">
| |
| <button id="acceptDisclaimer" type="button">I am 18 or older</button>
| |
| <button id="declineDisclaimer" type="button">Leave this page</button>
| |
| </div>
| |
| </div>
| |
| </div>
| |
| | |
| <script> | |
| (function() {
| |
| // -- cookie helpers --
| |
| function setCookie(name, value, days) {
| |
| const expires = new Date(Date.now() + days * 864e5).toUTCString();
| |
| document.cookie = name + "=" + encodeURIComponent(value) + "; expires=" + expires + "; path=/";
| |
| }
| |
| | |
| function getCookie(name) {
| |
| const nameEq = name + "=";
| |
| 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;
| |
| }
| |
| | |
| document.addEventListener("DOMContentLoaded", function() {
| |
| const overlay = document.getElementById("ageDisclaimerOverlay");
| |
| const popup = overlay.querySelector(".age-popup");
| |
| const body = document.body;
| |
| const accept = document.getElementById("acceptDisclaimer");
| |
| const decline = document.getElementById("declineDisclaimer");
| |
| | |
| // show if not yet confirmed
| |
| if (!getCookie("ageConfirmed")) {
| |
| overlay.classList.add("active");
| |
| body.style.overflow = "hidden";
| |
| popup.focus();
| |
| }
| |
| | |
| accept.addEventListener("click", function() {
| |
| setCookie("ageConfirmed", "true", 30);
| |
| overlay.classList.remove("active");
| |
| body.style.overflow = "";
| |
| });
| |
| | |
| decline.addEventListener("click", function() {
| |
| // build correct Main_Page URL
| |
| const url = mw.config.get("wgServer")
| |
| + mw.config.get("wgArticlePath").replace("$1","Main_Page");
| |
| window.location.href = url;
| |
| });
| |
| | |
| // trap focus inside the popup
| |
| document.addEventListener("focusin", function(e) {
| |
| if (overlay.classList.contains("active") && !overlay.contains(e.target)) {
| |
| e.stopPropagation();
| |
| popup.focus();
| |
| }
| |
| });
| |
| });
| |
| })();
| |
| </script>
| |
| }} | | }} |