MediaWiki:Common.js: Difference between revisions
mNo edit summary |
mNo edit summary Tag: Reverted |
||
| Line 29: | Line 29: | ||
mw.loader.using('mediawiki.user', function () { | mw.loader.using('mediawiki.user', function () { | ||
if (mw.user.isAnon()) { | $(document).ready(function () { | ||
if (mw.user.isAnon()) { | |||
// Hide dismiss buttons for anonymous users | |||
$('.dismiss-button').hide(); | |||
return; | |||
} | |||
// Enable dismissible behavior for logged-in users | |||
$('.maybe-dismissible').addClass('dismissible-notice'); | |||
$('.dismissible-notice').each(function () { | |||
let $notice = $(this); | |||
let dataId = $notice.data('id'); | |||
// Generate fallback ID based on page and content if not provided | |||
if (!dataId) { | |||
const page = mw.config.get('wgPageName'); | |||
const content = $notice.text().trim().replace(/\s+/g, ' ').slice(0, 100); | |||
dataId = page + '-' + content; | |||
$notice.attr('data-id', dataId); | |||
} | |||
// Check localStorage for dismissal | |||
if (localStorage.getItem('dismissed-' + dataId)) { | |||
$notice.hide(); | |||
} | |||
// Set up dismiss button | |||
$notice.find('.dismiss-button').click(function () { | |||
localStorage.setItem('dismissed-' + dataId, '1'); | |||
$notice.hide(); | |||
}); | |||
}); | |||
}); | }); | ||
}); | }); | ||