MediaWiki:Vector.js: verschil tussen versies

Uit Wildpluk wiki
Geen bewerkingssamenvatting
kGeen bewerkingssamenvatting
Regel 4: Regel 4:
     function selectCurrentMonthTab() {
     function selectCurrentMonthTab() {
         var currentMonth = new Date().getMonth() + 1;
         var currentMonth = new Date().getMonth() + 1;
        console.log('tabber live. current month:'+currentMonth);
         var currentTab = document.querySelector('.pluktips .tabber__tabs :nth-child(' + currentMonth + ')');
         var currentTab = document.querySelector('.pluktips .tabber__tabs :nth-child(' + currentMonth + ')');
         if (currentTab) {
         if (currentTab) {

Versie van 28 mei 2024 15:18

/* 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;
        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();