Jump to content

User:Arthurfragoso/vector-max-width-toggle.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.
/*
Creates a width toggle to the new vector layout.

This code was improved on the User:Jdlrobson/vector-max-width-toggle.js version.

Also add this to your CSS:

.mw-checkbox-hack-checkbox:checked ~ .mw-workspace-container .mw-content-container, .mw-checkbox-hack-checkbox:checked ~ .mw-workspace-container .mw-article-toolbar-container {
  margin-left: 11.5em;
}
*/
$(function(){
    var lastValue;
    try {
        lastValue = localStorage.getItem('max-width-on') || '0';
    } catch (e) {
        lastValue = '0';
    }

    if (lastValue === '1') {
        $(document.body).toggleClass('skin-vector-max-width');
    }

    var originalMaxWidth = $('.mw-content-container').css('max-width');
    var originalPageMaxWidth = $('.mw-page-container').css('max-width');
    var originalWorkspaceMaxWidth = $('.mw-workspace-container').css('max-width');

    var $switcher = $('<div style="position:absolute;right:0;top:0;background-image: url(https://upload.wikimedia.org/wikipedia/commons/2/28/Font_Awesome_5_solid_window-maximize.svg);width: 40px;height: 40px;background-size: 20px;background-position: top right;background-repeat: no-repeat;"></div>')
        .on('click', function() {
            $(document.body).toggleClass('skin-vector-max-width');
            localStorage.setItem('max-width-on', lastValue === '0' ? '1' : '0');
            var currentMaxWidth = $('.mw-content-container').css('max-width')
            var currentPageMaxWidth = $('.mw-page-container').css('max-width')
            var currentWorkspaceMaxWidth = $('.mw-workspace-container').css('max-width')
            $('.mw-content-container').css('max-width', currentMaxWidth === 'none' ? originalMaxWidth : 'none')
            $('.mw-page-container').css('max-width', currentPageMaxWidth === 'none' ? originalPageMaxWidth : 'none')
            $('.mw-workspace-container').css('max-width', currentWorkspaceMaxWidth === 'none' ? originalWorkspaceMaxWidth : 'none')
        } ).prependTo('#content');

    $('#content').css('position', 'relative');

    // no click mode
    $('.vector-menu-checkbox').on('mouseover', function ( ev ) {

        $('.vector-menu-checkbox').prop('checked', false);
         ev.target.checked = true;
    });

    $('.vector-menu:not(.vector-menu-dropdown)').on('mouseover', function () {
        $('.vector-menu-checkbox').prop('checked', false);
    });
});