Jump to content

User:Arielco/ShowHideSidebar-Modern.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
( 	function ( mw, $ ) {
	var sidebarSwitch;

	function sidebarHide() {
		document.getElementById( 'mw_portlets' ).style.visibility = 'hidden';
		document.getElementById( 'mw_content' ).style.marginLeft = '0';
		document.getElementById( 'p-cactions' ).style.marginLeft = '0';
		if ( sidebarSwitch ) {
			sidebarSwitch.parentNode.removeChild(sidebarSwitch);
		}
		sidebarSwitch = mw.util.addPortletLink( 'p-cactions', '#', 'Show sidebar', 'ca-sidebar', 'Show the navigation links', 'a' );
		$( sidebarSwitch ).click( function ( e ) {
			console.log('showing sidebar');
			e.preventDefault();
			sidebarShow();
		} );
	}
	
	function sidebarShow() {
		document.getElementById( 'mw_portlets' ).style.visibility = null;
		document.getElementById( 'mw_content' ).style.marginLeft = null;
		document.getElementById( 'p-cactions' ).style.marginLeft = null;
		if ( sidebarSwitch ) {
			sidebarSwitch.parentNode.removeChild(sidebarSwitch);
		}
		sidebarSwitch = mw.util.addPortletLink( 'p-cactions', '#', 'Hide sidebar', 'ca-sidebar', 'Hide the navigation links', 'a' );
		$( sidebarSwitch ).click( function ( e ) {
			console.log('hiding sidebar');
			e.preventDefault();
			sidebarHide();
		} );
	}
	
	console.log("2017-03-03");
	// Only activate on Vector skin
	if ( mw.config.get( 'skin' ) === 'modern' ) {
		$( function() {
			$('#searchInput').attr( 'accesskey', function(){console.log('alt-F accesskey');} );
			console.log($('#searchInput').attr('accesskey'));
			// Change this if you want to show the sidebar by default
			console.log('initial sidebarHide');
			sidebarHide();
		} );
	}
	
}( mediaWiki, jQuery ) );