User:Philo04/global.js

(function{	var conf = mw.config.get([ "skin", "wgScriptPath", "wgSiteName" ]);	if (conf.skin !== "fandomdesktop" || window.UCXSearchBarLoaded){		return;	}	window.UCXSearchBarLoaded = true;

var search_icon = $(' ');

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

var search_box = $(" ") .addClass("wiki-tools__search-input") .attr("type", "search") .attr("name", "search") .attr("placeholder", "Search " + conf.wgSiteName) .attr("title", "Search " + conf.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);

$(".wiki-tools__search").replaceWith(search_form); $.when(mw.loader.using(["mediawiki.api", "mediawiki.jqueryMsg"])).then(function{		return new mw.Api.loadMessagesIfMissing(["search-modal-see-all-results", "tooltip-search", "tooltip-search-go"]);	}).then(function{		$(".wiki-tools__search-input")			.attr("placeholder", mw.msg("tooltip-search"))			.attr("title", mw.msg("tooltip-search"));		$(".wiki-tools__search-button")			.attr("title", mw.msg("tooltip-search-go"));	});

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(function(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;");		}); }

$(".fandom-community-header__top-container .wiki-tools__search-input").on("input paste", function{		update_linksuggest(".fandom-community-header__top-container");	});

$(".fandom-sticky-header .wiki-tools__search-input").on("input paste", function{		update_linksuggest(".fandom-sticky-header");	});

$(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;");			}		}	}); });