User:Philo04/global.js

$.when($.ready, mw.loader.using(["mediawiki.api", "mediawiki.jqueryMsg"])).then(function{       return new mw.Api.loadMessagesIfMissing(["search-modal-see-all-results"]);    }).then(function{	var search_icon = $('  ');

var search_form = $(" ") .addClass("wiki-tools__search-container") .addClass("wds-dropdown") .attr("action", "/wiki/Special:Search");

var search_box = $(" ") .addClass("wiki-tools__search-input") .attr("type", "search") .attr("name", "search") .attr("placeholder", "Search " + mw.config.get('wgSiteName')) .attr("title", "Search " + mw.config.get('wgSiteName')) .attr("autocomplete", "off");

var search_hidden = $(" ") .attr("type", "hidden") .attr("name", "title") .attr("value", "Special:Search");

var search_button = $(" ") .addClass("wiki-tools__search-button") .addClass("wds-button") .addClass("wds-is-secondary") .attr("type", "submit") .attr("name", "go") .attr("value", "Go") .attr("title", "Go to a page with this exact name if it exists") .append(search_icon);

var search_linksuggest_box = $("") .addClass("wds-list") .addClass("wds-is-linked");

var search_linksuggest_box_div = $(" ") .addClass("wiki-tools__search-linksuggest-list") .addClass("wds-dropdown__content") .addClass("wds-is-not-scrollable") .attr("style", "display: none !important;") .append(search_linksuggest_box);

search_form.append(search_box, search_hidden, search_button, search_linksuggest_box_div);

$("div.wiki-tools.wds-button-group").prepend(search_form);

function update_linksuggest(container_selector){ var search_query = $(container_selector +" .wiki-tools__search-input").val.trim; if(!search_query){ $(container_selector + " .wiki-tools__search-linksuggest-list").attr("style", "display: none !important;"); return; }		new mw.Api.get({			action: "linksuggest",			get: "suggestions",			query: search_query,			format: "json"		}).then(function(data){			$(container_selector + " .wiki-tools__search-linksuggest-list > ul").empty;			data.linksuggest.result.suggestions.forEach(suggestion => { $(container_selector + " .wiki-tools__search-linksuggest-list > ul").append($("")					.attr("title", suggestion)					.append($('' + suggestion.replace(new RegExp("(" + search_query + ")", "gi"), "$1") + ""))				); });			$(container_selector + " .wiki-tools__search-linksuggest-list > ul").append($("") .append($('' + mw.msg("search-modal-see-all-results", search_query) + "")) );			$(container_selector + " .wiki-tools__search-linksuggest-list").attr("style", "display: block !important;");		}); }

var pause_event = false; var pause_event_sticky_header = false;

$(".fandom-community-header__top-container .wiki-tools__search-input").on("change keyup paste", function{		if(!pause_event){			pause_event = true;			update_linksuggest(".fandom-community-header__top-container");			pause_event = false;		}	});

$(".fandom-sticky-header .wiki-tools__search-input").on("change keyup paste", function{		if(!pause_event_sticky_header){			pause_event_sticky_header = true;			update_linksuggest(".fandom-sticky-header");			pause_event_sticky_header = false;		}	});

$(window).on("click", function(event){		if($(".fandom-community-header__top-container .wiki-tools__search-linksuggest-list").attr("style") == "display: block !important;"){			if(!$(".fandom-community-header__top-container .wiki-tools__search-container").get(0).contains(event.target)){				$(".fandom-community-header__top-container .wiki-tools__search-linksuggest-list").attr("style", "display: none !important;");			}		}		if($(".fandom-sticky-header .wiki-tools__search-linksuggest-list").attr("style") == "display: block !important;"){			if(!$(".fandom-sticky-header .wiki-tools__search-container").get(0).contains(event.target)){				$(".fandom-sticky-header .wiki-tools__search-linksuggest-list").attr("style", "display: none !important;");			}		}	}); });