} );
}
/**
* OpenStreetMap
* Basato in parte su [[meta:MediaWiki:OSM.js]] e [[fr:MediaWiki:Gadget-osm.js]]
* e ampiamente modificato da [[it:user:Rotpunkt]].
*/
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', 'Nascondi la mappa' )
.text( 'Nascondi' )
.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' ) ) +
'¶ms=' + 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', 'Clicca e trascina per ridimensionare la mappa' )
.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.draggable', 'jquery.ui.resizable'], 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 initOpenStreetMap() {
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', 'Mostrare / nascondere la mappa' )
.text( 'Mappa' )
.click( function ( e ) {
e.preventDefault();
var $osmDiv = $( '#OpenStreetMap' );
if ( $osmDiv.length ) {
$osmDiv.toggle();
} else {
showOpenStreetMap( geohackParams );
}
} );
$coordinates.append( ' (', $toggleAnchor, ')' );
}
}
$( initOpenStreetMap );
/**
|