MediaWiki:Common.js

From HUIJIA FUN
Revision as of 16:22, 9 October 2026 by PlurimodSU (talk | contribs) (New System)

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.
/**
 * HUIJIA FUN (EN) - MediaWiki:Common.js - v2
 * Loaded on every page, so only the two parts actually in use are kept:
 *   1. Tables using the old class="collapsible" -> MediaWiki's built-in mw-collapsible
 *   2. autocollapse / innercollapse support for mw-collapsible
 * Removed:
 *   - the console banner printed on every page load (it carried another wiki's name);
 *   - the NavFrame toggle function (only the function was defined, nothing ever created
 *     the toggle buttons, so it never ran).
 * Adapted from en.wikipedia.org MediaWiki:Common.js (CC BY-SA).
 */
/* global mw, $ */
mw.loader.using( [ 'mediawiki.util' ] ).done( function () {

	// 1. class="collapsible" -> mw-collapsible
	function makeCollapsibleMwCollapsible( $content ) {
		var $tables = $content
			.find( 'table.collapsible:not(.mw-collapsible)' )
			.addClass( 'mw-collapsible' );

		$tables.each( function () {
			if ( $( this ).hasClass( 'collapsed' ) ) {
				$( this ).addClass( 'mw-collapsed' );
			}
		} );
		if ( $tables.length ) {
			mw.loader.using( 'jquery.makeCollapsible' ).then( function () {
				$tables.makeCollapsible();
			} );
		}
	}
	mw.hook( 'wikipage.content' ).add( makeCollapsibleMwCollapsible );

	// 2. autocollapse (collapse when a page has two or more) and innercollapse (collapse inside outercollapse)
	function mwCollapsibleSetup( $collapsibleContent ) {
		var autoCollapseThreshold = 2;
		$collapsibleContent.each( function () {
			var $element = $( this ),
				$toggle;
			if ( $element.hasClass( 'collapsible' ) ) {
				$element.find( 'tr:first > th:first' ).prepend( $element.find( 'tr:first > * > .mw-collapsible-toggle' ) );
			}
			if ( $collapsibleContent.length >= autoCollapseThreshold && $element.hasClass( 'autocollapse' ) ) {
				$element.data( 'mw-collapsible' ).collapse();
			} else if ( $element.hasClass( 'innercollapse' ) && $element.parents( '.outercollapse' ).length ) {
				$element.data( 'mw-collapsible' ).collapse();
			}
			// On colored header backgrounds, the toggle link takes the text color to keep contrast
			$toggle = $element.find( '.mw-collapsible-toggle' );
			if ( $toggle.length && $toggle.parent()[ 0 ].style.color ) {
				$toggle.find( 'a' ).css( 'color', 'inherit' );
			}
		} );
	}
	mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup );
} );
/* DO NOT ADD CODE BELOW THIS LINE */