MediaWiki:Gadget-MainLangFirst.js
Jump to navigation
Jump to search
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.
/* global mw, $ */
( function () {
'use strict';
var langMap, langs;
if ( mw.config.get( 'wgNamespaceNumber' ) !== 0 ) {
return;
}
langMap = {
'bho': 'bh',
'gsw': 'als',
'lzh': 'zh_classical',
'nan': 'zh_min_nan',
'nb': 'no',
'rup': 'roa_rup',
'sgs': 'bat_smg',
'vro': 'fiu_vro',
'yue': 'zh_yue',
};
langs = mw.user.options.get( 'translate-editlangs' ).split( ', ' );
langs.push( mw.config.get( 'wgUserLanguage' ) );
langs = langs.map( function ( lang ) {
return langMap[ lang ] || lang;
} );
function highlightSiteLinks( $content ) {
function highlightSiteLinksGroup( group, customSuffix ) {
var selector,
suffix = customSuffix || group,
$group = $content.find( 'div[data-wb-sitelinks-group="' + group + '"]' );
// Highlight main languages
selector = langs.map( function ( code ) {
return '.wikibase-sitelinkview-' + code + suffix;
} ).join( ',' );
$group.find( selector )
.prependTo( $group.find( 'ul' ).eq( 0 ) )
.addClass( 'main-lang-highlight' );
}
highlightSiteLinksGroup( 'wikipedia', 'wiki' );
highlightSiteLinksGroup( 'wikibooks' );
highlightSiteLinksGroup( 'wikinews' );
highlightSiteLinksGroup( 'wikiquote' );
highlightSiteLinksGroup( 'wikisource' );
highlightSiteLinksGroup( 'wikiversity' );
highlightSiteLinksGroup( 'wikivoyage' );
highlightSiteLinksGroup( 'wiktionary' );
}
mw.hook( 'wikipage.content' ).add( highlightSiteLinks );
}() );