MediaWiki:Vector.js: verschil tussen versies
(Nieuwe pagina aangemaakt met '→Alle hier geplaatste JavaScript-code wordt geladen voor gebruikers van de vormgeving Vector: window.onload = function() { // Get the current month (1-based) var n = new Date().getMonth() + 1; // Select the nth child of the element with class 'tabber__tabs' var element = document.querySelector('.pluktips .tabber__tabs :nth-child(' + n + ')'); // Trigger the click event if the element exists if (element) { element.click();...') |
Geen bewerkingssamenvatting |
||
| Regel 1: | Regel 1: | ||
/* Alle hier geplaatste JavaScript-code wordt geladen voor gebruikers van de vormgeving Vector */ | /* Alle hier geplaatste JavaScript-code wordt geladen voor gebruikers van de vormgeving Vector */ | ||
function observeTabberClass() { | |||
// | // Function to run when the class is added | ||
function selectCurrentMonthTab() { | |||
const currentMonth = new Date().getMonth() + 1; | |||
const currentTab = document.querySelector('.pluktips .tabber__tabs :nth-child(' + currentMonth + ')'); | |||
if (currentTab) { | |||
currentTab.click(); | |||
} | |||
} | |||
// Observe changes on the element with class 'tabber' | |||
const tabberElement = document.querySelector('.tabber'); | |||
const observerConfig = { attributes: true, attributeFilter: ['class'] }; | |||
const observerCallback = function(mutationsList) { | |||
for (const mutation of mutationsList) { | |||
if (mutation.type === 'attributes' && mutation.attributeName === 'class') { | |||
if (mutation.target.classList.contains('tabber--live')) { | |||
selectCurrentMonthTab(); | |||
observer.disconnect(); // Stop observing after the class is added | |||
} | |||
} | |||
} | |||
}; | |||
const observer = new MutationObserver(observerCallback); | |||
observer.observe(tabberElement, observerConfig); | |||
} | |||
// Call the function to start observing | |||
observeTabberClass(); | |||
Versie van 28 mei 2024 15:12
/* Alle hier geplaatste JavaScript-code wordt geladen voor gebruikers van de vormgeving Vector */
function observeTabberClass() {
// Function to run when the class is added
function selectCurrentMonthTab() {
const currentMonth = new Date().getMonth() + 1;
const currentTab = document.querySelector('.pluktips .tabber__tabs :nth-child(' + currentMonth + ')');
if (currentTab) {
currentTab.click();
}
}
// Observe changes on the element with class 'tabber'
const tabberElement = document.querySelector('.tabber');
const observerConfig = { attributes: true, attributeFilter: ['class'] };
const observerCallback = function(mutationsList) {
for (const mutation of mutationsList) {
if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
if (mutation.target.classList.contains('tabber--live')) {
selectCurrentMonthTab();
observer.disconnect(); // Stop observing after the class is added
}
}
}
};
const observer = new MutationObserver(observerCallback);
observer.observe(tabberElement, observerConfig);
}
// Call the function to start observing
observeTabberClass();