User:Davidbuddy9/vector.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | The accompanying .css page for this skin is at User:Davidbuddy9/vector.css. |
/* Gadget will create the toggle button to select narrow/wide layout*/
var debug = true;
mw.loader.using( ['mediawiki.user'], function () {
if (!($(document.body).hasClass("ns-special") || $(document.body).hasClass("skin-vector-legacy"))) {
var lastValue;
try {
lastValue = (mw.user.options.get('gadget-FullWidthVectorOnCSS') == 1) ? '1' : '0';
} catch (e) {
lastValue = '0';
}
if (debug)
mw.log( 'Gadget lastValue' + lastValue + ' Options: ' + mw.user.options.get('gadget-FullWidthVectorOnCSS') );
var $switcher = $('<button class="pt-fullwidth-toggle">↔</button>')
.on('load', function() {
//var newValue=(lastValue === '1') ? '0' : '1';
var newValue='1';
if (newValue==1)
{
$(document.body)
.removeClass("skin-vector-max-width-narrow")
.addClass("skin-vector-max-width-wide")
}
else
{
$(document.body)
.removeClass("skin-vector-max-width-wide")
.addClass("skin-vector-max-width-narrow")
}
lastValue=newValue;
// Save state as CSS gadget so it is fast when new page is loaded
( new mw.Api() ).postWithToken( 'options', {
action: 'options',
change: 'gadget-FullWidthVectorOnCSS=' + lastValue
} ).done( function ( data ) {
if (debug)
mw.log( 'Gadget lastValue ' + lastValue );
} );
} );
$('.mw-workspace-container').first().prepend($switcher);
}
});