|
|
| Line 29: |
Line 29: |
|
| |
|
| mw.loader.using('mediawiki.user', function () { | | mw.loader.using('mediawiki.user', function () { |
| $(document).ready(function () { | | if (mw.user.isAnon()) { |
| if (mw.user.isAnon()) {
| | // Hide dismiss buttons for anonymous users |
| // Hide dismiss buttons for anonymous users
| | $('.user-only-dismiss').hide(); |
| $('.dismiss-button').hide();
| | return; |
| return;
| | } |
| }
| |
|
| |
|
| // Enable dismissible behavior for logged-in users
| | // Enable dismissible behavior for logged-in users |
| $('.maybe-dismissible').addClass('dismissible-notice');
| | $('.maybe-dismissible').addClass('dismissible-notice'); |
|
| |
|
| $('.dismissible-notice').each(function () {
| | $('.dismissible-notice .dismiss-button').click(function () { |
| let $notice = $(this);
| | $(this).closest('.dismissible-notice').hide(); |
| 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();
| |
| });
| |
| });
| |
| }); | | }); |
| }); | | }); |