|
|
| Line 1: |
Line 1: |
| /*mw.loader.load('https://deadlock.wiki/index.php?title=User:Monster_Domosed/Wiki_Redesign.js&action=raw&ctype=text/javascript');*/ | | /*mw.loader.load('https://deadlock.wiki/index.php?title=User:Monster_Domosed/Wiki_Redesign.js&action=raw&ctype=text/javascript');*/ |
|
| |
|
| $(function () {
| | (function () { |
| | function applyState(enabled) { |
| | const root = document.documentElement; |
|
| |
|
| function toggleFixedWidth(isEnabled) {
| | root.classList.toggle('fixed-width-mode', enabled); |
| document.documentElement.classList.toggle('fixed-width-mode', isEnabled); | | |
| mw.cookie.set('fixedWidth', isEnabled ? 'true' : 'false', { | | localStorage.setItem('fixedWidth', enabled); |
| prefix: '',
| |
| expires: 365 * 86400
| |
| });
| |
| } | | } |
|
| |
|
| var enabled = mw.cookie.get('fixedWidth', '', 'true') === 'true'; | | mw.hook('wikipage.content').add(function () { |
| toggleFixedWidth(enabled);
| |
| | |
| var link = mw.util.addPortletLink(
| |
| 'p-personal',
| |
| '#',
| |
| 'Fixed width',
| |
| 'pt-fixedwidth'
| |
| );
| |
|
| |
|
| if (!link) return;
| | const enabled = localStorage.getItem('fixedWidth') === 'true'; |
| | applyState(enabled); |
|
| |
|
| $(link).find('a').on('click', function (e) {
| | const link = mw.util.addPortletLink( |
| e.preventDefault(); | | 'p-personal', |
| | '#', |
| | '', |
| | 'pt-fixedwidth', |
| | 'Toggle fixed width' |
| | ); |
|
| |
|
| var current = document.documentElement.classList.contains('fixed-width-mode'); | | if (!link) return; |
| toggleFixedWidth(!current);
| |
| });
| |
| });
| |
|
| |
|
| $(function () {
| | const a = link.querySelector('a'); |
| var cookieOptions = {
| | if (!a) return; |
| prefix: '',
| |
| expires: 365 * 86400 | |
| };
| |
|
| |
|
| var isDefaultEnabled = mw.cookie.get('fixedWidth', cookieOptions.prefix, 'true') === 'true';
| | a.className = 'toggle-width'; |
|
| |
|
| function toggleFixedWidth(isEnabled) {
| | a.addEventListener('click', function (e) { |
| if (isEnabled) { | | e.preventDefault(); |
| document.documentElement.style.setProperty('--mw-width', '1200px');
| | const now = !document.documentElement.classList.contains('fixed-width-mode'); |
| document.documentElement.style.setProperty('--mw-left', '151px');
| | applyState(now); |
| document.documentElement.style.setProperty('--mw-right', '311px'); | | }); |
| document.documentElement.style.setProperty('--mw-personal', '326px'); | |
| document.documentElement.style.setProperty('--mw-margin-top', '-1px');
| |
| } else {
| |
| document.documentElement.style.setProperty('--mw-width', '100%');
| |
| document.documentElement.style.setProperty('--mw-left', 'auto');
| |
| document.documentElement.style.setProperty('--mw-right', 'auto');
| |
| document.documentElement.style.setProperty('--mw-personal', 'auto');
| |
| document.documentElement.style.setProperty('--mw-margin-top', '0px'); | |
| } | |
| }
| |
| | |
| toggleFixedWidth(isDefaultEnabled);
| |
| | |
| var toggle = mw.util.addPortletLink(
| |
| 'p-personal',
| |
| '#',
| |
| 'Toggle width',
| |
| 'pt-fixedwidth',
| |
| 'Toggle fixed width'
| |
| );
| |
| | |
| $(toggle).on('click', function (e) {
| |
| e.preventDefault();
| |
| | |
| var current = mw.cookie.get('fixedWidth', cookieOptions.prefix, 'true') === 'true';
| |
| var next = !current;
| |
| | |
| mw.cookie.set('fixedWidth', next ? 'true' : 'false', cookieOptions);
| |
| toggleFixedWidth(next);
| |
| }); | | }); |
| }); | | })(); |
|
| |
|
| /** | | /** |