MediaWiki:MediaWiki:OSM.js

De Hispanopedia
Revisión del 22:22 12 oct 2025 de Supremo (discusión | contribs.) (Página creada con «global $, mw: // Using OpenStreetMap in Wikipedia. // (c) 2008 by Magnus Manske // heavily altered by m:User:Danmichaelo, m:User:Hoo man, m:User:Simon04 // Released under GPL mw.loader.using('mediawiki.util', function() { // toogle map function openStreetMapToggle() { let a = $( '#coordinates a' ), link = '', url = ''; if (a.length === 0) { return; } let $mapBox = $('#openstreetmap-container') if ($mapBox.length > 0) { $mapBo…»)
(difs.) ← Revisión anterior | Revisión actual (difs.) | Revisión siguiente → (difs.)

Nota: Después de publicar, quizás necesite actualizar la caché de su navegador para ver los cambios.

  • Firefox/Safari: Mantenga presionada la tecla Shift mientras pulsa el botón Actualizar, o presiona Ctrl+F5 o Ctrl+R (⌘+R en Mac)
  • Google Chrome: presione Ctrl+Shift+R (⌘+Shift+R en Mac)
  • Edge: mantenga presionada Ctrl mientras pulsa Actualizar, o presione Ctrl+F5
/* global $, mw */
// Using OpenStreetMap in Wikipedia.
// (c) 2008 by Magnus Manske
// heavily altered by [[m:User:Danmichaelo]], [[m:User:Hoo man]], [[m:User:Simon04]]
// Released under GPL

mw.loader.using('mediawiki.util', function() {
	// toogle map
	function openStreetMapToggle() {
		let a = $( '#coordinates a' ),
			link = '',
			url = '';
		if (a.length === 0) {
			return;
		}

		let $mapBox = $('#openstreetmap-container')
		if ($mapBox.length > 0) {
			$mapBox.toggle();
			let isVisible = !$mapBox.is(':hidden');
			$(this)
				.toggleClass('opened', isVisible)
				.attr('aria-expanded', isVisible)
			;
			return false;
		}
		
		$.each(a, function(index, value) {
			if ( value.href.indexOf('geohack') === -1 ) {
				return true; // Returning non-false is the same as a continue
			}
			link = value.href;
			return false; // break
		});
		if (link === '') {
			return false; // No geohack link found
		}
		
		url = 'https://wiwosm.toolforge.org/osm-on-ol/kml-on-ol.php?lang=' + mw.config.get('osm_proj_lang') + '&uselang=' + mw.config.get('wgUserLanguage') + '&params=' + link.split('params=')[1] + '&title=' + mw.util.wikiUrlencode( mw.config.get( 'wgTitle' ) ) + '&secure=1';
		$('#contentSub').append(
			$('<div>').attr('id', 'openstreetmap-container').css({
				width: '100%',
				height: Math.max(Math.floor($(window).height() / 2), 350) + 'px',
				clear: 'both',
				'padding-bottom': '15px',
				'border-bottom': '1px solid #a2a9b1',
				'box-sizing': 'border-box',
				resize: 'vertical',
				overflow: 'hidden'
			}).append(
				// src has to be passed using .attr as it could contain malicious html!
				$('<iframe>').attr('id', 'openstreetmap').attr('src', url).css({
					border: '1px solid #a2a9b1',
					'box-sizing': 'border-box',
					width: '100%',
					height: '100%'
				})
			)
		);
		$(this).addClass('opened');
		
		return false;
	}

	// init GUI
	$(function() {
		let a = $('#coordinates a'),
			geohack = false;
		if (a.length === 0) {
			return;
		}

		$.each(a, function(index, value) {
			if ( value.href.indexOf('geohack') === -1 ) {
				return true;
			}
			if (value.href.indexOf('_globe:') !== -1) {
				return true; // no OSM for moon, mars, etc
			}
			geohack = true;
			return false;
		});
		if (!geohack) {
			return;
		}

		$('#coordinates').append(
			mw.config.get('osm_proj_map_prefix', ' ('),
			$('<a>')
				.attr('id', 'coordinates_map')
				.attr('aria-expanded', 'false')
				.attr('aria-controls', 'openstreetmap-container')
				.attr('href', '#')
				.append(mw.config.get('osm_proj_map'))
				.on('click', openStreetMapToggle)
			,
			mw.config.get('osm_proj_map_postfix', ')   ')
		);
	});
});