MediaWiki:Vector-2022.js: Difference between revisions
KurthBemis (talk | contribs) No edit summary |
KurthBemis (talk | contribs) mNo edit summary |
||
| Line 1: | Line 1: | ||
/* UVLists: show sidebar | /* UVLists: show the main menu in the sidebar for logged-out visitors unless | ||
they have hidden it. Vector keeps the table of contents pinned and | |||
remembers that choice itself; logged-in users have a saved preference. */ | |||
(function () { | (function () { | ||
var key = 'uvlists.sidebar.vector-main-menu'; | |||
if (mw.config.get('wgUserName')) { | if (mw.config.get('wgUserName')) { | ||
return; | return; | ||
} | } | ||
function hidden() { | |||
function | |||
try { | try { | ||
return localStorage.getItem( | return localStorage.getItem(key) === '0'; | ||
} catch (e) { | } catch (e) { | ||
return | return false; | ||
} | } | ||
} | } | ||
// | // Remember the visitor's own hide and show clicks. | ||
document.addEventListener('click', function (event) { | document.addEventListener('click', function (event) { | ||
var button = event.isTrusted && event.target instanceof Element && | |||
event.target.closest('[data-event-name^="pinnable-header.vector-main-menu."]'); | |||
if (button) { | |||
try { | |||
localStorage.setItem(key, /\.pin$/.test(button.getAttribute('data-event-name')) ? '1' : '0'); | |||
if ( | } catch (e) { | ||
// Storage may be unavailable; the default applies next time. | |||
} | |||
} | } | ||
}, true); | }, true); | ||
mw.loader.using('skins.vector.js').then(function () { | |||
$(function () { | |||
// The sidebar column exists only at 1120px and wider. Pinning | |||
// there lets Vector unpin and repin as the window is resized. | |||
var pin = document.querySelector('[data-event-name="pinnable-header.vector-main-menu.pin"]'); | |||
if (pin && !hidden() && window.matchMedia('(min-width: 1120px)').matches && | |||
// | !document.documentElement.classList.contains('vector-feature-main-menu-pinned-enabled')) { | ||
pin.click(); | |||
var | |||
if ( | |||
} | } | ||
}); | }); | ||
}); | |||
}()); | }()); | ||