MediaWiki:Gadget-wiwosm.js
Zur Navigation springen
Zur Suche springen
Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.
- Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
- Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
- Internet Explorer/Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
- Opera: Strg+F5
// Using OpenStreetMap in Wikipedia.
// (c) 2008 by Magnus Manske
// heavily altered by [[m:User:Danmichaelo]], [[m:User:Hoo man]], [[m:User:Simon04]]
// Released under GPL
// 2021 entirely rewritten by [[w:de:User:PerfektesChaos]]
// <nowiki>
( function ( mw, $ ) {
"use strict";
var Version = "2021-03-10 dewiki@BETA",
Sign = "wiwosm",
URLroot = "https://wiwosm.toolforge.org/osm-on-ol/kml-on-ol.php",
Config = { cLangs: false,
coordinates: false,
env: false,
maxH: 350,
slang: false,
$coordinate: false,
$container: false,
$toggle: false,
$widget: false
};
function factory() {
// Design of default insertion container
return { "border-bottom": "1px solid #A2A9B1",
"clear": "both",
"height": Math.max( 0.5 * Config.$window.height(),
Config.maxH )
+ "px",
"overflow": "hidden",
"padding-bottom": "15px",
"resize": "vertical",
"width": "100%"
};
} // factory()
function feasible( $ask ) {
// Is $ask a valid jQuery object?
var s = ( typeof $ask );
return ( ( s === "object" || s === "function" ) && $ask &&
typeof $ask.length === "number"
&& $ask.length === 1 &&
typeof $ask.addClass === "function" &&
typeof $ask.after === "function" &&
typeof $ask.append === "function" &&
typeof $ask.attr === "function" &&
typeof $ask.click === "function" &&
typeof $ask.clone === "function" &&
typeof $ask.css === "function" &&
typeof $ask.eq === "function" &&
typeof $ask.find === "function" &&
typeof $ask.hide === "function" &&
typeof $ask.html === "function" &&
typeof $ask.offset === "function" &&
typeof $ask.scrollTop === "function" &&
typeof $ask.text === "function" &&
typeof $ask.toggle === "function" );
} // feasible()
function features( assign ) {
// Configuration hook arrived
var i, s, v;
if ( typeof assign === "object"
&& assign ) {
v = assign[ s ];
for ( s in assign ) {
switch ( s ) {
case "$coordinate":
case "$container":
case "$toggle":
case "$widget":
if ( feasible( v ) ) {
Config[ s ] = v;
}
break;
case "height":
if ( typeof v === "number" &&
v > 10 &&
v < 2048 ) {
Config.maxH = Math.floor( v );
}
break;
case "lang":
if ( typeof Config.reLang !== "object" ) {
s = "^[a-z][a-z][a-z]?\\(-[-a-zA-Z]+\\)?$";
Config.reLang = new RegExp( s );
}
switch ( typeof v ) {
case "string":
if ( Config.reLang.test( v ) ) {
Config.slang = v;
}
break;
case "object":
if ( v &&
typeof v.length === "number" ) {
Config.cLangs = Config.cLangs || [ ];
for ( i = 0; i < v.length; i++ ) {
s = false;
if ( typeof v[ i ] === "string" &&
Config.reLang.test( v[ i ] ) ) {
s = v[ i ];
}
Config.cLangs.push( s );
} // for i
}
break;
} // switch typeof v
break;
} // switch s
} // for s in assign
}
} // features()
function fiat( at ) {
// Create and insert $iframe
var co = Config.coordinates[ at ],
sel = "openstreetmap",
slang, src;
Config.env = Config.env ||
mw.config.get( [ "wgContentLanguage",
"wgTitle",
"wgUserLanguage",
"osm_proj_lang" ] );
if ( Config.cLangs &&
Config.cLangs.length > at &&
Config.cLangs[ at ] ) {
slang = Config.cLangs[ at ];
} else {
slang = Config.slang ||
Config.env.osm_proj_lang ||
Config.env.wgContentLanguage;
}
src = URLroot + "?secure=1"
+ "&lang=" + slang
+ "¶ms=" + co.href.split( "params=" )[ 1 ]
+ "&title=" + mw.util.wikiUrlencode( Config.env.wgTitle )
+ "&uselang=" + Config.env.wgUserLanguage;
co.$iframe = $( "<iframe>" );
co.$iframe.addClass( sel )
.attr( { src: src } )
.css( { border: "1px solid #A2A9B1",
height: "100%",
width: "100%" } );
if ( ! at ) {
co.$iframe.attr( "id", sel );
}
co.$container.append( co.$iframe );
} // fiat()
function flip( at ) {
// Toggle has been clicked
var co = Config.coordinates[ at ],
sel = "openstreetmap-container",
i, j, k, $e;
if ( co.$iframe ) {
co.$container.toggle();
co.live = ! co.live;
} else {
Config.$window = Config.$window || $( window );
if ( ! co.$container || ! co.$container.length ) {
// LEGACY
$e = $( "#contentSub" );
if ( $e.length !== 1 ) {
// Minerva has no #contentSub
$e = $( "#mw-content-text" );
}
if ( $e.length === 1 ) {
co.$container = $( "<div>" );
co.$container.addClass( sel )
.css( factory() );
if ( ! at ) {
co.$container.attr( "id", sel );
}
$e.after( co.$container );
}
} else if ( Config.$container.length < at ) {
co.$container = Config.$container.eq( at );
} else {
co.$container = Config.$container.eq( 0 );
}
if ( co.$container ) {
co.$iframe = true; // race condition
co.live = true;
mw.loader.using( [ "mediawiki.util" ],
function () { fiat( at ); } );
co.$container.css( { "min-height": "10px",
"max-height": "fit-content" } );
} else {
co.$widget.hide();
co.live = false;
}
}
if ( co.live ) {
i = co.$container.scrollTop();
k = co.$container.offset().top;
if ( k < i ) {
co.$container.scrollTop( k );
} else {
j = Config.$window.height();
if ( k + 0.5 * Config.maxH > i + j ) {
i = i + j - Config.maxH;
if ( i < 0 ) {
i = 0;
}
co.$container.scrollTop( i );
}
}
}
} // flip()
function furnish() {
// Autorun on loading; DOM is ready
var config = { type: Sign,
vsn: Version },
sel = "coordinates_map",
co, env, i, k, s, $a, $e;
if ( ! Config.$coordinate ) {
// LEGACY
Config.$coordinate = $( "#coordinate" );
}
if ( Config.$coordinate.length ) {
for ( i = 0; i < $e.length; i++ ) {
$e = Config.$coordinate.eq( i );
$a = $e.find( "a" );
for ( k = 0; k < $a.length; k++ ) {
s = $a.eq( k ).attr( "href" );
if ( s.indexOf( "geohack" ) > 0 &&
s.indexOf( "_globe:" ) < 0 ) {
// no OSM for moon, mars, etc.
Config.coordinates = Config.coordinates || [ ];
Config.coordinates.push( { $container: false,
$coordinate: $e,
$iframe: false,
href: s } );
break; // for k
}
} // for k
} // for i
}
if ( Config.coordinates ) {
if ( ! ( Config.$widget && Config.$toggle ) ||
( Config.$widget && ! Config.$widget.length ) ||
( Config.$toggle && ! Config.$toggle.length ) ) {
// LEGACY
env = mw.config.get( [ "osm_proj_map_map",
"osm_proj_map_prefix",
"osm_proj_map_postfix" ] );
Config.$widget = $( "<span>" );
if ( ! Config.$toggle ) {
Config.$toggle = $( "<span>" );
s = env.osm_proj_map_map;
if ( s ) {
Config.$toggle.html( s );
} else {
Config.$toggle.text( "[OSM]" );
}
}
$e = $( "<span>" );
s = env.osm_proj_map_prefix;
if ( s ) {
$e.html( s );
} else {
$e.css( { "margin-left": "1em" } )
.text( "(" );
}
Config.$widget.append( $e,
Config.$toggle );
$e = $( "<span>" );
s = env.osm_proj_map_postfix;
if ( s ) {
$e.html( s );
} else {
$e.css( { "margin-right": "2em" } )
.text( ")" );
}
Config.$widget.append( $e );
}
Config.$toggle.addClass( sel )
.css( { "cursor": "pointer" } );
for ( i = 0; i < Config.coordinates.length; i++ ) {
co = Config.coordinates[ i ];
if ( Config.$widget.length < i ) {
co.$widget = Config.$widget.eq( i );
} else {
co.$widget = Config.$widget.eq( 0 ).clone();
}
co.$toggle = co.$widget.find( "." + sel );
if ( co.$toggle.length ) {
if ( ! i ) {
co.$toggle.attr( "id", sel );
}
co.$toggle.click( function () { flip( i ); } );
co.$coordinate.after( co.$widget );
}
} // for i
}
for ( s in Config ) {
if ( Config[ s ] ) {
config[ s ] = Config[ s ];
}
} // for s in Config
mw.hook( Sign + ".ready" ).fire( config );
} // furnish()
mw.hook( Sign + ".config" ).add( features );
$( furnish );
}( window.mediaWiki, window.jQuery ) );
// </nowiki>