MediaWiki:Gadget-wiwosm.js
Megjegyzés: közzététel után frissítened kell a böngésződ gyorsítótárát, hogy lásd a változásokat.
- Firefox / Safari: tartsd lenyomva a Shift gombot és kattints a Frissítés gombra a címsorban, vagy használd a Ctrl–F5 vagy Ctrl–R (Macen ⌘–R) billentyűkombinációt
- Google Chrome: használd a Ctrl–Shift–R (Macen ⌘–Shift–R) billentyűkombinációt
- Edge: tartsd nyomva a Ctrl-t, és kattints a Frissítés gombra, vagy nyomj Ctrl–F5-öt
/**
* Using OpenStreetMap in Wikipedia.
*
* @author Magnus Manske, 2008
* heavily altered by [[m:User:Danmichaelo]], [[m:User:Hoo man]]
* @license GPL
* @source https://meta.wikimedia.org/wiki/MediaWiki:OSM.js
* @see https://wiki.openstreetmap.org/wiki/WIWOSM
*/
osm_proj_lang = 'hu'; // project language
function openStreetMapToggle() {
var $a = $( '#coordinates a' ),
link = '',
url = '',
params;
if ( !$a.length ) {
return;
}
if ( $( '#openstreetmap' ).length ) {
$( '#openstreetmap' ).toggle();
return false;
}
$a.each( function () {
if ( this.href.indexOf( 'geohack' ) > -1 ) {
link = this.href;
return false; // break
}
} );
if ( link ) {
params = link.match( /params=([^?&]*)/ ) || link.match( /geohack\/[a-z]{2,5}\/([^?&]*)/ );
params = params && params[ 1 ];
}
if ( !params ) {
return false; // No geohack link found
}
url = 'https://wiwosm.toolforge.org/osm-on-ol/kml-on-ol.php?'
+ 'lang=' + osm_proj_lang
+ '&uselang=' + mw.config.get('wgUserLanguage')
+ '¶ms=' + params
+ '&title=' + mw.util.wikiUrlencode( mw.config.get( 'wgTitle' ) )
+ '&secure=1';
$( '<iframe>' )
.attr( 'src', url )
.attr( 'id', 'openstreetmap' )
.appendTo( '#contentSub' );
return false;
}
/**
* Remove #openstreetmap while initializing. Since it's in #contentSub, it isn't
* removed while generating a new live preview, therefore doesn't reflect
* coordinate changes.
*/
function cleanup() {
if ( $( '#openstreetmap' ).length ) {
$( '#openstreetmap' ).remove();
}
}
function createLink( $content ) {
var $a = $( '#coordinates a' ),
geohack = false;
if ( !$a.length ) return;
$a.each( function () {
if ( this.href.indexOf( 'geohack' ) > -1 && this.href.indexOf( '_globe:' ) === -1 ) {
// no OSM for Moon, Mars etc.
geohack = true;
return false;
}
} );
if ( !geohack ) return;
$( '<a>' )
.attr( 'href', '#' )
.attr( 'id', 'coordinates_map' )
.text( 'térkép ▼' )
.click( openStreetMapToggle )
.appendTo( $( '#coordinates' ) );
$( cleanup ); // remove #openstreetmap if present
}
mw.hook( 'wikipage.content' ).add( createLink ); // find absulutely positioned links