Zum Inhalt springen

„Benutzer:Prolineserver/osm.js“ – Versionsunterschied

aus Wikipedia, der freien Enzyklopädie
Inhalt gelöscht Inhalt hinzugefügt
aus meiner alten sv-monobook.js
 
find all coordinates and alert them
 
Zeile 10: Zeile 10:
function openStreetMapInit () {
function openStreetMapInit () {

c = document.getElementById ( 'coordinates' ) ;
c = getElementsByClass ( 'coordinates', 'document', 'span') ;
if ( !c ) {
c = document.getElementById ( 'coordinates_text' ) ;
if (!c) return ;
if (!c) return ;
}
}

a = c.getElementsByTagName ( 'a' ) ;
for ( i = 0 ; i < c.length ; i++ ) {
a = c[i].getElementsByTagName ( 'a' ) ;
geohack = 0 ;
for ( i = 0 ; i < a.length ; i++ ) {
for ( j = 0 ; j < a.length ; j++ ) {
h = a[i] ;
h = a[j] ;
alert(h.href);
// alert(h.href);
if ( !h.href.match(/geohack/) ) continue ;
if ( !h.href.match(/geohack/) ) continue ;
// geohack = 1 ;
geohack = 1 ;
// break ;
break ;
}
if (h.parentNode.id == 'coordinates' || h.parentNode.id == 'coordinates_text') {
alert(c[i].id);
na = document.createElement ( 'a' ) ;
}
na.href = '#' ;
}
params = h.href.split('params=')[1] ;
na.onclick = openStreetMapToggle(params) ;
na.appendChild ( document.createTextNode ( 'OSM' ) ) ;
h.parentNode.appendChild ( document.createTextNode ( ' (' ) ) ;
h.parentNode.appendChild ( na ) ;
h.parentNode.appendChild ( document.createTextNode ( ') ' ) ) ;
}
}
// if ( geohack == 0 ) return ;
}
function openStreetMapToggle (params) {
function openStreetMapToggle (params) {
Zeile 75: Zeile 64:
addOnloadHook(openStreetMapInit);
addOnloadHook(openStreetMapInit);




// Stolen from http://www.anyexample.com/webdev/javascript/javascript_getelementsbyclass_function.xml

function getElementsByClass( searchClass, domNode, tagName) {
if (domNode == null) domNode = document;
if (tagName == null) tagName = '*';
var el = new Array();
var tags = domNode.getElementsByTagName(tagName);
var tcl = " "+searchClass+" ";
for(i=0,j=0; i<tags.length; i++) {
var test = " " + tags[i].className + " ";
if (test.indexOf(tcl) != -1)
el[j++] = tags[i];
}
return el;
}

Aktuelle Version vom 24. März 2009, 16:07 Uhr

//document.write('<script type="text/javascript" src="' 
//             + 'http://sv.wikipedia.org/w/index.php?title=Användare:Prolineserver/osm.js' 
//             + '&action=raw&ctype=text/javascript&dontcountme=s"><\/script>');


// Verwendung von OpenStreetMap in Wikipedia.
// (c) 2008 by Magnus Manske
// Released under GPL
 
 
function openStreetMapInit () {

  c = getElementsByClass ( 'coordinates', 'document', 'span') ;
    if (!c) return ;
  }

  for ( i = 0 ; i < c.length ; i++ ) {
    a = c[i].getElementsByTagName ( 'a' ) ;
    for ( j = 0 ; j < a.length ; j++ ) {
      h = a[j] ;
//      alert(h.href);
      if ( !h.href.match(/geohack/) ) continue ;
      geohack = 1 ;
      break ;
    }
    alert(c[i].id);
  } 
}
 
function openStreetMapToggle (params) {
  c = document.getElementById ( 'coordinates' ) ;
  if ( !c ) {
    c = document.getElementById ( 'coordinates_text' ) ;
    if (!c) return ;
  }
  cs = document.getElementById ( 'contentSub' ) ;
  osm = document.getElementById ( 'openstreetmap' ) ;
 
  if ( cs && osm ) {
    cs.removeChild ( osm ) ;
    return ;
  }
//  a = c.getElementsByTagName ( 'a' ) ;
//  for ( i = 0 ; i < a.length ; i++ ) {
//    h = a[i].href ;
//    if ( !h.match(/geohack/) ) continue ;
//    geohack = 1 ;
//    break ;
//  }
//  h = h.split('params=')[1] ;
 
  i = document.createElement ( 'iframe' ) ;
  url = 'http://tools.wikimedia.de/~magnus/ol/wp_poi.php?title=' + wgTitle ;
  url += '&language=' + wgUserLanguage ;
  url += '&params=' + params ;
  i.id = 'openstreetmap' ;
  i.style.width = '100%' ;
  i.style.height = '300px' ;
  i.style.clear = 'both' ;
  i.src = url ;
  cs.appendChild ( i ) ;
}
 
 
addOnloadHook(openStreetMapInit);




// Stolen from http://www.anyexample.com/webdev/javascript/javascript_getelementsbyclass_function.xml

function getElementsByClass( searchClass, domNode, tagName) {
	if (domNode == null) domNode = document;
	if (tagName == null) tagName = '*';
	var el = new Array();
	var tags = domNode.getElementsByTagName(tagName);
	var tcl = " "+searchClass+" ";
	for(i=0,j=0; i<tags.length; i++) {
		var test = " " + tags[i].className + " ";
		if (test.indexOf(tcl) != -1)
			el[j++] = tags[i];
	}
	return el;
}