MediaWiki:Vector.js: verschil tussen versies
kGeen bewerkingssamenvatting |
Geen bewerkingssamenvatting |
||
Regel 3: | Regel 3: | ||
// Function to run when the class is added | // Function to run when the class is added | ||
function selectCurrentMonthTab() { | function selectCurrentMonthTab() { | ||
var currentMonth = new Date().getMonth() + 1; | |||
console.log('tabber live. current month:'+currentMonth); | |||
var currentTab = document.querySelector('.pluktips .tabber__tabs :nth-child(' + currentMonth + ')'); | |||
if (currentTab) { | if (currentTab) { | ||
currentTab.click(); | currentTab.click(); | ||
Regel 12: | Regel 12: | ||
// Observe changes on the element with class 'tabber' | // Observe changes on the element with class 'tabber' | ||
var tabberElement = document.querySelector('.tabber'); | |||
var observerConfig = { attributes: true, attributeFilter: ['class'] }; | |||
var observerCallback = function(mutationsList) { | |||
for ( | for (var i = 0; i < mutationsList.length; i++) { | ||
var mutation = mutationsList[i]; | |||
if (mutation.type === 'attributes' && mutation.attributeName === 'class') { | if (mutation.type === 'attributes' && mutation.attributeName === 'class') { | ||
if (mutation.target.classList.contains('tabber--live')) { | if (mutation.target.classList.contains('tabber--live')) { | ||
selectCurrentMonthTab(); | selectCurrentMonthTab(); | ||
observer.disconnect(); // Stop observing after the class is added | observer.disconnect(); // Stop observing after the class is added | ||
break; | |||
} | } | ||
} | } | ||
Regel 26: | Regel 28: | ||
}; | }; | ||
var observer = new MutationObserver(observerCallback); | |||
observer.observe(tabberElement, observerConfig); | observer.observe(tabberElement, observerConfig); | ||
} | } |
Versie van 28 mei 2024 15:17
/* 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() { var currentMonth = new Date().getMonth() + 1; console.log('tabber live. current month:'+currentMonth); var currentTab = document.querySelector('.pluktips .tabber__tabs :nth-child(' + currentMonth + ')'); if (currentTab) { currentTab.click(); } } // Observe changes on the element with class 'tabber' var tabberElement = document.querySelector('.tabber'); var observerConfig = { attributes: true, attributeFilter: ['class'] }; var observerCallback = function(mutationsList) { for (var i = 0; i < mutationsList.length; i++) { var mutation = mutationsList[i]; if (mutation.type === 'attributes' && mutation.attributeName === 'class') { if (mutation.target.classList.contains('tabber--live')) { selectCurrentMonthTab(); observer.disconnect(); // Stop observing after the class is added break; } } } }; var observer = new MutationObserver(observerCallback); observer.observe(tabberElement, observerConfig); } // Call the function to start observing observeTabberClass();