MediaWiki:Common.js: Difference between revisions

From Bose Portable PA Knowledge
Jump to navigation Jump to search
mNo edit summary
m may need to roll back to if we break FAQList
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* MediaWiki:Common.js
  Global JS for the wiki.
  - Keeps FAQ expand/collapse handlers.
  - Adds reliable body classes (mw-user / mw-anonuser) so CSS can target logged-in vs anonymous users.
  - Lightweight and safe; fails silently if mw.user is unavailable.
*/


/* Expand/Collapse all for FAQList */
/* Expand/Collapse all for FAQList */
Line 16: Line 21:
});
});


 
/* Ensure body has mw-user or mw-anonuser so CSS can target logged-in vs anon reliably.
/* MediaWiki:Common.js - test if it's loading */
  Runs early via ResourceLoader. */
// alert("Common.js is running");
( function () {
    if ( typeof mw === 'undefined' || !mw.user ) return;
    try {
        if ( mw.user.isAnon() ) {
            document.body.classList.add( 'mw-anonuser' );
            document.body.classList.remove( 'mw-user' );
        } else {
            document.body.classList.add( 'mw-user' );
            document.body.classList.remove( 'mw-anonuser' );
        }
    } catch ( e ) {
        if ( window.console && console.warn ) console.warn( 'Common.js body class helper failed', e );
    }
}() );

Revision as of 15:58, 2 April 2026

/* MediaWiki:Common.js
   Global JS for the wiki.
   - Keeps FAQ expand/collapse handlers.
   - Adds reliable body classes (mw-user / mw-anonuser) so CSS can target logged-in vs anonymous users.
   - Lightweight and safe; fails silently if mw.user is unavailable.
*/

/* Expand/Collapse all for FAQList */
mw.hook('wikipage.content').add(function ($content) {

    // Expand all
    $content.on('click', '.faq-expand-all', function () {
        $('.faq-list details').attr('open', true);
    });

    // Collapse all
    $content.on('click', '.faq-collapse-all', function () {
        $('.faq-list details').removeAttr('open');
    });

});

/* Ensure body has mw-user or mw-anonuser so CSS can target logged-in vs anon reliably.
   Runs early via ResourceLoader. */
( function () {
    if ( typeof mw === 'undefined' || !mw.user ) return;
    try {
        if ( mw.user.isAnon() ) {
            document.body.classList.add( 'mw-anonuser' );
            document.body.classList.remove( 'mw-user' );
        } else {
            document.body.classList.add( 'mw-user' );
            document.body.classList.remove( 'mw-anonuser' );
        }
    } catch ( e ) {
        if ( window.console && console.warn ) console.warn( 'Common.js body class helper failed', e );
    }
}() );