MediaWiki:Common.js: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Tag: Reverted
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 11: Line 18:
});
});
      
      
    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 35: Line 85:
     }
     }
      
      
    // 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 82: Line 169:
                 toggleButton.text('[Close]');
                 toggleButton.text('[Close]');
                 console.log("Filters shown.");
                 console.log("Filters shown.");
                //$('.view-container-buttons').hide();
                //$('div.filtered-view.filtered-list').css('padding-top', '38px');
             } else {
             } else {
                 filtersDiv.attr('style', 'display: none !important');
                 filtersDiv.attr('style', 'display: none !important');
                 toggleButton.text('[Open]');
                 toggleButton.text('[Open]');
                 console.log("Filters hidden.");
                 console.log("Filters hidden.");
                //$('.view-container-buttons').show();
                //$('div.filtered-view.filtered-list').css('padding-top', '0');
             }
             }
         });
         });
     }  
     }  
    // 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 108: Line 243:
         // 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 290: Line 428:
    // 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 476: Line 654:
         $(".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 486: Line 667:
         $(".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 493: Line 677:
         $(".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 500: Line 687:
         $(".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
        // Refresh the page
    location.reload();
     });
     });


Line 506: Line 698:
         $(".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 514: Line 709:
    $(".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 520: Line 718:
    $(".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 526: Line 727:
    $(".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
});
});
// Check if div with class "mw-search-results-info" exists
    if ($('.mw-search-results-info').length) {
        // Select the child <p> element and check its content
        var $paragraph = $('.mw-search-results-info > p');
        var currentText = $paragraph.text().trim();
       
        // Check if the current text is not "There were no results matching the query."
        if (currentText !== "There were no results matching the query.") {
            // Overwrite the content with "Search results"
            $paragraph.text('Pages related to your Search');
        }
    }
   
    // Object to store encountered titles
    var encounteredTitles = {};
    // Iterate over each search result
    $('.mw-search-result-heading').each(function() {
        // Get the title of the current search result
        var title = $(this).find('a').attr('title');
        // Check if the title has already been encountered
        if (encounteredTitles[title]) {
            // Hide the duplicate search result
            $(this).hide();
        } else {
            // Mark the title as encountered
            encounteredTitles[title] = true;
        }
    });
   
    // Remove unwanted white spaces between lines
    $('.mw-search-results-container').contents().filter(function() {
        return this.nodeType === 3; // Filter text nodes
    }).remove();
   
    // Edits regarding Search Results
    // Define the new form HTML as a string
var newFormHtml = '<form action="/index.php" id="searchform">' +
    '<div id="simpleSearchSpecial" class="right-inner-addon">' +
    '<span>[ Search ]</span>' +
    '<input class="form-control" name="search" placeholder="" title="Search [alt-shift-f]" accesskey="f" id="searchInput" tabindex="1" autocomplete="off" type="search">' +
    '<span class="closing-bracket">]</span>' +
    '<input value="Special:Search" name="title" type="hidden">' +
    '</div>' +
    '</form>';
// Replace the div with id="searchText" with the new form
$('#searchText').replaceWith(newFormHtml);
   
    // Target the button based on its complex class structure
    $(".oo-ui-actionFieldLayout-button .oo-ui-buttonInputWidget").remove();
   
    // Make header-box in Home clickable
    $('.head-box').click(function() {
        window.location.href = '/Main_Page'; // Redirects to the home page
    });
});
});

Navigation menu