Jump to content

User:Ofus/hide-vector-sidebar.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Ofus (talk | contribs) at 18:30, 28 November 2016. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
// import from User:PleaseStand/hide-vector-sidebar.js

/* 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);
        }
        // mw.util.addPortletLink( portletId, href, text [, id [, tooltip [, accesskey [, nextnode ]]]] );
        // sidebarSwitch = mw.util.addPortletLink( 'p-cactions', '#', 'Hide sidebar', 'ca-sidebar', 'Hide the navigation links', 'a' );
        // n-mainpage-description
        sidebarSwitch = mw.util.addPortletLink(
            'p-tb',
            '#',
            'Hide sidebar',
            't-mworg',
            'Hide the navigation links ',
            'h',
            '#n-mainpage-description'
        );
        $( 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', '#', 'Hide sidebar', 'ca-sidebar', 'Hide the navigation links', 'a' );
        sidebarSwitch = mw.util.addPortletLink(
            'p-tb',
            '#',
            'Hide sidebar',
            't-mworg',
            'Hide the navigation links ',
            'h',
            '#n-mainpage-description'
        );
        $( sidebarSwitch ).click( function ( e ) {
            e.preventDefault();
            sidebarHide();
        } );
    }
 
    // Only activate on Vector skin
    if ( mw.config.get( 'skin' ) === 'vector' ) {
        $( function() {
            // Change this if you want to show the sidebar by default
            // sidebarHide();
        } );
    }
 
}( mediaWiki, jQuery ) );