User:Westgrass/common.js

$(function{	if( mw.config.get("skin") !== "fandomdesktop" ){		return;	}	if("ontouchstart" in window){ // only when this is not registered in common.js		return; 	}	//this is much faster than mw.loadMessage	var l10n = (function{ var $data = { en: { view: 'View', more: 'More', share: 'Share', pagetools: 'Page Tools', //faster then load from right rail which is loaded by ajax "cargo-pagevalues": 'Page values' }		};		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'));

//build page tools on aside (faster than move from right rail) var tools = mw.config.get("wgRailModuleParams"); if(tools){ tools = tools.toolbox; var $box = $(		' '+			''+				' '+l10n('pagetools')+' '+				' '+			' '+			' '+		' ').appendTo($('.fandom-community-header__local-navigation .extra-large-navigation')).find('ul.wds-list'); for(var key in tools){ var item = tools[key]; $('', {					id: item.id,					rel: item.rel,					append: $('', {href: item.href, text: l10n(key) || item.text || item.msg})				}).appendTo($box); }		if($box.children.length === 0){ $box.closest('div.wds-dropdown').remove; }		else{ if($.cookie('hydra-nav-pagetools') == "y"){ $box.closest('.wds-dropdown').toggleClass('collapsed').find('.wds-dropdown__content').css('display', 'none'); }		}	}

//move language to aside: var $languages = $('.page-footer__languages') if($languages.length){ $languages.removeClass('wds-collapsible-panel').addClass('wds-dropdown').attr('data-index', 'languages') .appendTo($('.fandom-community-header__local-navigation .extra-large-navigation')); var $header = $languages.find('.wds-collapsible-panel__header'); $(		''+			' '+$header.text+' </a>'+			'<svg class="wds-icon wds-icon-tiny wds-dropdown__toggle-chevron"><use xlink:href="#wds-icons-dropdown-tiny"> '+		' ').prependTo($languages); $header.remove; $languages.find('.wds-collapsible-panel__content') .removeClass.addClass('wds-dropdown__content wds-is-not-scrollable') .find('a').wrap('</li>'); $languages.find('.wds-dropdown__content li').wrapAll('<ul class="wds-list wds-is-linked"></ul>'); if($.cookie('hydra-nav-languages') == "y"){ $languages.toggleClass('collapsed').find('.wds-dropdown__content').css('display', 'none'); }	}

//click to toggle expand/collapse for local nav dropdown lists: $(".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 $topbar = $('.page-side-tools__wrapper'); if(!$topbar.length){ return; }	var $left = $('<ul class="left-tabs"></ul>').appendTo($topbar); 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($topbar); var $more = $right.find('ul'); var actions = mw.config.get('wgWikiaBarSkinData'); if(actions){ actions = actions.contentActions; //render 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>', {					accesskey: item.accesskey,					id: item.id,					class: item.class|| +(item.exists===false?' new':),					append: $('</a>', {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'); var $moremenu = $more.closest('.wds-dropdown'); //move dropdown to the end. $moremenu.appendTo($right); //language 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" for right tabs? 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'); }	}	//merge my tools bar to top right bar: var $mytools = $('#WikiaBar ul.tools'); $mytools.find('.wds-dropdown li a').each(function(index, element){		if(!$right.find('#ca-'+element.dataset.name).length){			$(element, {id: '#ca-'+element.dataset.name}).appendTo($more).wrap('</li>');		}	}); $mytools.find('li.overflow a').each(function(index, element){		if(!$right.find('#ca-'+element.dataset.name).length){			$(element, {id: '#ca-'+element.dataset.name}).insertBefore($moremenu).wrap('</li>');		}	}) $mytools.find('li.tools-customize').appendTo($right); //remove "more" if it is empty. if($more.children.length == 0){ $moremenu.remove; }	//move wiki-tools__search to topbar:(for UCXsearch) $('.community-header-wrapper .wiki-tools__search').closest('li').appendTo($left); });