User:Danmichaelo/Sandbox.js
Appearance
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
// Using OpenStreetMap in Wikipedia.
// (c) 2008 by Magnus Manske
// Released under GPL
function openStreetMapToggle () {
var a = $( '#coordinates a' ),
osm_secure = '',
link = '',
url = '';
if (a.length === 0) {
return;
}
if ($('#openstreetmap').length > 0) {
$('#openstreetmap').toggle();
return false;
}
$.each(a, function(index, value) {
if ( !value.href.match( /geohack/ ) ) {
return true; // Returning non-false is the same as a continue
}
link = value.href;
return false; // break
});
if ( link === '' ) {
return ; // No geohack link found
}
if ( window.location.protocol === 'https:' ) {
osm_secure = '&secure=1';
}
url = '//toolserver.org/~kolossos/openlayers/kml-on-ol.php?lang=' + osm_proj_lang + '&uselang=' + wgUserLanguage + '¶ms=' + link.split('params=')[1] + '&title=' + mw.util.wikiUrlencode( mw.config.get( 'wgTitle' ) ) + osm_secure ;
$('#contentSub').append('<iframe id="openstreetmap" src="' + url + '" style="width:100%; height: 350px; clear:both;"></iframe>');
return false ;
}
function openStreetMapInit () {
var a = $('#coordinates a'),
geohack = false;
if (a.length === 0) {
return;
}
$.each(a, function(index, value) {
if ( !value.href.match( /geohack/ ) ) {
return true;
}
if (value.href.match(/_globe:/)) {
return true; // no OSM for moon, mars, etc
}
geohack = true;
return false;
});
if ( !geohack ) {
return;
}
$('#coordinates').append(' (<a id="coordinates_map" href="#">' + osm_proj_map + '</a>) ');
$('#coordinates_map').click(openStreetMapToggle);
}
$( openStreetMapInit ) ;