Jump to content

MediaWiki:Common.js: Difference between revisions

From Gyaanipedia
No edit summary
Tags: Manual revert Mobile edit Mobile web edit
No edit summary
Tags: Reverted Mobile edit Mobile web edit
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */
/* Dismiss Site Notice Function */
function dismissSiteNotice() {
    var notice = document.getElementById( 'customSiteNotice' );
   
    if ( notice ) {
        notice.style.display = 'none';
       
        // Use localStorage to remember the dismissal state
        // The value '1' means 'dismissed'.
        localStorage.setItem( 'customSiteNoticeDismissed', '1' );
        // 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
        var content = document.getElementById( 'mw-body' ) || document.getElementById( 'content' );
        if ( content ) {
            content.style.marginTop = '0';
        }
    }
}
// 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:49, 6 December 2025

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


/* Dismiss Site Notice Function */
function dismissSiteNotice() {
    var notice = document.getElementById( 'customSiteNotice' );
    
    if ( notice ) {
        notice.style.display = 'none';
        
        // Use localStorage to remember the dismissal state
        // The value '1' means 'dismissed'.
        localStorage.setItem( 'customSiteNoticeDismissed', '1' );

        // 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
        var content = document.getElementById( 'mw-body' ) || document.getElementById( 'content' );
        if ( content ) {
            content.style.marginTop = '0';
        }
    }
}

// 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. 
 */