MediaWiki:Common.js/switchInfobox2.js

// //switch infobox code for newer infoboxes //as generated by Module:Infobox (function {	//shows the infobox corresponding to the given index	var showInfoboxVariant = function(index) {		//for everything that can be changed...		//    the things that can change can be a th, td, or caption tag		$('.infobox-switch th[data-attr-param][data-attr-param!=""], .infobox-switch td[data-attr-param][data-attr-param!=""], .infobox-switch caption[data-attr-param][data-attr-param!=""]').each(function{ var elt = $(this), param = elt.attr('data-attr-param'), //attempt to grab the new version from the infobox resources val = $('.infobox-switch-resources > span[data-attr-param="'+param+'"] > span[data-attr-index="'+index+'"]'); //if it couldn't grab the new one, grab the default if (!val.length) { val = $('.infobox-switch-resources > span[data-attr-param="'+param+'"] > span[data-attr-index="0"]'); }			elt.html(val.html); });	},	//various other vars	$infoboxselect,	$select,	$hash;	//if .infobox-buttons-select is present, turn the buttons into a dropdown	if ($('.infobox-buttons-select').length) {		$infoboxselect = $('.infobox-buttons-select');		$select = $(' ') .attr('id', 'infobox-select')									.attr('name', 'infobox-select');		$infoboxselect.children.each(function { var $this = $(this); var $option = $(' ') .val($this.attr('data-switch-index')) .text($this.text) .attr('data-switch-anchor', '#'+$this.text); $select.append($option); });		$select.change(function (event) { showInfoboxVariant($(event.currentTarget).val); });		//remove all the buttons from the container and replace it with the select		$infoboxselect.empty.append(' Version: ').append($select);	}	//otherwise make the buttons clickable	else {		$("span.button[data-switch-index]").click(function (e) { showInfoboxVariant($(e.target).attr('data-switch-index')); });	}	//unhide the buttons/select	$('.infobox-buttons').show;	//if there's a hash, and it matches text of one of the buttons/options, switch to it on load	if (window.location.hash !== "") {		$hash = $('.infobox-buttons > span[data-switch-anchor="'+window.location.hash+'"], .infobox-buttons > select > option[data-switch-anchor="'+window.location.hash+'"]');		if ($hash.length) {			showInfoboxVariant($hash.val);			$('.infobox-buttons > select').val($hash.val); //change the select as well (silently fails if there isn't a select)		}	} }); //