User:Westgrass/common.js

$(function{

//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',				'recentchangeslinked': 'Related changes'			}		};		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];		};	});

(function{	//top nav bar

var $topbar = $('.page-side-tools__wrapper'); if(!$topbar.length){ return; } $topbar.empty;

var $left = $('').appendTo($topbar); var $right = $(		''+			''+				' ' + l10n('more') + '  '+				' '+			''+		'').appendTo($topbar); var $more = $right.find('ul'); var $cactions = $('#cactions'); var actions = mw.config.get('wgWikiaBarSkinData'); if(actions){ actions = actions.contentActions; if(actions['cargo-purge'] && actions.purge){ delete actions['cargo-purge']; }		var $target = $left; Object.keys(actions).forEach(function(key){			if(key.substring(0,8) === 'varlang-'){ return; } //skip language variants			var item = actions[key];			if(key === 'share'){				$(''+ ''+ ' '+l10n('share')+' '+ ' '+ ' '+					'<div class="wds-dropdown__content"> '+ '</li>').appendTo($left).find('.wds-dropdown__content').html(item.html);				return;			}			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'){				$target = $more;			}			var z = $('#p-cactions #'+item.id);			if(z.length){				z.closest('li').appendTo($target); //reuse the item from the dropdown list			}			else{				//build a new one				var a = $('<a></a>', { accesskey: item.accesskey, id: item.id, class: (item.class||) + (item.exists===false?' new':), href: item.href, text: item.text, }).appendTo($target).wrap('</li>');				if(item.data){					Object.keys(item.data).forEach(function(index) { a.attr('data-'+index, item.data[index]); });				}			}		});	}	//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. var $more_menu = $more.closest('.wds-dropdown').appendTo($right);

return; //take watch/unwatch out from "more" $more.find('.mw-watchlink').closest('li').insertBefore($more_menu);

//language variants var $v = $('.page-header__top .page-header__variants .wds-dropdown'); if($v.length){ var $t = $('</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 > 1){ $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){		var $element = $(element);		if(!$right.find( '#'+$element.attr('id') || '#ca-'+$element.attr('data-name')).length){			$element.appendTo($more).wrap('</li>').attr('id', 'ca-'+$element.attr('data-name'));		}	}); $mytools.find('li.overflow a').each(function(index, element){		var $element = $(element);		if(!$right.find( '#'+$element.attr('id') || '#ca-'+$element.attr('data-name')).length){			$element.insertBefore($more_menu).wrap('</li>').attr('id', 'ca-'+$element.attr('data-name'));		}	}); if($more.children.length){ mw.loader.using("ext.fandom.wikiaBar.js").then(function{			$more.append($mytools.find('li.tools-customize'));		}); }	else{ $more_menu.remove; }

});

//move wiki-tools__search to topbar:(for UCXsearchbar. still need some css to make it work.) $('.community-header-wrapper .wiki-tools__search').insertAfter($left).wrap(' ');

});