„MediaWiki:Gadget-osm.js“ – Versionsunterschied
Erscheinungsbild
Inhalt gelöscht Inhalt hinzugefügt
KKeine Bearbeitungszusammenfassung |
D (Diskussion | Beiträge) globale variablen überschreiben ist böse. und 1 und 0 als boolean-ersatz unschön. |
||
Zeile 5: | Zeile 5: | ||
function openStreetMapInit () { |
function openStreetMapInit () { |
||
c = document.getElementById ( 'coordinates' ) ; |
var c = document.getElementById ( 'coordinates' ) ; |
||
if ( !c ) return ; |
if ( !c ) return ; |
||
a = c.getElementsByTagName ( 'a' ) ; |
var a = c.getElementsByTagName ( 'a' ) ; |
||
geohack = |
var geohack = false; |
||
for ( i = 0 ; i < a.length ; i++ ) { |
for ( var i = 0 ; i < a.length ; i++ ) { |
||
h = a[i].href ; |
var h = a[i].href ; |
||
if ( !h.match(/geohack/) ) continue ; |
if ( !h.match(/geohack/) ) continue ; |
||
geohack = |
geohack = true ; |
||
break ; |
break ; |
||
} |
} |
||
if ( geohack |
if ( !geohack ) return ; |
||
na = document.createElement ( 'a' ) ; |
var na = document.createElement ( 'a' ) ; |
||
na.href = '#' ; |
na.href = '#' ; |
||
na.onclick = openStreetMapToggle ; |
na.onclick = openStreetMapToggle ; |
||
Zeile 29: | Zeile 29: | ||
function openStreetMapToggle () { |
function openStreetMapToggle () { |
||
c = document.getElementById ( 'coordinates' ) ; |
var c = document.getElementById ( 'coordinates' ) ; |
||
if ( !c ) return ; |
if ( !c ) return ; |
||
cs = document.getElementById ( 'contentSub' ) ; |
var cs = document.getElementById ( 'contentSub' ) ; |
||
osm = document.getElementById ( 'openstreetmap' ) ; |
var osm = document.getElementById ( 'openstreetmap' ) ; |
||
if ( cs && osm ) { |
if ( cs && osm ) { |
||
Zeile 44: | Zeile 44: | ||
} |
} |
||
var found_link = |
var found_link = false ; |
||
a = c.getElementsByTagName ( 'a' ) ; |
var a = c.getElementsByTagName ( 'a' ) ; |
||
for ( i = 0 ; i < a.length ; i++ ) { |
var h; |
||
for ( var i = 0 ; i < a.length ; i++ ) { |
|||
h = a[i].href ; |
h = a[i].href ; |
||
if ( !h.match(/geohack/) ) continue ; |
if ( !h.match(/geohack/) ) continue ; |
||
found_link = |
found_link = true ; |
||
break ; |
break ; |
||
} |
} |
||
if ( found_link |
if ( !found_link ) return ; // No geohack link found |
||
h = h.split('params=')[1] ; |
h = h.split('params=')[1] ; |
||
i = document.createElement ( 'iframe' ) ; |
var i = document.createElement ( 'iframe' ) ; |
||
url = 'http://tools.wikimedia.de/~magnus/ol/wp_poi.php?title=' + wgTitle ; |
var url = 'http://tools.wikimedia.de/~magnus/ol/wp_poi.php?title=' + wgTitle ; |
||
url += '&language=' + wgUserLanguage ; |
url += '&language=' + wgUserLanguage ; |
||
url += '¶ms=' + h ; |
url += '¶ms=' + h ; |
Version vom 18. Mai 2009, 18:16 Uhr
// Verwendung von OpenStreetMap in Wikipedia.
// (c) 2008 by Magnus Manske
// Released under GPL
function openStreetMapInit () {
var c = document.getElementById ( 'coordinates' ) ;
if ( !c ) return ;
var a = c.getElementsByTagName ( 'a' ) ;
var geohack = false;
for ( var i = 0 ; i < a.length ; i++ ) {
var h = a[i].href ;
if ( !h.match(/geohack/) ) continue ;
geohack = true ;
break ;
}
if ( !geohack ) return ;
var na = document.createElement ( 'a' ) ;
na.href = '#' ;
na.onclick = openStreetMapToggle ;
na.appendChild ( document.createTextNode ( 'OSM' ) ) ;
// c.appendChild ( document.createElement ( 'br' ) )
c.appendChild ( document.createTextNode ( ' (' ) ) ;
c.appendChild ( na ) ;
c.appendChild ( document.createTextNode ( ') ' ) ) ;
}
function openStreetMapToggle () {
var c = document.getElementById ( 'coordinates' ) ;
if ( !c ) return ;
var cs = document.getElementById ( 'contentSub' ) ;
var osm = document.getElementById ( 'openstreetmap' ) ;
if ( cs && osm ) {
if ( osm.style.display == 'none' ) {
osm.style.display = 'block' ;
} else {
osm.style.display = 'none' ;
// cs.removeChild ( osm ) ;
}
return false ;
}
var found_link = false ;
var a = c.getElementsByTagName ( 'a' ) ;
var h;
for ( var i = 0 ; i < a.length ; i++ ) {
h = a[i].href ;
if ( !h.match(/geohack/) ) continue ;
found_link = true ;
break ;
}
if ( !found_link ) return ; // No geohack link found
h = h.split('params=')[1] ;
var i = document.createElement ( 'iframe' ) ;
var url = 'http://tools.wikimedia.de/~magnus/ol/wp_poi.php?title=' + wgTitle ;
url += '&language=' + wgUserLanguage ;
url += '¶ms=' + h ;
i.id = 'openstreetmap' ;
i.style.width = '100%' ;
i.style.height = '300px' ;
i.style.clear = 'both' ;
i.src = url ;
cs.appendChild ( i ) ;
return false ;
}
addOnloadHook(openStreetMapInit);