MediaWiki:Gadget-map-toggler.js

Z Wikipedii, wolnej encyklopedii

Uwaga: aby zobaczyć zmiany po opublikowaniu, może zajść potrzeba wyczyszczenia pamięci podręcznej przeglądarki.

  • Firefox / Safari: Przytrzymaj Shift podczas klikania Odśwież bieżącą stronę, lub naciśnij klawisze Ctrl+F5, lub Ctrl+R (⌘-R na komputerze Mac)
  • Google Chrome: Naciśnij Ctrl-Shift-R (⌘-Shift-R na komputerze Mac)
  • Internet Explorer / Edge: Przytrzymaj Ctrl, jednocześnie klikając Odśwież, lub naciśnij klawisze Ctrl+F5
  • Opera: Naciśnij klawisze Ctrl+F5.
/**
 * Przełączanie map w infoboksach, jeśli są dwie lub więcej.
 * Modyfikacja kodu wspierającego Szablon:Galeria.
 */
jQuery(document).ready(function(){
	// Don't do anything in the printable version.
	if(location.search.match(/[?&]printable=yes/)) return;

	mw.loader.using('mediawiki.util', function() {
		mw.util.addCSS(
			// And hide effects if "non-printable" page is printed.
			'@media print{ .locationmap-infobox-toggle-button {display: none} }' +
			// Regular styles.
			'.locationmap-infobox-toggle-button {margin:0; font-size:80%; font-weight:normal; line-height:1.5em}'
		);
	})

	function toggleMap (group, remindex, shwindex) {
		jQuery("#infobox-" + group + "-locationmap-" + remindex).hide();
		jQuery("#infobox-" + group + "-locationmap-" + shwindex).show();
	}
	jQuery('table.infobox').each(function(i, group) {
		var maps = jQuery(group).children('tbody').children('tr.infobox-locationmap');
		var count = maps.get().length;
		if (count <= 1) {
			return 1;
		}
		var mapNames = []
		maps.each(function(j, currentmap){
			var titleNode = jQuery(currentmap).children('td:first-child()').children('div:first-child()').children('div').get(0);
			var text = jQuery(titleNode).text();
			var mapName = text.replace('Położenie na mapie ', '');
			mapNames[j] = mapName;
		});
		maps.each(function(j, currentmap) {
			jQuery(currentmap).attr('id', "infobox-" + i + "-locationmap-" + j);
			var nextlink = jQuery('<a href="#"/>');
			var nextmap = (j + 1) % count;
			nextlink.text('Przełącz na mapę ' + mapNames[nextmap]).click(function() {
				toggleMap(i, j, nextmap); return false;
			});
			var titleNode = jQuery(currentmap).children('td:first-child()').children('div:first-child()').children('div').get(0);
			jQuery('<div/>').addClass('locationmap-infobox-toggle-button')
				.append('(')
				.append(nextlink)
				.append(')')
				.appendTo(jQuery(titleNode));
			if (j != 0) {
				jQuery(currentmap).hide().addClass('noprint');
			}
		});
	});
});