Aller au contenu

MediaWiki:Gadget-osm.js

Une page de Wikipédia, l'encyclopédie libre.
Ceci est une version archivée de cette page, en date du 22 septembre 2014 à 03:27 et modifiée en dernier par Arkanosis (discuter | contributions) (9 révisions importées depuis de:MediaWiki:Gadget-osm.js : Import de la dernière version sous forme de gadget pour bénéficier des avantages de ResourceLoader). Elle peut contenir des erreurs, des inexactitudes ou des contenus vandalisés non présents dans la version actuelle.
Note : après avoir enregistré la page, vous devrez forcer le rechargement complet du cache de votre navigateur pour voir les changements.

Mozilla / Firefox / Konqueror / Safari : maintenez la touche Majuscule (Shift) en cliquant sur le bouton Actualiser (Reload) ou pressez Maj-Ctrl-R (Cmd-R sur Apple Mac) ;

Firefox (sur GNU/Linux) / Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5.
/**
 * Verwendung von OpenStreetMap in Wikipedia.
 * (c) 2008 by Magnus Manske, Released under GPL
 */
mw.loader.using( [ 'mediawiki.util' ], function() { $( function() {
	var c = $( '#coordinates' );
	if ( !c.length ) {
		return;
	}

	var a = c.find( 'a' );
	var geohack = false;
	for (var i = 0; i < a.length; i++) {
		var h = a[i].href;
		if (!h.match(/geohack/)) continue;
		if (h.match(/skyhack/)) continue;
		if (h.match(/_globe:/)) continue; // no OSM for moon, mars, etc
		geohack = true;
		break;
	}
	if ( !geohack ) {
		return;
	}

	var separator = $( document.createElement( 'span' ) );
	separator.text( ' | ' );
	separator.attr( 'class', 'noprint coordinates-separator' );
	c.append( separator );
	var img = $( document.createElement( 'img' ) );
	img.attr( {
		'src': '/media/wikipedia/commons/thumb/c/c9/OpenStreetMapLogo.png/17px-OpenStreetMapLogo.png',
		'width': '17px',
		'height': '17px'
	} );
	var a = $( document.createElement( 'a' ) );
	a.attr( {
		'href': '#',
		'title': 'Zeige Koordinaten auf einer Karte von OpenStreetMap',
		'class': 'noprint osm-icon-coordinates'
	} );
	a.click( function () {
		var c = $( '#coordinates' );
		if ( !c.length) {
			return;
		}
		var cs = $( '#contentSub' );
		var osm = $( '#openstreetmap' );

		if ( cs.length && osm.length ) {
			if ( osm.css( 'display' ) === 'none' ) {
				osm.css( 'display', 'block' );
			} else {
				osm.css( 'display', 'none' );
			}
			return false;
		}

		var found_link = false;
		var a = c.find( 'a' );
		var h;
		for (var i = 0; i < a.length; i++) {
			h = a[i].href;
			if (!h.match(/geohack/)) continue;
			found_link = true;
			break;
		}
		if ( !found_link ) {
			return; // No geohack link found
		}

		h = h.split('params=')[1];

		var url = '//tools.wmflabs.org/wiwosm/osm-on-ol/kml-on-ol.php?lang=de&uselang='
			+ mw.util.rawurlencode( mw.config.get( 'wgUserLanguage' ) )
			+ '&params=' + h
			+ '&title=' + mw.util.wikiUrlencode( mw.config.get( 'wgTitle' ) );

		var iframe = $( document.createElement( 'iframe' ) );
		iframe.attr( 'id', 'openstreetmap' );
		iframe.css({
			'width': '100%',
			'height': '350px',
			'clear': 'both'
		});
		iframe.attr( 'src', url );
		cs.append( iframe );
		return false;
	});
	a.append( img );
	c.append( a );
})});