MediaWiki:Vector.js: verschil tussen versies

Uit Wildpluk wiki
Geen bewerkingssamenvatting
kGeen 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() {
        console.log('tabber live');
         const currentMonth = new Date().getMonth() + 1;
         const currentMonth = new Date().getMonth() + 1;
         const currentTab = document.querySelector('.pluktips .tabber__tabs :nth-child(' + currentMonth + ')');
         const currentTab = document.querySelector('.pluktips .tabber__tabs :nth-child(' + currentMonth + ')');

Versie van 28 mei 2024 15:14

/* 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() {
        console.log('tabber live');
        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();