MediaWiki:Common.js: Difference between revisions
		
		
		
		Jump to navigation
		Jump to search
		
|  add toggle-sidebar script | m change shortcut key from a to g (Chrome fails with a) | ||
| Line 18: | Line 18: | ||
| 		} | 		} | ||
| 		sidebarSwitch = mw.util.addPortletLink( 'p-cactions', '#', 'Toggle sidebar',   | 		sidebarSwitch = mw.util.addPortletLink( 'p-cactions', '#', 'Toggle sidebar',   | ||
| 'ca-sidebar', 'Hide the navigation links', ' | 'ca-sidebar', 'Hide the navigation links', 'g' ); | ||
| 		$( sidebarSwitch ).click( function ( e ) { | 		$( sidebarSwitch ).click( function ( e ) { | ||
| 			e.preventDefault(); | 			e.preventDefault(); | ||
| Line 35: | Line 35: | ||
| 		} | 		} | ||
| 		sidebarSwitch = mw.util.addPortletLink( 'p-cactions', '#', 'Toggle sidebar',   | 		sidebarSwitch = mw.util.addPortletLink( 'p-cactions', '#', 'Toggle sidebar',   | ||
| 'ca-sidebar', 'Hide the navigation links', ' | 'ca-sidebar', 'Hide the navigation links', 'g' ); | ||
| 		$( sidebarSwitch ).click( function ( e ) { | 		$( sidebarSwitch ).click( function ( e ) { | ||
| 			e.preventDefault(); | 			e.preventDefault(); | ||
Latest revision as of 18:48, 18 September 2015
/* Any JavaScript here will be loaded for all users on every page load. */
/* hide-vector-sidebar.js: Adds a button to toggle visibility of the Vector sidebar.
   Written by PleaseStand. Public domain; all copyright claims waived as described
   in http://en.wikipedia.org/wiki/Template:PD-self */
( function ( mw, $ ) {
	var sidebarSwitch;
	function sidebarHide() {
		document.getElementById( 'mw-panel' ).style.visibility = 'hidden';
		document.getElementById( 'mw-head-base' ).style.marginLeft = '0';
		document.getElementById( 'content' ).style.marginLeft = '0';
		document.getElementById( 'left-navigation' ).style.marginLeft = '0';
		document.getElementById( 'footer' ).style.marginLeft = '0';
		if ( sidebarSwitch ) {
			sidebarSwitch.parentNode.removeChild(sidebarSwitch);
		}
		sidebarSwitch = mw.util.addPortletLink( 'p-cactions', '#', 'Toggle sidebar', 
'ca-sidebar', 'Hide the navigation links', 'g' );
		$( sidebarSwitch ).click( function ( e ) {
			e.preventDefault();
			sidebarShow();
		} );
	}
	
	function sidebarShow() {
		document.getElementById( 'mw-panel' ).style.visibility = '';
		document.getElementById( 'mw-head-base' ).style.marginLeft = '';
		document.getElementById( 'content' ).style.marginLeft = '';
		document.getElementById( 'left-navigation' ).style.marginLeft = '';
		document.getElementById( 'footer' ).style.marginLeft = '';
		if ( sidebarSwitch ) {
			sidebarSwitch.parentNode.removeChild(sidebarSwitch);
		}
		sidebarSwitch = mw.util.addPortletLink( 'p-cactions', '#', 'Toggle sidebar', 
'ca-sidebar', 'Hide the navigation links', 'g' );
		$( sidebarSwitch ).click( function ( e ) {
			e.preventDefault();
			sidebarHide();
		} );
	}
	
	// Only activate on Vector skin
	if ( mw.config.get( 'skin' ) === 'vector' ) {
        // if ( mw.config.get( 'wgAction' ) === 'history' ) {
		$( function() {
			// Change this if you want to show the sidebar by default
			sidebarShow();
		} );
	 //}
        }
	
}( mediaWiki, jQuery ) );