MediaWiki:Common.js: Difference between revisions

From Seven Sages of Rome
No edit summary
No edit summary
Line 1: Line 1:
mw.loader.load('jquery.ui');
function drilldownswitcher() {
function drilldownswitcher() {
     $('#drilldown-switch:contains("Show all filters")').length ? ($(".drilldown-filter-values:has(a)").css("display", "block"),
     $('#drilldown-switch:contains("Show all filters")').length ? ($(".drilldown-filter-values:has(a)").css("display", "block"),
Line 40: Line 38:
})
})
$(document).ready(function () {
$(document).ready(function () {
     // Get page titles from the hidden div
     // Retrieve page titles from hidden div
     var pageTitles = $("#pageList").text().split(',');
     var pageTitles = $("#pageList").text().split(',');


     // Initialize autocomplete on the input field
     // Input and suggestions list elements
     $("#targetPageInput").autocomplete({
    var $input = $("#targetPageInput");
         source: pageTitles,
    var $suggestions = $("#autocomplete-suggestions");
         minLength: 2 // Minimum characters before suggestions appear
 
    // Show suggestions based on input
     $input.on("input", function () {
        var query = $(this).val().toLowerCase().trim();
        $suggestions.empty().hide();
 
        if (query.length < 2) return; // Start showing suggestions from 2 characters
 
        // Filter page titles
        var matches = pageTitles.filter(function (title) {
            return title.toLowerCase().indexOf(query) !== -1;
         });
 
        // Display matching suggestions
        if (matches.length > 0) {
            matches.forEach(function (match) {
                $("<li>").text(match).appendTo($suggestions)
                    .on("click", function () {
                        $input.val($(this).text());
                        $suggestions.empty().hide();
                    });
            });
            $suggestions.show();
         }
    });
 
    // Hide suggestions when clicking outside
    $(document).on("click", function (e) {
        if (!$(e.target).closest("#autocomplete-container").length) {
            $suggestions.empty().hide();
        }
     });
     });
});
});

Revision as of 20:11, 13 November 2024

function drilldownswitcher() {
    $('#drilldown-switch:contains("Show all filters")').length ? ($(".drilldown-filter-values:has(a)").css("display", "block"),
            $(".drilldown-values-toggle").each(function () {
                $("img").each(function () {
                    $(this).attr("src", $(this).attr("src").replace("right-arrow.png", "down-arrow.png"));
                });
            }),
            (document.getElementById("drilldown-switch").innerHTML = 'Hide all filters <i class="fa fa-minus"></i>'))
        : $('#drilldown-switch:contains("Hide all filters")').length &&
        ($(".drilldown-filter-values:has(a)").css("display", "none"),
            $(".drilldown-values-toggle").each(function () {
                $("img").each(function () {
                    $(this).attr("src", $(this).attr("src").replace("down-arrow.png", "right-arrow.png"));
                });
            }),
            (document.getElementById("drilldown-switch").innerHTML = 'Show all filters <i class="fa fa-plus"></i>'));
}
$(document).ready(function () {
    $(".drilldown-results").css({ "-webkit-filter": "blur(0)", "-moz-filter": "blur(0)", "-o-filter": "blur(0)", "-ms-filter": "blur(0)", filter: "blur(0)" }), $(".drilldown-filter-values:has(a)").css("display", "none");
    $('<br /><h3 class="drilldown-pre-header">1. Selected Filters</h3>').insertBefore("#drilldown-applied-filters"),
    $('<h3 class="drilldown-pre-filters">2. Available Filters</h3>').insertBefore("#drilldown-applicable-filters"),
    $('<h3 class="drilldown-post-filters">3. Filtered Results</h3>').insertAfter("#drilldown-applicable-filters"),
    $('<html><div class="drilldown-btn-wrapper"><a class="btn primary-btn" href="javascript:;" onclick="drilldownswitcher()" id="drilldown-switch">Show all filters <i class="fa fa-plus"></i></a></div></html>').insertBefore("#drilldown-filters");
    $(".drilldown-values-toggle").each(function () {
    	$("img").each(function () {
        	$(this).attr("src", $(this).attr("src").replace("down-arrow.png", "right-arrow.png"));
    	});
    });

    if( mw.storage.get( "wip-dismissed" ) === null || JSON.parse(mw.storage.get( "wip-dismissed" )) === false){
    	$( ".wip-alert" ).fadeIn( "slow", function() {});
    }
    
    $( "#close-wip" ).on( "click", function() {
	  mw.storage.set( "wip-dismissed", true );
	  $( ".wip-alert" ).fadeOut( "slow", function() {});
    } );
})
$(document).ready(function () {
    // Retrieve page titles from hidden div
    var pageTitles = $("#pageList").text().split(',');

    // Input and suggestions list elements
    var $input = $("#targetPageInput");
    var $suggestions = $("#autocomplete-suggestions");

    // Show suggestions based on input
    $input.on("input", function () {
        var query = $(this).val().toLowerCase().trim();
        $suggestions.empty().hide();

        if (query.length < 2) return; // Start showing suggestions from 2 characters

        // Filter page titles
        var matches = pageTitles.filter(function (title) {
            return title.toLowerCase().indexOf(query) !== -1;
        });

        // Display matching suggestions
        if (matches.length > 0) {
            matches.forEach(function (match) {
                $("<li>").text(match).appendTo($suggestions)
                    .on("click", function () {
                        $input.val($(this).text());
                        $suggestions.empty().hide();
                    });
            });
            $suggestions.show();
        }
    });

    // Hide suggestions when clicking outside
    $(document).on("click", function (e) {
        if (!$(e.target).closest("#autocomplete-container").length) {
            $suggestions.empty().hide();
        }
    });
});