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 108: Line 108:
     }
     }
      
      
    function checkFiltersCleared(selector, communityElement, positionSelector, positionIndex) {
// 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');
    var checkedFilters = $(selector + ' .filtered-value-option input[type="checkbox"]:checked');
    console.log("Checked filters count in " + selector + ":", checkedFilters.length);
    if (checkedFilters.length === 0) {
    if (checkedFilters.length === 0) {
        positionAndShowCommunityElement(communityElement, positionSelector, positionIndex);
        console.log("All filters are cleared in " + selector);
        communityElement.show();
    } else {
    } else {
        communityElement.hide();
        console.log("Some filters are still active in " + selector);
        communityElement.hide(); // Hide the element if any filters are active
    }
    }
}
}


function positionAndShowCommunityElement(communityElement, positionSelector, positionIndex) {
    communityElement.detach();
    var targetPosition = $(positionSelector + ' .filtered-list-item').eq(positionIndex);
    if(targetPosition.length === 0) {
        console.log("Target position not found. Selector or index might be incorrect.");
        return;
    }
    communityElement.insertAfter(targetPosition);
    communityElement.hide().fadeIn();
    console.log("Community element should now be visible after", targetPosition);
}
// Event delegation for filter changes in block view
// Event delegation for filter changes in block view
$('#list').on('change', '.filtered-value-option input[type="checkbox"]', function() {
$('#list').on('change', '.filtered-value-option input[type="checkbox"]', function() {
    checkFiltersCleared('#list', communityFeatured, '#list', 1); // Position after 2nd filtered card
    checkFiltersCleared('#list', communityFeatured); // Call the function directly without delay
});
});
// Event delegation for filter changes in list view
// Event delegation for filter changes in list view
$('#list-list').on('change', '.filtered-value-option input[type="checkbox"]', function() {
$('#list-list').on('change', '.filtered-value-option input[type="checkbox"]', function() {
    checkFiltersCleared('#list-list', communityListFeatured, '#list-list', 3); // Position after 4th filtered card
    checkFiltersCleared('#list-list', communityListFeatured); // Call the function directly without delay
});
});


Navigation menu