User:Westgrass/common.js

$(function{   if( !$('body.skin-fandomdesktop').length ){        return;    }	if("ontouchstart" in window){ // only when this is not registered in common.js		return; 	}	var l10n = (function{ var $data = { en: { view: 'View', more: 'More', share: 'Share' }		};		var $lang = mw.config.get("wgUserLanguage"); return function ($key) { // (null==undefined) is true,(null===undefined) is false return ($data[$lang] && $data[$lang][$key] != null) ? $data[$lang][$key] : $data.en[$key]; };	});	$('.fandom-sticky-header').remove;	//index wiki nav sections:	$(".fandom-community-header__local-navigation .extra-large-navigation > .wds-dropdown").each(function($index, $div){ $div.dataset.index = $index; if($.cookie('hydra-nav-'+$index) == "y"){ $($div).toggleClass('collapsed').find('.wds-dropdown__content').css('display', 'none'); }	});	//move gp logo to top bar	$('.fandom-community-header__top-container').appendTo($('.global-navigation__links'));	//move wiki tools to aside, theme switch to netbar	$('.wiki-tools').first.find('a').removeClass('wds-button').appendTo($('.fandom-community-header__local-navigation .extra-large-navigation>:first-child .wds-list')).wrap('').filter('.wiki-tools__theme-switch').appendTo($('.global-navigation__links'));

//move page tools to aside $("#WikiaRail").on("afterLoad.rail", function{		var $pageTools = $('#p-tb');		if(!$pageTools.length){			return;		}		var $t = $('  '+$pageTools.find('h2').text+'    ');		$t.find("div.wds-dropdown__content").append($pageTools.find('ul').clone.removeClass.addClass('wds-list wds-is-linked'));		if($.cookie('hydra-nav-pagetools') == "y"){			$t.toggleClass('collapsed').find('.wds-dropdown__content').css('display', 'none');		}		var $f = $('.fandom-community-header__local-navigation .extra-large-navigation .page-footer__languages');		if($f.length){			$t.insertBefore($f);		}		else{			$t.appendTo($('.fandom-community-header__local-navigation .extra-large-navigation')); }			});	//move language to aside:	var $l = $('.page-footer__languages').removeClass('wds-collapsible-panel').addClass('wds-dropdown').attr('data-index', 'languages').appendTo($('.fandom-community-header__local-navigation .extra-large-navigation'));	var $h = $l.find('.wds-collapsible-panel__header');	$l.prepend($(' '+$h.text+'  '));	$h.remove;	$l.find('.wds-collapsible-panel__content').removeClass.addClass('wds-dropdown__content wds-is-not-scrollable').find('a').wrap('');	$l.find('.wds-dropdown__content li').wrapAll('');	if($.cookie('hydra-nav-languages') == "y"){		$l.toggleClass('collapsed').find('.wds-dropdown__content').css('display', 'none'); }

//local nav dropdown lists workaround: $(".fandom-community-header__local-navigation").on("click", '.wds-dropdown__toggle.first-level-item', function(event){		event.stopPropagation;		var $item = $(this).closest('.wds-dropdown');		$item.toggleClass('collapsed').find('.wds-dropdown__content').slideToggle('fast');       $.cookie('hydra-nav-' + $item[0].dataset.index, $item.hasClass('collapsed')?"y":"n", { expires: 365, path: '/' });	});	//top bars var $box = $('.page-side-tools__wrapper'); if(!$box.length){ return; }	var $left = $('</ul>').appendTo($box); var $right = $('<ul class="right-tabs"><li class="wds-dropdown"><div class="wds-dropdown__toggle"> '+l10n('more')+' <svg class="wds-icon wds-icon-tiny wds-dropdown__toggle-chevron"><use xlink:href="#wds-icons-dropdown-tiny"> <div class="wds-dropdown__content"><ul class="wds-list wds-is-linked"></ul> </li></ul>').appendTo($box); var $more = $right.find('ul'); var actions = mw.config.get('wgWikiaBarSkinData').contentActions; //other items: if(actions['cargo-purge'] && actions.purge){ delete actions['cargo-purge']; }	var $target = $left; for(var key in actions){ var item = actions[key]; if(key == 'edit' || key == 'viewsource'){ $target = $right; }		else if(item.id == 'ca-delete' || item.id == 'ca-move' || item.id == 'ca-purge' || item.id == 'ca-protect' || item.id == 'ca-cargo-purge'){ $target = $more; }		if(key == 'share'){ $('<li class="wds-dropdown" id="ca-share"><div class="wds-dropdown__toggle"> '+l10n('share')+' <svg class="wds-icon wds-icon-tiny wds-dropdown__toggle-chevron"><use xlink:href="#wds-icons-dropdown-tiny"> <div class="wds-dropdown__content"> </li>').appendTo($left).find('.wds-dropdown__content').append($(item.html)); }		else{ $('</li>').attr('accesskey', item.accesskey).attr('id', item.id).addClass(item.class+(item.exists===false?' new':'')).append($('</a>').attr('href', item.href).text(item.text)).appendTo($target); $('#p-cactions #'+item.id).closest('li').remove; }	}	//anything left in "old" dropdown list? $('#p-cactions ul li').appendTo($more); $('#p-views').remove; $more.attr('id', 'p-cactions'); $right.attr('id', 'p-views'); //move dropdown to the end. $right.find('.wds-dropdown').appendTo($right); //variants var $v = $('.page-header__top .page-header__variants .wds-dropdown'); if($v.length){ var $t = $('<li class="wds-dropdown" id="p-variants"></li>').append($v.children).appendTo($left).find('.wds-dropdown__toggle'); $($t[0].firstChild).wrap(' ') $left.find('#ca-share').appendTo($left); }	//need "view"? if(actions.edit || actions.viewsource){ var $view = $left.find('.selected').clone.attr('id', 'ca-view').prependTo($right); $view.find('a').text(l10n('view')); if($right.find('.selected').length){ $view.removeClass('.selected'); }	}

});

$.when(mw.loader.using(["mediawiki.api", "mediawiki.jqueryMsg"])).then(function{   return new mw.Api.loadMessagesIfMissing(["searchsuggest-search", "tooltip-search", "tooltip-search-go", "search-modal-see-all-results"]); }).then(function{	if(window.UCXSEARCHBARLoaded || mw.config.get("skin") !== "fandomdesktop"){		return;	}	window.UCXSEARCHBARLoaded = true;	var ScriptPath = mw.config.get("wgScriptPath");

var search_form = $(" ", {		class: "wiki-tools__search-container wds-dropdown",		action: ScriptPath + "/wiki/Special:Search",		append: [			$(" ", { class: "wiki-tools__search-input", type: "search", name: "search", placeholder: mw.msg("searchsuggest-search"), title: mw.msg("tooltip-search"), autocomplete: "off" }),			$(" ", {				type: "hidden", name: "title", value: "Special:Search" }),			$(" ", {				class: "wiki-tools__search-button wds-button wds-is-secondary", type: "submit", title: mw.msg("tooltip-search-go"), append: $('<svg class="wds-icon wds-icon-small"><use xlink:href="#wds-icons-magnifying-glass-small"> ') }),			$(" ", {				class: "wiki-tools__search-linksuggest-list wds-dropdown__content wds-is-not-scrollable", style: "display: none !important;", append: $("<ul>", {					class: "wds-list wds-is-linked"				}) })		]	});

$(".wiki-tools").addClass("wiki-tools__ucxsearch"); // trigger hiding of fake search box to prevent content shift $(".wiki-tools__search").replaceWith(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(function(suggestion){ $(container_selector + " .wiki-tools__search-linksuggest-list > ul").append($("", { title: suggestion, append: $('' + suggestion.replace(new RegExp("(" + search_query + ")", "gi"), "$1") + "</a>") }));			});			$(container_selector + " .wiki-tools__search-linksuggest-list > ul").append($("", {				append: $("", { class: "wiki-tools__search-linksuggest-list-see-all", href: ScriptPath + "/wiki/Special:Search?query=" + search_query, text: 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;");			}		}	}); });