MediaWiki:Common.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
/* Switch Infobox -- Allows multiple infoboxes to be seamlessly switched.
*/
// Fixes a weird bug with the MW parser that adds lots of empty parapgraphs
$( '.switch-infobox > p, .switch-infobox-triggers > p' ).each( function() {
if ( $( this ).children( 'br' ).length ) {
$( this ).remove();
} else {
$( this ).replaceWith( this.innerHTML );
}
} );
// Appends the switch triggers to every item
$( '.switch-infobox' ).each( function() {
// The switch triggers
var triggers = $( this ).children( '.switch-infobox-triggers' );
$( this ).children( '.item' ).find( 'caption' ).append( triggers );
} );
// Does the actual switching
$( '.switch-infobox' ).find( '.switch-infobox-triggers' ).children( '.trigger' ).click( function() {
// The parent .switch-infobox of the clicked trigger
var parentSwitchInfobox = $( this ).parents( '.switch-infobox' );
// Hides items showing
parentSwitchInfobox.children( '.item.showing' ).removeClass( 'showing' );
// Show the relevant item
parentSwitchInfobox.children( '.item[data-id="' + this.getAttribute( 'data-id' ) + '"]' ).addClass( 'showing' );
} );
// Finishes loading and makes switch infoboxes functional
$( '.switch-infobox.loading' ).removeClass( 'loading' );
//Debug
console.log('Initialised switch infoboxes', $( '.switch-infobox' ).length);