MediaWiki:Vector-2022.js: Difference between revisions
KurthBemis (talk | contribs) Created page with "→UVLists: pin the main menu for public visitors.: (function () { if (mw.config.get('wgUserName')) { return; } var root = document.documentElement; function pinMainMenu() { if (!root.classList.contains('vector-animations-ready')) { return false; } var button = document.querySelector( '[data-event-name="pinnable-header.vector-main-menu.pin"]' ); if (!button) { return fal..." |
KurthBemis (talk | contribs) mNo edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
/* UVLists: | /* 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 | function hidden() { | ||
try { | |||
return localStorage.getItem(key) === '0'; | |||
} catch (e) { | |||
return false; | return false; | ||
} | } | ||
} | } | ||
// Remember the visitor's own hide and show clicks. | |||
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'); | |||
} catch (e) { | |||
// Storage may be unavailable; the default applies next time. | |||
} | |||
} | } | ||
}, 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(); | |||
} | |||
}); | |||
}); | }); | ||
}()); | }()); | ||