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 1: Line 1:
$
$(document).ready(function() {
    // Global variables
    var cards = $('.card');
    var showArticleWrapper = $('#show-article-wrapper');
    var areFiltersActive = false;
 
    // Make header-box in Home clickable
    $('.head-box').click(function() {
        window.location.href = '/Main_Page'; // Redirects to the home page
    });
 
    // Loop through each card to format related articles
    cards.each(function() {
        // Check if the card has related articles
        var relatedArticles = $(this).find('.related-articles');
        if (relatedArticles.length > 0) {
            // Get all the related article elements
            var relatedArticleElements = relatedArticles.find('.related-article');
 
            // Create an array to store unique related articles
            var uniqueArticles = [];
 
            // Loop through each related article element
            relatedArticleElements.each(function() {
                // Remove <p> tags from the article
                $(this).find('p').remove();
 
                // Convert the article HTML to a string
                var articleHTML = $(this)[0].outerHTML;
 
                // Check if the article HTML already exists in the uniqueArticles array
                if ($.inArray(articleHTML, uniqueArticles) === -1) {
                    // If it doesn't exist, add it to the uniqueArticles array
                    uniqueArticles.push(articleHTML);
                }
            });
 
            // Clear the content of the related articles container
            relatedArticles.empty();
 
            // Append the unique related articles back to the container
            relatedArticles.append(uniqueArticles.join(''));
        }
    });
 
    // Utility Functions
    function sortChronologically() {
        var cards = $('.list-container .card').get();
 
        cards.sort(function(a, b) {
            var numberA = parseInt($(a).find('.entry-number').text().replace(/\[|\]/g, ''), 10);
            var numberB = parseInt($(b).find('.entry-number').text().replace(/\[|\]/g, ''), 10);
            return numberB - numberA; // Descending order
        });
 
        $.each(cards, function(index, item) {
            $('.list-container').append(item);
        });
    }
 
    function randomizeCards(selector) {
        var cards = $(selector).get();
 
        var i = cards.length, j, temp;
        while (--i > 0) {
            j = Math.floor(Math.random() * (i + 1));
            temp = cards[i];
            cards[i] = cards[j];
            cards[j] = temp;
        }
 
        $.each(cards, function(index, item) {
            $(selector).parent().append(item);
        });
    }
 
    function sortAlphabetically(selector) {
        var cards = $(selector).get();
 
        cards.sort(function(a, b) {
            var titleA = $(a).find('.title').text().toUpperCase();
            var titleB = $(b).find('.title').text().toUpperCase();
            return (titleA < titleB) ? -1 : (titleA > titleB) ? 1 : 0;
        });
 
        $.each(cards, function(index, item) {
            $(selector).parent().append(item);
        });
    }
 
    function updateViews() {
        // Handle cards in the list view
        $('.home-chronicle-list div.list-container div.card:not(.event)').each(function() {
            if (!$(this).closest('.home-chronicle-block').length) {
                var title = $(this).find('.title').detach();
                var images = $(this).find('.images').detach();
   
                // Remove existing .title-images if it exists
                $(this).find('.title-images').remove();
   
                var titleImagesContainer = $('<div class="title-images"></div>').append(images, title);
                $(this).find('.people').after(titleImagesContainer);
            }
        });
   
        // Handle cards in the block view
        $('.home-chronicle-block div.list-container div.card:not(.event)').each(function() {
            // Remove .title-images container if it exists, re-attach .title and .images to their original places
           

Navigation menu