MediaWiki:Common.js: Difference between revisions

No edit summary
No edit summary
 
Line 1: Line 1:
/* ICE List – Anon donate banner (safe + scoped)
* - ONLY runs for anonymous users
* - ONLY styles when Anonnotice has content
* - Adds a close (×) button
* - Remembers dismissal in localStorage
*/
(function () {
(function () {
   'use strict';
   'use strict';
Line 20: Line 14:
     if (!siteNotice) return;
     if (!siteNotice) return;


    // If empty, do nothing
     var txt = (siteNotice.textContent || '').replace(/\s+/g, ' ').trim();
     var txt = (siteNotice.textContent || '').replace(/\s+/g, ' ').trim();
     if (!txt) return;
     if (!txt) return;


     siteNotice.classList.add('icelist-anon-donate');
     siteNotice.classList.add('icelist-anon-donate');
    // Donate link hook (optional) + fallback
    var donateLink = siteNotice.querySelector('.icelist-donate-cta a')
      || siteNotice.querySelector('a[href*="ICE_List_Wiki:Donate"]');
    if (donateLink) donateLink.classList.add('icelist-donate-btn');


     // Add close button once
     // Add close button once
Line 37: Line 27:
       btn.setAttribute('aria-label', 'Close');
       btn.setAttribute('aria-label', 'Close');
       btn.textContent = '×';
       btn.textContent = '×';
      // put it at the top so it can't get shoved off-screen by table layout
       siteNotice.insertBefore(btn, siteNotice.firstChild);
       siteNotice.insertBefore(btn, siteNotice.firstChild);


       btn.addEventListener('click', function (e) {
       btn.addEventListener('click', function (e) {
         e.preventDefault();
         e.preventDefault();
        e.stopPropagation();
         siteNotice.style.display = 'none';
         siteNotice.style.display = 'none';
         localStorage.setItem(KEY, String(Date.now() + DAYS * 24 * 60 * 60 * 1000));
         localStorage.setItem(KEY, String(Date.now() + DAYS * 24 * 60 * 60 * 1000));
Line 50: Line 37:
   }
   }


   // run when page content is ready (MW-safe)
   if (document.readyState === 'loading') {
  mw.hook('wikipage.content').add(mount);
    document.addEventListener('DOMContentLoaded', mount);
  } else {
    mount();
  }
})();
})();