MediaWiki:Common.js
MediaWiki interface page
More actions
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.
/* Make level-3 headings (=== ... ===) collapsible like the skin's level-2 sections.
* Reuses Citizen's own classes, so its click handler and styles do the rest. */
mw.hook( 'wikipage.content' ).add( function ( $content ) {
if ( !document.body.classList.contains( 'citizen-sections-enabled' ) ) {
return;
}
$content.find( '.citizen-section > .mw-heading3' ).each( function () {
var heading = this;
if ( heading.classList.contains( 'citizen-section-heading' ) ) {
return;
}
var body = document.createElement( 'div' );
body.className = 'citizen-section';
var next = heading.nextElementSibling;
while ( next && !next.matches( '.mw-heading2, .mw-heading3' ) ) {
var after = next.nextElementSibling;
body.appendChild( next );
next = after;
}
heading.after( body );
heading.classList.add( 'citizen-section-heading' );
var icon = document.createElement( 'span' );
icon.className = 'citizen-section-indicator citizen-ui-icon mw-ui-icon-wikimedia-collapse';
heading.prepend( icon );
} );
} );