MediaWiki:Common.js: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Tag: Reverted
Line 160: Line 160:
     }  
     }  
      
      
 
// Function to check if filters are cleared and update visibility of community elements
    function checkFiltersCleared(selectors, communityElements) {
        selectors.forEach((selector, index) => {
            var checkedFilters = $(selector + ' .filtered-value-option input[type="checkbox"]:checked');
            if (checkedFilters.length === 0) {
                console.log("All filters are cleared");
                communityElements[index].show();
            } else {
                console.log("Some filters are still active");
                communityElements[index].hide();
            }
        });
    }
      
      
// Function to check if filters are cleared and update visibility of community elements
function checkFiltersCleared(selector, communityElement) {
    var checkedFilters = $(selector + ' .filtered-value-option input[type="checkbox"]:checked');
    console.log("Checked filters count in " + selector + ":", checkedFilters.length);
    if (checkedFilters.length === 0) {
        console.log("All filters are cleared in " + selector);
        communityElement.show();
    } else {
        console.log("Some filters are still active in " + selector);
        communityElement.hide(); // Hide the element if any filters are active
    }
}


     // Event delegation for filter changes in block, list views, and their variations
     // Event delegation for filter changes in block, list views, and their variations
Line 186: Line 185:
     });
     });


    // Initial checks
    var selectors = ['#list', '#list-list', '#list-block-1', '#list-block-2', '#list-block-3', '#list-list-1', '#list-list-2', '#list-list-3'];
    var communityElements = [
        $('#community-featured'),
        $('#community-featured-block-1'),
        $('#community-featured-block-2'),
        $('#community-featured-block-3'),
        $('#community-featured-list-1'),
        $('#community-featured-list-2'),
        $('#community-featured-list-3')
    ];


     // Initial checks
     // Initial check on page load
     var selectors = ['#list', '#list-list'];
     checkFiltersCleared(selectors, communityElements);


     // Iterate over the selectors and perform initial checks
     // Check whenever a filter changes
     selectors.forEach(function(selector) {
     selectors.forEach(selector => {
        checkFiltersCleared(selector, communityFeatured);
        $(selector).on('change', '.filtered-value-option input[type="checkbox"]', function() {
            checkFiltersCleared(selectors, communityElements);
        });
     });
     });


// Function to check if all filters are cleared and return boolean
// Function to check if all filters are cleared and return boolean
function areFiltersCleared(selector) {
function areFiltersCleared(selectors) {
    var checkedFilters = $(selector + ' .filtered-value-option input[type="checkbox"]:checked');
        return selectors.every(selector => {
    return checkedFilters.length === 0;
            var checkedFilters = $(selector + ' .filtered-value-option input[type="checkbox"]:checked');
}
            return checkedFilters.length === 0;
        });
    }
// Function to open the modal and adjust the list
// Function to open the modal and adjust the list
function openModal(cardElement, event) {
function openModal(cardElement, event) {

Navigation menu