MediaWiki:Common.js: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
Tag: Reverted
No edit summary
Tag: Manual revert
Line 159: Line 159:
         });
         });
     }  
     }  
   
      
      
// Function to check if filters are cleared and update visibility of community elements
// Function to check if filters are cleared and update visibility of community elements
    function checkFiltersCleared(selectors, communityElements) {
function checkFiltersCleared(selector, communityElement) {
        selectors.forEach((selector, index) => {
    var checkedFilters = $(selector + ' .filtered-value-option input[type="checkbox"]:checked');
            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");
    if (checkedFilters.length === 0) {
                communityElements[index].show();
        console.log("All filters are cleared in " + selector);
            } else {
        communityElement.show();
                console.log("Some filters are still active");
    } else {
                communityElements[index].hide();
        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 184: Line 185:
         checkFiltersCleared('#' + contextId, communityFeatured);
         checkFiltersCleared('#' + contextId, communityFeatured);
     });
     });


     // Initial checks
     // 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 selectors = ['#list', '#list-list'];
    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 check on page load
    checkFiltersCleared(selectors, communityElements);


     // Check whenever a filter changes
     // Iterate over the selectors and perform initial checks
     selectors.forEach(selector => {
     selectors.forEach(function(selector) {
        $(selector).on('change', '.filtered-value-option input[type="checkbox"]', function() {
        checkFiltersCleared(selector, communityFeatured);
            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(selectors) {
function areFiltersCleared(selector) {
        return selectors.every(selector => {
    var checkedFilters = $(selector + ' .filtered-value-option input[type="checkbox"]:checked');
            var checkedFilters = $(selector + ' .filtered-value-option input[type="checkbox"]:checked');
    return checkedFilters.length === 0;
            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