MediaWiki:Common.js: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
Tag: Manual revert
No edit summary
Line 1: Line 1:
$(document).ready(function () {
$(document).ready(function () {
var areFiltersActive = false;
var areFiltersActive = false;
    var communityFeatured = $('#community-featured');
    var communityFeaturedBlock1 = $('#community-featured-block-1');
    var communityFeaturedBlock2 = $('#community-featured-block-2');
    var communityFeaturedBlock3 = $('#community-featured-block-3');
    var communityFeaturedList1 = $('#community-featured-list-1');
    var communityFeaturedList2 = $('#community-featured-list-2');
    var communityFeaturedList3 = $('#community-featured-list-3');
     var filteredCards = $('.filtered-list-item');
     var filteredCards = $('.filtered-list-item');
     var showArticleWrapper = $('#show-article-wrapper');
     var showArticleWrapper = $('#show-article-wrapper');
Line 18: Line 11:
});
});
      
      
    updateCommunityFeaturedPosition('block', '1');
   
    // Insert the community featured element after the second card
if (communityFeatured.length && filteredCards.length >= 2) {
    console.log("Community Featured element and at least two filtered cards found.");
    communityFeatured.detach();
    filteredCards.eq(1).after(communityFeatured);
    communityFeatured.show();
    console.log("Community Featured element has been moved after the second filtered card.");
} else {
    if (!communityFeatured.length) {
        console.log("No Community Featured element found.");
    }
    if (filteredCards.length < 2) {
        console.log("Less than two filtered cards found. Found: ", filteredCards.length);
    }
}
    function updateCommunityFeaturedPosition(view, section) {
    // Only proceed if filters are not active
    if (!areFiltersActive) {
        // Hide all communityFeatured elements initially
        $('[id^="community-featured-"]').hide();
   
        // Determine the appropriate communityFeatured element based on the current view and section
        var communityFeatured;
        if (view === 'block') {
            communityFeatured = $('#community-featured-block-' + section);
        } else if (view === 'list') {
            communityFeatured = $('#community-featured-list-' + section);
        }
   
        // Position the appropriate communityFeatured element after the second card if it exists
        if (communityFeatured.length) {
            var filteredCards = communityFeatured.closest('.list-container').find('.filtered-list-item');
            if (filteredCards.length >= 2) {
                communityFeatured.detach();
                filteredCards.eq(1).after(communityFeatured);
                communityFeatured.show();
            }
        }
    }
    }


     // Check if the specific element exists on the page
     // Check if the specific element exists on the page
Line 85: Line 35:
     }
     }
      
      
    // Using delegated event handling for both #list, #list-list and their variations
$('#list, #list-list, #list-block-1, #list-block-2, #list-block-3, #list-list-1, #list-list-2, #list-list-3').on('mousedown', '.filtered-value-option', function(event) {
    console.log("Filter clicked within context:", this);
    // Check context and hide the corresponding communityFeatured element
    var context = $(this).closest('[id]').attr('id'); // Get the closest parent with an ID
    switch (context) {
        case 'list':
            communityFeatured.hide();
            break;
        case 'list-block-1':
            communityFeaturedBlock1.hide();
            break;
        case 'list-block-2':
            communityFeaturedBlock2.hide();
            break;
        case 'list-block-3':
            communityFeaturedBlock3.hide();
            break;
        case 'list-list-1':
            communityFeaturedList1.hide();
            break;
        case 'list-list-2':
            communityFeaturedList2.hide();
            break;
        case 'list-list-3':
            communityFeaturedList3.hide();
            break;
        default:
            // If the context does not match any case, you can log it or handle it as needed
            console.log("Unknown context:", context);
    }
    // Additional debugging: Check the event target and its parents
    console.log("Event target:", event.target);
    console.log("Parents of event target:", $(event.target).parents());
});


     // Format paragraphs
     // Format paragraphs
Line 180: Line 93:
         });
         });
     }  
     }  
    // Function to check if filters are cleared for given selectors and update visibility of corresponding community elements
function updateCommunityElementsVisibility(selectors, communityElements) {
    for (var i = 0; i < selectors.length; i++) {
        var selector = selectors[i];
        var communityElement = communityElements[i]; // Access the corresponding community element
        var checkedFilters = $(selector + ' .filtered-value-option input[type="checkbox"]:checked');
        console.log("Checked filters count in " + selector + ":", checkedFilters.length);
        // If no filters are checked, show the community element associated with this selector
        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 community element if any filters are active
        }
    }
}
    // Initial checks
    var selectors = [
    '#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')
];
    // Call the function to initially set the visibility based on filters
    updateCommunityElementsVisibility(selectors, communityElements);
    // You can also call this function in response to filter changes or page events where filters might be modified
    $('#list, #list-block-1, #list-block-2, #list-block-3, #list-list-1, #list-list-2, #list-list-3').on('change', '.filtered-value-option input[type="checkbox"]', function() {
        areFiltersActive = $('.filtered-value-option input[type="checkbox"]:checked').length > 0;
    updateCommunityElementsVisibility(selectors, communityElements);
    });


// Function to open the modal and adjust the list
// Function to open the modal and adjust the list
Line 247: Line 108:
         // Adjust width of filtered-list-items in #list
         // Adjust width of filtered-list-items in #list
    filteredListItems.css('width', 'calc(33.333% - 0px)');
    filteredListItems.css('width', 'calc(33.333% - 0px)');
   
    // Hide communityFeatured
    $('[id^="community-featured"]').hide();
    // Clear existing content in modal
    // Clear existing content in modal
Line 432: Line 290:
    // End of openModal
    // End of openModal
}
}
// Function to check if all filters are cleared in block view and its variations
    function checkBlockFiltersCleared() {
        var selectors = ['#list', '#list-block-1', '#list-block-2', '#list-block-3'];
        for (var i = 0; i < selectors.length; i++) {
            var selector = selectors[i];
            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);
                // Show all community elements related to block views
                $('#community-featured, #community-featured-block-1, #community-featured-block-2, #community-featured-block-3').show();
            } else {
                console.log('Some filters are still active in ' + selector);
                // Hide all community elements related to block views
                $('#community-featured, #community-featured-block-1, #community-featured-block-2, #community-featured-block-3').hide();
            }
        }
    }
    // Function to check if all filters are cleared in list view and its variations
    function checkListFiltersCleared() {
        var selectors = ['#list-list', '#list-list-1', '#list-list-2', '#list-list-3'];
        for (var i = 0; i < selectors.length; i++) {
            var selector = selectors[i];
            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);
                // Show all community elements related to list views
                $('#community-featured, #community-featured-list-1, #community-featured-list-2, #community-featured-list-3').show();
            } else {
                console.log('Some filters are still active in ' + selector);
                // Hide all community elements related to list views
                $('#community-featured, #community-featured-list-1, #community-featured-list-2, #community-featured-list-3').hide();
            }
        }
    }


// closeModal function
// closeModal function
Line 658: Line 476:
         $(".home-block-view > div").hide();
         $(".home-block-view > div").hide();
         $(".home-chronicle-block").show();
         $(".home-chronicle-block").show();
   
        // Update the position of the communityFeatured elements for the chronicle block view
        updateCommunityFeaturedPosition('block', '1'); // '1' corresponds to chronicle
     });
     });
Line 671: Line 486:
         $(".home-list-view > div").hide();
         $(".home-list-view > div").hide();
         $(".home-chronicle-list").show();
         $(".home-chronicle-list").show();
        // Update the position of the communityFeatured elements for the chronicle list view
        updateCommunityFeaturedPosition('list', '1'); // '1' corresponds to chronicle
     });
     });
Line 681: Line 493:
         $(".home-list-view > div").hide();
         $(".home-list-view > div").hide();
         $(".home-chronicle-list").show();
         $(".home-chronicle-list").show();
        // Update the position of the communityFeatured element for the chronicle list view
        updateCommunityFeaturedPosition('list', '1'); // '1' corresponds to chronicle
     });
     });


Line 691: Line 500:
         $(".home-list-view > div").hide();
         $(".home-list-view > div").hide();
         $(".home-random-list").show();
         $(".home-random-list").show();
        // Update the position of the communityFeatured element for the random list view
        updateCommunityFeaturedPosition('list', '2'); // '2' corresponds to random
     });
     });


Line 700: Line 506:
         $(".home-list-view > div").hide();
         $(".home-list-view > div").hide();
         $(".home-alphabetical-list").show();
         $(".home-alphabetical-list").show();
        // Update the position of the communityFeatured element for the alphabetical list view
        updateCommunityFeaturedPosition('list', '3'); // '3' corresponds to alphabetical
     });
     });


Line 711: Line 514:
    $(".home-block-view > div").hide();
    $(".home-block-view > div").hide();
    $(".home-chronicle-block").show();
    $(".home-chronicle-block").show();
        // Update the position of the communityFeatured element for the alphabetical list view
        updateCommunityFeaturedPosition('block', '1'); // '1' corresponds to chronicle
});
});
Line 720: Line 520:
    $(".home-block-view > div").hide();
    $(".home-block-view > div").hide();
    $(".home-random-block").show();
    $(".home-random-block").show();
        // Update the position of the communityFeatured element for the random list view
        updateCommunityFeaturedPosition('block', '2'); // '2' corresponds to random
});
});
Line 729: Line 526:
    $(".home-block-view > div").hide();
    $(".home-block-view > div").hide();
    $(".home-alphabetical-block").show();
    $(".home-alphabetical-block").show();
        // Update the position of the communityFeatured element for the alphabetical list view
        updateCommunityFeaturedPosition('block', '3'); // '3' corresponds to alphabetical
});
});


Navigation menu