Template:18PlusDisclaimer: Difference between revisions
Template page
More actions
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
<templatestyles src="Template:18PlusDisclaimer/styles.css" /> | <templatestyles src="Template:18PlusDisclaimer/styles.css" /> | ||
<!-- the overlay itself --> | |||
{{#tag:html| | {{#tag:html| | ||
<div id="ageDisclaimerOverlay" class="age-overlay" style="display:none"> | <div id="ageDisclaimerOverlay" class="age-overlay" style="display:none"> | ||
<div class="age-blur"></div> | |||
<div class="age-popup slide-down"> | |||
<h2>You must be 18+ to view this content</h2> | |||
<p>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">I am 18 or older</button> | |||
<button id="declineDisclaimer">Leave this page</button> | |||
</div> | |||
</div> | </div> | ||
</div> | </div> | ||
}} | |||
<script | <!-- the behavior, loaded safely as JS --> | ||
{{#tag:script| | |||
(function($, mw) { | (function($, mw) { | ||
// once mw.user and mw.util are available… | |||
mw.loader.using(['mediawiki.user', 'mediawiki.util']). | mw.loader.using(['mediawiki.user', 'mediawiki.util']).then(function() { | ||
var overlay = $('#ageDisclaimerOverlay'), | |||
popup = overlay.find('.age-popup'), | |||
isAnon = mw.user.isAnon(), | |||
cookieConfirmed = document.cookie.split('; ').some(function(c){ return c.trim()==='ageConfirmed=true'; }); | |||
// | // show to everyone on first visit, and force-show again for logged‑in users | ||
if (!cookieConfirmed || !isAnon) { | if (!cookieConfirmed || !isAnon) { | ||
overlay.css('display','flex'); | |||
overlay.css('display', 'flex'); | $('body').css('overflow','hidden'); | ||
$('body').css('overflow', 'hidden'); | // trigger slide‑in | ||
// trigger | requestAnimationFrame(function(){ popup.addClass('slide-active'); }); | ||
} | } | ||
$('#acceptDisclaimer').on('click', function() { | $('#acceptDisclaimer').on('click', function() { | ||
// set 30‑day cookie | |||
document.cookie = | document.cookie = 'ageConfirmed=true;max-age=' + (30*24*60*60) + ';path=/'; | ||
overlay.hide(); | overlay.hide(); | ||
$('body').css('overflow', ''); | $('body').css('overflow',''); | ||
}); | }); | ||
$('#declineDisclaimer').on('click', function() { | $('#declineDisclaimer').on('click', function() { | ||
window.location.href = mw.util.getUrl('Main_Page'); | window.location.href = mw.util.getUrl('Main_Page'); | ||
}); | }); | ||
}); | }); | ||
})(jQuery, mw); | })(jQuery, mw); | ||
| type="text/javascript" }} | |||
}} | |||
Revision as of 11:05, 19 April 2025
<script !isAnon) {
overlay.css('display','flex');
$('body').css('overflow','hidden');
// trigger slide‑in
requestAnimationFrame(function(){ popup.addClass('slide-active'); });
}
$('#acceptDisclaimer').on('click', function() {
// set 30‑day cookie
document.cookie="'ageConfirmed=true;max-age=' + (30*24*60*60) + ';path=/';
overlay.hide();
$('body').css('overflow',);
});
$('#declineDisclaimer').on('click', function() {
window.location.href = mw.util.getUrl('Main_Page');
});
});
})(jQuery, mw);" type="text/javascript">
(function($, mw) {
// once mw.user and mw.util are available…
mw.loader.using(['mediawiki.user', 'mediawiki.util']).then(function() {
var overlay = $('#ageDisclaimerOverlay'),
popup = overlay.find('.age-popup'),
isAnon = mw.user.isAnon(),
cookieConfirmed = document.cookie.split('; ').some(function(c){ return c.trim()==='ageConfirmed=true'; });
// show to everyone on first visit, and force-show again for logged‑in users
if (!cookieConfirmed </script>