MediaWiki:Common.js:修订间差异
MediaWiki界面页面
更多操作
添加提醒 |
搬些脚本 |
||
| 第7行: | 第7行: | ||
** [[MediaWiki:<皮肤名>.js]] — 作用于特定皮肤的Javascript。 | ** [[MediaWiki:<皮肤名>.js]] — 作用于特定皮肤的Javascript。 | ||
*/ | */ | ||
/* global mw, $ */ | |||
mw.loader.using( [ 'mediawiki.util' ] ).done( function () { | |||
/* Begin of mw.loader.using callback */ | |||
/** | |||
* Add support to mw-collapsible for autocollapse, innercollapse and outercollapse | |||
* Source: https://en.wikipedia.org/wiki/MediaWiki:Common.js | |||
* | |||
* @author TheDJ (Maintainer) | |||
*/ | |||
function mwCollapsibleSetup( $collapsibleContent ) { | |||
var $element, | |||
$toggle, | |||
autoCollapseThreshold = 2; | |||
$.each( $collapsibleContent, function ( index, element ) { | |||
$element = $( element ); | |||
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' ) ) { | |||
if ( $element.parents( '.outercollapse' ).length > 0 ) { | |||
$element.data( 'mw-collapsible' ).collapse(); | |||
} | |||
} | |||
// because of colored backgrounds, style the link in the text color | |||
// to ensure accessible contrast | |||
$toggle = $element.find( '.mw-collapsible-toggle' ); | |||
if ( $toggle.length ) { | |||
// Make the toggle inherit text color | |||
if ( $toggle.parent()[ 0 ].style.color ) { | |||
$toggle.find( 'a' ).css( 'color', 'inherit' ); | |||
} | |||
} | |||
} ); | |||
} | |||
mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup ); | |||
/* End of mw.loader.using callback */ | |||
} ); | |||
/* 不要在这行下面添加代码! */ | |||
2022年5月27日 (五) 21:25的版本
/*
* 全wiki通用Javascript
*
* 这里放置的Javascript将在用户使用桌面版每次载入页面时加载, 不分皮肤。
** [[MediaWiki:Gadget-site-javascript.js]] — 全站通用Javascript;
** [[MediaWiki:Mobile.js]] — 仅在移动版生效的Javascript;
** [[MediaWiki:<皮肤名>.js]] — 作用于特定皮肤的Javascript。
*/
/* global mw, $ */
mw.loader.using( [ 'mediawiki.util' ] ).done( function () {
/* Begin of mw.loader.using callback */
/**
* Add support to mw-collapsible for autocollapse, innercollapse and outercollapse
* Source: https://en.wikipedia.org/wiki/MediaWiki:Common.js
*
* @author TheDJ (Maintainer)
*/
function mwCollapsibleSetup( $collapsibleContent ) {
var $element,
$toggle,
autoCollapseThreshold = 2;
$.each( $collapsibleContent, function ( index, element ) {
$element = $( element );
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' ) ) {
if ( $element.parents( '.outercollapse' ).length > 0 ) {
$element.data( 'mw-collapsible' ).collapse();
}
}
// because of colored backgrounds, style the link in the text color
// to ensure accessible contrast
$toggle = $element.find( '.mw-collapsible-toggle' );
if ( $toggle.length ) {
// Make the toggle inherit text color
if ( $toggle.parent()[ 0 ].style.color ) {
$toggle.find( 'a' ).css( 'color', 'inherit' );
}
}
} );
}
mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup );
/* End of mw.loader.using callback */
} );
/* 不要在这行下面添加代码! */