MediaWiki:Common.js: Difference between revisions
From HUIJIA FUN
PlurimodSU (talk | contribs) Created page with "→All the codes under are from https://otomad.wiki/MediaWiki:Common.js: console.log("\n%c _____ ______ _____ ___ __ ______ ____ %c__ __ ______ __ __ ______ \n%c/\\ __ \\/\\__ _\\/\\ __ \\ \\ \\_\\ \\/\\ _ \\/\\ _ \\ %c/\\ \\ __/\\ \\/\\__ _\\ /\\ \\/\\ \\ /\\__ _\\ \n%c\\ \\ \\/\\ \\/_/\\ \\/\\ \\ \\/\\ \\/\\ \\ \\ \\/\\ \\ \\ \\/\\ \\ %c\\ \\/\\ \\ \\ \\/_/\\ \\/ \\ \\ \\/ /\\/_/\\ \\/ \n%c \\ \\ \\ \\ \\ \\ \\ \\ \\ \\..." |
PlurimodSU (talk | contribs) New System |
||
| Line 1: | Line 1: | ||
/** | /** | ||
* | * 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, $ */ | /* global mw, $ */ | ||
mw.loader.using( [ 'mediawiki.util' ] ).done( function () { | |||
// 1. class="collapsible" -> mw-collapsible | |||
/ | |||
function makeCollapsibleMwCollapsible( $content ) { | function makeCollapsibleMwCollapsible( $content ) { | ||
var $tables = $content | var $tables = $content | ||
| Line 41: | Line 19: | ||
.addClass( 'mw-collapsible' ); | .addClass( 'mw-collapsible' ); | ||
$.each( | $tables.each( function () { | ||
if ( $( this ).hasClass( 'collapsed' ) ) { | |||
if ( $( | $( this ).addClass( 'mw-collapsed' ); | ||
$( | |||
} | } | ||
} ); | } ); | ||
if ( $tables.length | if ( $tables.length ) { | ||
mw.loader.using( 'jquery.makeCollapsible' ).then( function () { | mw.loader.using( 'jquery.makeCollapsible' ).then( function () { | ||
$tables.makeCollapsible(); | $tables.makeCollapsible(); | ||
| Line 56: | Line 32: | ||
mw.hook( 'wikipage.content' ).add( makeCollapsibleMwCollapsible ); | mw.hook( 'wikipage.content' ).add( makeCollapsibleMwCollapsible ); | ||
/ | // 2. autocollapse (collapse when a page has two or more) and innercollapse (collapse inside outercollapse) | ||
function mwCollapsibleSetup( $collapsibleContent ) { | function mwCollapsibleSetup( $collapsibleContent ) { | ||
var | var autoCollapseThreshold = 2; | ||
$collapsibleContent.each( function () { | |||
var $element = $( this ), | |||
$.each( | $toggle; | ||
$element = $( | |||
if ( $element.hasClass( 'collapsible' ) ) { | if ( $element.hasClass( 'collapsible' ) ) { | ||
$element.find( 'tr:first > th:first' ).prepend( $element.find( 'tr:first > * > .mw-collapsible-toggle' ) ); | $element.find( 'tr:first > th:first' ).prepend( $element.find( 'tr:first > * > .mw-collapsible-toggle' ) ); | ||
| Line 72: | Line 43: | ||
if ( $collapsibleContent.length >= autoCollapseThreshold && $element.hasClass( 'autocollapse' ) ) { | if ( $collapsibleContent.length >= autoCollapseThreshold && $element.hasClass( 'autocollapse' ) ) { | ||
$element.data( 'mw-collapsible' ).collapse(); | $element.data( 'mw-collapsible' ).collapse(); | ||
} else if ( $element.hasClass( 'innercollapse' ) | } 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' ); | $toggle = $element.find( '.mw-collapsible-toggle' ); | ||
if ( $toggle.length | if ( $toggle.length && $toggle.parent()[ 0 ].style.color ) { | ||
$toggle.find( 'a' ).css( 'color', 'inherit' ); | |||
} | } | ||
} ); | } ); | ||
} | } | ||
mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup ); | mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup ); | ||
} ); | } ); | ||
/* DO NOT ADD CODE BELOW THIS LINE */ | /* DO NOT ADD CODE BELOW THIS LINE */ | ||
Revision as of 16:22, 9 October 2026
/**
* 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 */
