Jump to content

MediaWiki:Common.js: Difference between revisions

From Gyaanipedia
No edit summary
Tags: Reverted Mobile edit Mobile web edit
No edit summary
Tags: Reverted Mobile edit Mobile web edit
Line 2: Line 2:




/* Dismiss Site Notice Function */
// Add dismiss button to sitenotice
function dismissSiteNotice() {
$(function() {
     var notice = document.getElementById( 'customSiteNotice' );
     if ($('#siteNotice').length) {
   
        var cookieName = 'dismissSiteNotice';
    if ( notice ) {
        var cookieValue = $('#siteNotice').attr('data-notice-id') || 'sitenotice';
        notice.style.display = 'none';
          
          
         // Use localStorage to remember the dismissal state
         // Check if already dismissed
        // The value '1' means 'dismissed'.
         if ($.cookie(cookieName) === cookieValue) {
         localStorage.setItem( 'customSiteNoticeDismissed', '1' );
            $('#siteNotice').hide();
 
             return;
        // You also need to adjust the page content margin back up
        var content = document.getElementById( 'mw-body' ) || document.getElementById( 'content' );
        if ( content ) {
            // Remove the 40px margin added by the CSS
             content.style.marginTop = '0';
         }
         }
    }
}
// Function to check if the notice should be shown on page load
function checkSiteNoticeDismissal() {
    // 1. Get the dismissal state from localStorage
    var isDismissed = localStorage.getItem( 'customSiteNoticeDismissed' );
   
    // 2. Get the notice element
    var notice = document.getElementById( 'customSiteNotice' );
   
    // 3. Hide the notice if it was dismissed
    if ( isDismissed === '1' && notice ) {
        notice.style.display = 'none';
          
          
         // Also remove the page content margin
         // Add dismiss button
         var content = document.getElementById( 'mw-body' ) || document.getElementById( 'content' );
         var dismissBtn = $('<span class="sitenotice-dismiss">[dismiss]</span>');
         if ( content ) {
        dismissBtn.css({
             content.style.marginTop = '0';
            'cursor': 'pointer',
         }
            'float': 'right',
            'font-size': '90%',
            'margin-left': '1em'
        });
          
        dismissBtn.click(function() {
             $('#siteNotice').slideUp();
            $.cookie(cookieName, cookieValue, { expires: 30, path: '/' });
         });
       
        $('#siteNotice').prepend(dismissBtn);
     }
     }
}
});
 
// Run the check when the page is ready
$( checkSiteNoticeDismissal );
 
/* * NOTE ON RESETTING:
* To make the notice appear again for ALL users (even those who dismissed it),
* you MUST change the name of the localStorage key (e.g., from
* 'customSiteNoticeDismissed' to 'customSiteNoticeDismissedV2') in this .js file.
*/

Revision as of 10:54, 6 December 2025

/* Any JavaScript here will be loaded for all users on every page load. */


// Add dismiss button to sitenotice
$(function() {
    if ($('#siteNotice').length) {
        var cookieName = 'dismissSiteNotice';
        var cookieValue = $('#siteNotice').attr('data-notice-id') || 'sitenotice';
        
        // Check if already dismissed
        if ($.cookie(cookieName) === cookieValue) {
            $('#siteNotice').hide();
            return;
        }
        
        // Add dismiss button
        var dismissBtn = $('<span class="sitenotice-dismiss">[dismiss]</span>');
        dismissBtn.css({
            'cursor': 'pointer',
            'float': 'right',
            'font-size': '90%',
            'margin-left': '1em'
        });
        
        dismissBtn.click(function() {
            $('#siteNotice').slideUp();
            $.cookie(cookieName, cookieValue, { expires: 30, path: '/' });
        });
        
        $('#siteNotice').prepend(dismissBtn);
    }
});