MediaWiki:Gadget-allLangs.js
跳转到导航
跳转到搜索
- 其他语言中
注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的更改的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Internet Explorer:按住Ctrl的同时单击刷新,或按Ctrl-F5
- Opera:前往菜单 → 设置(Mac为Opera → 选项),然后隐私和安全 → 清除浏览数据 → 缓存的图片和文件。
mw.loader.using( [
'mediawiki.util',
'mcw.messages',
'ext.gadget.global-utils'
] ).then( function( require ) {
var pagename = '';
const config = mw.config.get([
'wgNamespaceNumber',
'wgCanonicalNamespace',
'wgCanonicalSpecialPageName',
'wgTitle',
'wgServer'
]);
if ( [8, 9].includes(config.wgNamespaceNumber)) { // MediaWiki, Talk
pagename = config.wgCanonicalNamespace + ':' + config.wgTitle;
}
else if ( config.wgNamespaceNumber === -1 ) { // Special
pagename = config.wgCanonicalNamespace + ':' + config.wgCanonicalSpecialPageName;
const subpageIdx = config.wgTitle.indexOf( '/' );
if ( subpageIdx >= 0 )
pagename = pagename + config.wgTitle.substring( subpageIdx );
}
if ( !pagename.length || $('#p-lang').length ) return;
var pagepath = mw.util.getUrl(pagename);
const wikis = require( 'ext.gadget.global-utils' ).wikiList.filter( wiki => wiki.url !== config.wgServer );
var langCollapsed = (localStorage.getItem("sidebar_vector_c_p-lang") === "y");
$('<nav id="p-lang" class="vector-menu mw-portlet mw-portlet-lang vector-menu-portal portal" aria-labelledby="p-lang-label" role="navigation">').append(
$('<h3 id="p-lang-label" class="vector-menu-heading" tabindex="0">').append(
$('<span class="vector-menu-heading-label">').text(mw.msg('otherlanguages'))
).on("keypress", function(event) {
if (event.which == 13) {
$(this).trigger("click");
event.stopImmediatePropagation();
}
}).on("click", function(event) {
var $el = $(this).parent();
event.stopPropagation();
$el.toggleClass("collapsed");
if($el.hasClass("collapsed")){
localStorage.setItem("sidebar_vector_c_p-lang", "y");
$el.find(".vector-menu-content").slideUp("fast");
}
else{
localStorage.setItem("sidebar_vector_c_p-lang", "n");
$el.find(".vector-menu-content").slideDown("fast");
}
}),
$('<div class="vector-menu-content">').append(
$('<ul class="vector-menu-content-list">')
).css('display', langCollapsed ? 'none' : '')
).addClass(langCollapsed ? 'collapsed' : '').insertAfter('#p-tb');
for (const wiki of wikis) {
$(mw.util.addPortletLink('p-lang', wiki.url + pagepath, wiki.name ))
.addClass('interlanguage-link interwiki-' + wiki.id)
.find('a').addClass('interlanguage-link-target')
.attr('title', pagename + ' – ' + wiki.name)
.attr('lang', wiki.id).attr('hreflang', wiki.id);
}
} );