মিডিয়াউইকি:Gadget-OpenStreetMap.js

উইকিপিডিয়া, মুক্ত বিশ্বকোষ থেকে

লক্ষ্য করুন: প্রকাশ করার পর, পরিবর্তনগুলো দেখতে আপনাকে আপনার ব্রাউজারের ক্যাশে পরিষ্কার করার প্রয়োজন হতে পারে।

  • ফায়ারফক্স / সাফারি: পুনরায় লোড-এ ক্লিক করার সময় শিফট টিপে ধরে রাখুন, অথবা হয় Ctrl-F5 বা Ctrl-R টিপুন (ম্যাকে ⌘-R টিপুন)
  • গুগল ক্রোম: Ctrl-Shift-R (ম্যাকে ⌘-Shift-R) টিপুন
  • ইন্টারনেট এক্সপ্লোরার / এজ: Ctrl ধরে রাখা অবস্থায় Refresh-এ ক্লিক করুন, অথবা Ctrl-F5 টিপুন
  • অপেরা: Ctrl-F5 টিপুন।
/**
 * OpenStreetMap: aggiunge il link "Mappa" a lato delle coordinate visualizzate
 * in alto a destra nelle voci georeferenziate, per aprire la mappa di OpenStreetMap.
 * Basato in parte su [[meta:MediaWiki:OSM.js]] e [[fr:MediaWiki:Gadget-osm.js]]
 * e ampiamente modificato da [[it:User:Rotpunkt]].
 */
/*jshint unused: false */
/*global mediaWiki, jQuery */

( function ( mw, $ ) {
	'use strict';

	function showOpenStreetMap( geohackParams ) {
		var url, $topDiv, $iframe, $osmDiv;
	
		// top div
		$topDiv = $( '<div>' ).css( { position: 'relative', top: '0', width: '100%', height: '10%' } );
		$( '<a>' )
			.attr( 'href', '#' )
			.attr( 'title', 'মানচিত্র বন্ধ করুন' )
			.text( 'বন্ধ করুন' )
			.css( { float: 'right', margin: '10px' } )
			.click( function ( e ) {
				e.preventDefault();
				$( '#OpenStreetMap' ).hide();
			} )
			.appendTo( $topDiv );
	
		// iframe
		url = '//tools.wmflabs.org/wiwosm/osm-on-ol/kml-on-ol.php?' +
			  'lang=' + mw.config.get( 'wgPageContentLanguage' ) +
			  '&uselang=' + mw.util.rawurlencode( mw.config.get( 'wgUserLanguage' ) ) +
			  '&params=' + geohackParams +
			  '&title=' + mw.util.wikiUrlencode( mw.config.get( 'wgTitle' ) ) +
			  ( window.location.protocol === 'https:' ? '&secure=1' : '' );
		$iframe = $( '<iframe>' )
			.attr( 'src', url )
			.css( { width: '100%', height: '90%', clear: 'both' } );
	
		// container div
		$osmDiv = $( '<div>' )
			.attr( 'id', 'OpenStreetMap' )
			.attr( 'title', 'পুনঃআকার করতে ক্লিক করে টেনে আনুন' )
			.css( {
				position : 'absolute',
				zIndex : 5000,
				top: '10%',
				left: '15%',
				width : '70%',
				height : '80%',
				border : '2px solid black',
				backgroundColor : 'white',
				overflow : 'hidden',
				cursor: 'move'
			} )
			.append( $topDiv )
			.append( $iframe );
		mw.loader.using( ['jquery.ui'], function () {
			$osmDiv.draggable();
			$osmDiv.resizable( { minWidth: 150, minHeight: 200 } );
		} );
		$( 'body' ).append( $osmDiv );
	}
	
	// ritorna i parametri geohack, cercandoli nel tag anchor creato dal template coord
	function getGeohackParams() {
		var ret;
		$( '#coordinates a' ).each( function( i, el ) {
			if ( el.href.match( /geohack/ ) && !el.href.match( /(skyhack|_globe:(?!earth))/ ) ) {
				ret = el.href.split( 'params=' )[1];
				return false;
			}
		} );
		return ret;
	}
	
	$( function () {
		var $toggleAnchor, $coordinates = $( '#coordinates' ), geohackParams = getGeohackParams();
		// se è stato utilizzato il template coord e se sono presenti parametri geohack validi
		if ( $coordinates.length && geohackParams ) {
			$toggleAnchor = $( '<a>' )
				.attr( 'href', '#' )
				.attr( 'title', 'মানচিত্র দেখান' )
				.text( 'মানচিত্র' )
				.click( function ( e ) {
					e.preventDefault();
					var $osmDiv = $( '#OpenStreetMap' );
					if ( $osmDiv.length ) {
						$osmDiv.toggle();
					} else {
						showOpenStreetMap( geohackParams );
					}
				} );
	var $img = $( '<img>' );
	$img.attr( {
		'src': '//upload.wikimedia.org/wikipedia/commons/thumb/c/c9/OpenStreetMapLogo.png/17px-OpenStreetMapLogo.png',
		'width': '17px',
		'height': '17px',
		'alt': 'OSM'
	} );
			$coordinates.append( ' | ', $img, ' ', $toggleAnchor);
		}
	} );
}( mediaWiki, jQuery ) );