མི་ཌི་ཡ་ཝི་ཀི།:Vector.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.
/* All JavaScript here will be loaded for users of the Vector skin */
$( () => {
// List of portlets that are default-collapsed for logged out users
const defaultCollapsedPortlets = {
de: [ 'p-tb', 'Wiki-Gemeinschaft' ],
minecraft: [ 'p-tb', 'p-Wiki_community' ], // en
es: [ 'p-tb', 'p-Comunidad_wiki' ],
fr: [ 'p-tb', 'p-Communauté' ],
he: [ 'p-tb' ],
it: [ 'p-tb', 'p-Comunità_del_wiki' ],
ja: [ 'p-tb', 'p-Wikiコミュニティ' ],
ko: [ 'p-tb', 'p-위키_커뮤니티' ],
lzh: [ 'p-tb' ],
nl: [ 'p-tb', 'p-Wikigemeenschap' ],
pt: [ 'p-tb', 'p-Minecraft_Wiki', 'p-Links_do_Minecraft' ],
ru: [ 'p-tb', 'p-community-links' ],
th: [ 'p-tb', 'p-ชุมชนวิกิ' ],
uk: [ 'p-tb', 'p-Спільнота_вікі' ],
zh: [ 'p-tb', 'p-sidebar-community' ],
meta: []
};
const wiki = mw.config.get('wgServerName').split('.')[0];
mw.hook( 'mcw.makeSidebarPortletCollapsible' ).add( portlet => {
const $portlet = $( portlet );
if ( !$portlet.length || !$portlet.attr( 'id' ) ) {
console.error( 'mcw.makeSidebarPortletCollapsible encountered unexpected argument:', $portlet );
return;
}
if ( $portlet.hasClass( 'collapsible' ) ) return;
const isSmallScreen = window.matchMedia( '(max-width: 720px)' );
const id = $portlet.attr( 'id' );
const storageId = 'sidebar_vector_c_' + id;
const collapsedStorage = localStorage.getItem( storageId );
let isCollapsed = collapsedStorage === 'y';
if ( collapsedStorage === null && ( !mw.config.get( 'wgUserId' ) || mw.config.get( 'wgUserIsTemp' ) ) ) {
isCollapsed = defaultCollapsedPortlets[wiki].includes( id );
}
$portlet.addClass( 'collapsible' );
// On small screen widths, the portlets are placed below the page content.
// Collapse them by default; only one can be expanded at a time to not make the page too long
function initCollapseState( isSmallScreen ) {
if ( !isSmallScreen.matches ) {
$portlet.toggleClass( 'collapsed', isCollapsed )
.find( '.vector-menu-content' ).toggle( !isCollapsed );
} else {
$portlet.addClass( 'collapsed' )
.find( '.vector-menu-content' ).hide();
}
}
initCollapseState(isSmallScreen);
isSmallScreen.onchange = initCollapseState;
function doSlideAnimation( $element ) {
const isReducedMotion = window.matchMedia( '(prefers-reduced-motion: reduce)' ).matches;
const animationTime = isReducedMotion ? 0 : 'fast';
const $content = $element.find( '.vector-menu-content' );
if ( $element.hasClass( 'collapsed' ) ) {
$content.slideUp( animationTime );
} else {
$content.slideDown( animationTime );
}
}
function toggleCollapsed() {
$portlet.toggleClass( 'collapsed' );
doSlideAnimation( $portlet );
if ( !isSmallScreen.matches ) {
isCollapsed = $portlet.hasClass( 'collapsed' );
localStorage.setItem( storageId, isCollapsed ? 'y' : 'n' );
mw.hook( 'mcw.toggleCollapsibleSidebarPortlet' ).fire( $portlet[0], isCollapsed );
} else {
const $otherPortlets = $( '#mw-panel .vector-menu-portal.collapsible' )
.not( $portlet )
.addClass( 'collapsed' );
doSlideAnimation( $otherPortlets );
}
}
$portlet.find( '.vector-menu-heading' )
.attr( 'tabindex', 0 )
.on( 'keypress', event => {
if ( event.key == 'Enter' ) {
event.stopImmediatePropagation();
toggleCollapsed();
}
} )
.on( 'click', event => {
event.stopPropagation();
toggleCollapsed();
} );
} );
// Make sidebar sections collapsible
$( '#mw-panel .vector-menu-portal' ).has( '.vector-menu-heading:visible' ).each( ( i, portlet ) => {
mw.hook( 'mcw.makeSidebarPortletCollapsible' ).fire( portlet );
} );
// Make watch tab collapsible
mw.loader.using( 'skins.vector.legacy.js' ).then( () => {
$( '#ca-watch, #ca-unwatch' ).addClass( 'collapsible' );
$.collapsibleTabs.handleResize();
} );
// Prevent real time preview from polluting the edit form
mw.hook( 'ext.WikiEditor.realtimepreview.loaded' ).add( function(realtimePreview){
realtimePreview.$previewNode.find('input').attr('disabled', true);
});
} );