MediaWiki:Common.js

//Automatically expand pages to full-width on FandomDesktop for unregistered users. //common.js is loaded BEFORE fandomdesktop-expand module, so we attach it to window.load to make sure it works. $(window).on('load', function{	if( (wgUserName === null) && (!$('html').hasClass('is-content-expanded')) ){		$("button.content-size-toggle").click;	} });

$.when( $.ready ).then(function {	/* Document is ready. */

// Disable triggering of new browser tab when clicking URL links that point to internal wiki addresses (purge, edit, etc) $('a[href^="//terraria.fandom.com/"]').removeAttr('target');

// Select links to new tabs for Template:ilnt and Template:elnt $('.linkNewTab a').attr('target','_blank');

// desktop view for mobile screen. $('#mw-panel').append(' '); $('#menu-toggle-button').on('click', function{		$('#mw-panel').toggleClass('on');	}); });

// AJAX tables $.when( $.ready ).then(function {	var l10n = (function($lang, $data){ return function($key){ return ($data[$lang] || $data['en'])[$key] || $data['en'][$key]; }	})(mw.config.get( 'wgPageContentLanguage' ),{ en: { showData: 'show data', wait: 'Please wait, the content is being loaded...', edit: 'edit', hide: 'hide', show: 'show', error: 'Unable to load table; the source article for it might not exist.' },		de: { showData: 'Daten anzeigen', wait: 'Bitte warten, der Inhalt wird geladen...', edit: 'bearbeiten', hide: 'verbergen', show: 'anzeigen', error: 'Kann Tabelle nicht laden; möglicherweise existiert der Quellartikel nicht.' },		fr: { showData: 'affiche les données', wait: 'Veuillez patienter pendant le chargement du contenu...', edit: 'modifier', hide: 'masquer', show: 'afficher', error: 'Impossible de charger cette table; l\'article originel ne semble pas exister.' },		pt: { wait: 'Por favor espere, o conteúdo está sendo carregado...', edit: 'Editar', hide: 'Esconder', show: 'Mostrar', error: 'Não é possível a carregar tabela; o artigo fonte pode não existir.' },		zh: { showData: '显示数据', wait: '请稍候，正在加载内容……', edit: '编辑', hide: '隐藏', show: '显示', error: '无法加载表格，其源文章可能不存在. '		}	});

$("table.ajax").each(function (i) {		var table = $(this).attr("id", "ajaxTable" + i);		table.find(".nojs-message").remove;		var headerLinks = $(' ').appendTo(table.find('th').first);		var cell = table.find("td").first;		var needLink = true;		cell.parent.show;		if (cell.hasClass("showLinkHere")) {			var old = cell.html;			var rep = old.replace(/\[link\](.*?)\[\/link\]/, '$1'); 			if (rep != old) {				cell.html(rep);				needLink = false;			}		}		if (needLink){			headerLinks.html('['+l10n('showData')+']');		}		table.find(".ajax-load-link").parent.andSelf.filter('a').click(function(event) { event.preventDefault; var sourceTitle = table.data('ajax-source-page'), baseLink = mw.config.get('wgScript') + '?'; cell.text(l10n('wait')); $.get(baseLink + $.param({ action: 'render', title: sourceTitle }), function (data) {				if (data) {					cell.html(data);					cell.find('.ajaxHide').remove;					cell.find('.terraria:not(.ajaxForceTerraria)').removeClass('terraria');					if (cell.find("table.sortable").length) {						mw.loader.using('jquery.tablesorter', function { cell.find("table.sortable").tablesorter; });					}					headerLinks.text('[');					headerLinks.append($(''+l10n('edit')+'').attr('href', baseLink + $.param({ action: 'edit', title: sourceTitle })));					headerLinks.append(document.createTextNode(']\u00A0['));					var shown = true;					$(""+l10n('hide')+"").click(function { shown = !shown; shown ? cell.show : cell.hide; $(this).text(shown ? l10n('hide') : l10n('show')); }).appendTo(headerLinks);					headerLinks.append(document.createTextNode(']'));				}			}).error(function {				cell.text(l10n('error'));			}); });	}); });

$(window).on('load', function{	//main page header.	var $btn = $('#box-wikiheader #box-wikiheader-toggle-link');	if($btn.length){		var $box = $('#box-wikiheader');		$btn.css('display', 'inline-block');		if($box.innerHeight > 180){			$box.addClass('collapsed');		}		$btn.on('click', function{ $box.toggleClass('collapsed'); });	}

// translation project banner $btn = $('#indic-project #indic-project-flag'); if($btn.length){ var $text = $('#indic-project'); var $indic = $('#mw-indicator-translation-project'); $btn.css('display', 'inline'); $btn.on('click', function{			$text.toggleClass('collapsed');			$indic.toggleClass('expanded');		}); }

//sidebar height fix. //override left-sidebar resize handle. var $sidebar = $('#mw-panel'); var $wrapper = $('#global-wrapper'); var $footer = $('#curse-footer'); $footer.css('margin-top', '0'); var $top = 0; window.handleResizeEvents = function { var $sidebar_bottom = $sidebar.offset.top + $sidebar.outerHeight(true); var $footer_top = $footer.offset.top; if ($sidebar_bottom > $footer_top - $top){ $top = $sidebar_bottom - $wrapper.offset.top; $wrapper.css('min-height', $top+'px'); }	};	window.handleResizeEvents; });

// Hyperlink required modules in Module namespace // Author: RheingoldRiver $(function {	if (mw.config.get('wgCanonicalNamespace') != 'Module') return;	$('.s1, .s2').each(function { var html = $(this).html; // the module name is surrounded by quotes, so we have to remove them var quote = html[0]; var quoteRE = new RegExp('^' + quote + '|' + quote + '$', 'g'); var name = html.replace(quoteRE, ""); // remove quotes // link the module name if (name.startsWith("Module:")) { var target = encodeURIComponent(name); var url = mw.config.get('wgServer') + mw.config.get('wgScript') + '?title=' + target; var str = quote + '' + name + '' + quote; $(this).html(str); }	}); });

//npcinfobox $(document).ready(function {	$('.infobox .modetabs .tab, .infotable.npc .modetabs .tab').on('click', function{ var $this = $(this); if($this.hasClass('current')){ return; }		$this.parent.children.removeClass('current'); $this.addClass('current'); $this.closest('.infobox, .infotable').removeClass('c-expert c-master c-normal').addClass($this.hasClass('normal')?'c-normal':($this.hasClass('expert')?'c-expert':'c-master')); }); });

//spoiler $(document).ready(function {	$('.spoiler-content').on('click', function{ $(this).toggleClass('show'); }); });

//l10n_data_table(template:l10n_subtemplate) $(document).ready(function {	$('.l10n-data-table th.lang').on('click', function{ var $this = $(this); var lang = $this.attr('lang'); if(lang=='en'){ return; }		$this.closest('table.l10n-data-table').find('td.'+lang).toggleClass('shrinked'); $this.toggleClass('shrinked'); });	$('.l10n-data-table th.all-lang').on('click', function{ var $this = $(this); $this.toggleClass('shrinked'); if($this.hasClass('shrinked')){ $this.closest('table.l10n-data-table').find('td.l, th.lang').addClass('shrinked'); $this.closest('table.l10n-data-table').find('td.en, th.en').removeClass('shrinked'); }else{ $this.closest('table.l10n-data-table').find('td.l, th.lang').removeClass('shrinked'); }	});	//only expand current language	$('.l10n-data-table').each(function{ var $this = $(this); var lang = $this.attr('lang'); if(lang == 'en'){ return; }		var th = $this.find('th.lang.'+lang); if (th.length){ $this.find('th.all-lang').trigger('click'); th.trigger('click'); }	}); });

mw.loader.load('/index.php?title=MediaWiki:HairDyeSliders.js&action=raw&ctype=text/javascript');