MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary Tag: Manual revert |
No edit summary Tag: Reverted |
||
| Line 60: | Line 60: | ||
console.error("Failed to load OpenSeadragon."); | console.error("Failed to load OpenSeadragon."); | ||
}); | }); | ||
}); | |||
//toc edit | |||
document.addEventListener("DOMContentLoaded", function() { | |||
function adjustPinnedToc() { | |||
if (window.innerWidth < 768) { | |||
let pinnedToc = document.querySelector(".vector-pinnable-header-pinned"); // Pin class | |||
if (pinnedToc) { | |||
pinnedToc.style.fontSize = "12px"; // Adjust font size | |||
pinnedToc.style.lineHeight = "1.2"; // Adjust line height | |||
// Apply font size to all child elements | |||
document.querySelectorAll('.vector-pinnable-header-pinned *') | |||
.forEach(el => el.style.fontSize = "12px"); | |||
} | |||
} | |||
} | |||
adjustPinnedToc(); // Apply font size on page load | |||
window.addEventListener("resize", adjustPinnedToc); // Adjust on resize | |||
// Watch for changes to the page (e.g., pin/unpin the TOC) | |||
let observer = new MutationObserver(() => adjustPinnedToc()); | |||
observer.observe(document.body, { childList: true, subtree: true }); | |||
}); | }); | ||
Revision as of 01:02, 13 March 2025
mw.loader.using('mediawiki.util').then(function () {
if (!mw.config.get('wgUserName')) { // Only for non-logged-in users
console.log('Non-logged-in user detected');
// Automatically tick the checkbox to expand the Main menu
var mainMenuCheckbox = document.getElementById('vector-main-menu-dropdown-checkbox');
if (mainMenuCheckbox) {
mainMenuCheckbox.checked = true; // Check the checkbox to expand the menu
console.log('Main menu checkbox checked');
}
// Delay the "Move to Sidebar" button click to ensure the button is clickable
setTimeout(function() {
// Target the "Move to Sidebar" button by the 'data-event-name' attribute
var moveToSidebarButton = document.querySelector('[data-event-name="pinnable-header.vector-main-menu.pin"]');
if (moveToSidebarButton) {
moveToSidebarButton.click(); // Click the button
console.log('Move to sidebar button clicked');
}
}, 200); // Delay of 150ms to allow elements to load, 50 is not quite enough so upped to 100
}
});
mw.loader.using('mediawiki.user').then(function() {
if (!mw.config.get('wgUserName')) { // If the user is NOT logged in
document.body.classList.add('not-logged-in'); // Manually add the not-logged-in class
}
});
mw.loader.using('mediawiki.user').then(function() {
if (!mw.config.get('wgUserName')) { // If the user is NOT logged in
document.body.classList.add('not-logged-in'); // Manually add the not-logged-in class
}
});
mw.loader.using(['jquery'], function() {
// Load OpenSeadragon manually
$.getScript('/extensions/OpenSeadragon/openseadragon.min.js')
.done(function () {
console.log("OpenSeadragon loaded successfully.");
// Ensure OpenSeadragon is defined
if (typeof OpenSeadragon !== 'undefined' && $('#openseadragon1').length) {
var viewer = OpenSeadragon({
id: "openseadragon1",
prefixUrl: "/extensions/OpenSeadragon/images/",
tileSources: "/extensions/OpenSeadragon/images/Map/Wyld West legend complete with Hope V1.dzi"
});
console.log("OpenSeadragon viewer initialized.");
} else {
console.error("OpenSeadragon is not defined or #openseadragon1 element is missing.");
}
})
.fail(function () {
console.error("Failed to load OpenSeadragon.");
});
});
//toc edit
document.addEventListener("DOMContentLoaded", function() {
function adjustPinnedToc() {
if (window.innerWidth < 768) {
let pinnedToc = document.querySelector(".vector-pinnable-header-pinned"); // Pin class
if (pinnedToc) {
pinnedToc.style.fontSize = "12px"; // Adjust font size
pinnedToc.style.lineHeight = "1.2"; // Adjust line height
// Apply font size to all child elements
document.querySelectorAll('.vector-pinnable-header-pinned *')
.forEach(el => el.style.fontSize = "12px");
}
}
}
adjustPinnedToc(); // Apply font size on page load
window.addEventListener("resize", adjustPinnedToc); // Adjust on resize
// Watch for changes to the page (e.g., pin/unpin the TOC)
let observer = new MutationObserver(() => adjustPinnedToc());
observer.observe(document.body, { childList: true, subtree: true });
});