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
  • Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
//<pre>
// Script to embed Coordinate template generation in MediaWiki's edit page

//
// globals
//
var wpSummary = null;
var optionalBox = null;
var optionalBoxLabel = null;
var optionalNumber = null;
var lat,lon;

//
// configuration
//
cohel_config = {
 data : {
  listRegions : [ 'US','DE','US-CA' ],
  nbsp        : false,
  template    : 0,
  region      : 0 
 },

 prefix : 'cohel_',

 restore : function() {
  var name;
  var pos;

  if(document.cookie)
  {
   var cookies = document.cookie.split('; ');
   for (var i = 0; i < cookies.length; i++)
   {
    // gehoert der Keks uns?
    if( cookies[i].substr(0,this.prefix.length) == this.prefix )
    {
     pos = cookies[i].indexOf('=');
     name = cookies[i].substring(this.prefix.length, pos);

     // nur existierende felder wiederherstellen!
     if( typeof(this.data[name]) != 'undefined' )
     {
      // skalar
      if( cookies[i].substr(pos+1,2) == 'V:' ) 
       this.data[name] = cookies[i].substr(pos+3);

      // array
      if( cookies[i].substr(pos+1,2) == 'A:' ) 
       this.data[name] = cookies[i].substr(pos+3).split('+');

      // boolean
      if( cookies[i].substr(pos+1,2) == 'B:' ) 
       if( cookies[i].substr(pos+3) > 0 ) 
        this.data[name] = true;
       else
        this.data[name] = false;
     }
    }
   } //endfor
  } //endif_cookie
 },

 save : function() {
  var today = new Date();
  var nextyear = new Date( today.getTime() + 30758400000 );
  var params = '; expires=' + nextyear.toGMTString() + '; path=/';

  for (var key in this.data) 
  { 
   if( ( typeof(this.data[key]) == 'object' ) && ( this.data[key].length > 0 ) )
   {
    // join geht nicht, weil ich uriencoden will
    var dummy = encodeURIComponent( this.data[key][0] );
    for (var i = 1; i < this.data[key].length; i++)
     dummy += '+' + encodeURIComponent( this.data[key][i] );
     document.cookie = this.prefix + key + '=' + 'A:' + dummy + params;
   }
   else if( typeof(this.data[key]) == 'boolean' )
   { 
    if(this.data[key]) 
     document.cookie = this.prefix + key + '=' + 'B:1' + params;
    else
     document.cookie = this.prefix + key + '=' + 'B:0' + params;
   }
   else
   { 
    document.cookie = this.prefix + key + '=' + 'V:' + encodeURIComponent(this.data[key]) + params;
   }
  }

  return true;
 }

};

var listTemplates = new Array( 'Koordinate_Artikel' );
var listRegions = new Array( 'US','DE','US-CA' );
var listTypes = new Array( 'landmark', 'city', 'mountain', 'waterbody', 'isle', 'airport', 'country', 'state', 'adm1st', 'adm2nd' );

var typeSelect = null;
var regionSelect = null;
var editbox = null;
var coordinatebox = null;

//
// Insert the coordinate Form into the edit box.
//
function coordinatesInstall()
{
 cohel_config.restore();
 
 var i=0;
 var copywarn = document.getElementById('editpage-copywarn');
 if (copywarn != null) {
  var cleaner = "<br style=\\'clear:both;\\' />";
  CoordinatesHTML =  '<div style="border: 1px solid gray; padding: 3px; margin-top: 2px; margin-bottom:2px;" >'
  CoordinatesHTML += '<input type="button" value="Coordinate einfügen" onclick="interpretCoordinates();" /> ';
  CoordinatesHTML += '<input type="text" size="80" id="CoordinateBox" onfocus="showDetails()" />';
  CoordinatesHTML += '<div id="CoordinateDetails" style="margin-top: 2px; position: relative"><a href="#" onclick="hideDetails()" style="position:absolute; bottom:3px; right:3px; font-size:50%">schlie&szlig;en</a>';
  CoordinatesHTML += 'Region:<select title="Region" id="CoordinateRegion"><option value="">-</option>';
  for (i=0; i<listRegions.length; ++i) {
   CoordinatesHTML += '<option value="'+listRegions[i]+'">'+listRegions[i]+'</option>';
  }
  CoordinatesHTML += '</select> Typ:<select onchange="toggleOptional()" title="Typ (bitte angeben)" id="CoordinateType">';
  for (i=0; i<listTypes.length; ++i) {
   CoordinatesHTML += '<option value="'+listTypes[i]+'">'+listTypes[i]+'</option>';
  }
  CoordinatesHTML += '</select> <span id="CoordinateBoxOptional" style="visibility: hidden"><span id="CoordinateBoxOptionalLabel"></span><input type="text" size="9" id="CoordinateNumber" /></span></div></div>';
  copywarn.innerHTML = CoordinatesHTML + copywarn.innerHTML;
  wpSummary = document.getElementById('wpSummary');
  optionalBox = document.getElementById('CoordinateBoxOptional');
  optionalBoxLabel = document.getElementById('CoordinateBoxOptionalLabel');
  optionalNumber = document.getElementById('CoordinateNumber');
  detailBox = document.getElementById('CoordinateDetails');

  typeSelect = document.getElementById('CoordinateType');
  regionSelect = document.getElementById('CoordinateRegion');

  hideDetails();

  editbox = document.getElementById('wpTextbox1');
  coordinatebox = document.getElementById('CoordinateBox');
 
  // suche nach boilerplate text: Koordinaten 38,18° Nord, 122,26° West
  var boilerplate_filter = /Koordinaten.* ([^°]+)° (Nord|Süd), ([^°]+)° (West|Ost)/;
  var result;
  if( result = boilerplate_filter.exec(editbox.value) )
  {
   lat = result[1].replace(/,/, ".");
   if( result[2] == 'Süd' ) lat*=-1;
   lon = result[3].replace(/,/, ".");
   if( result[4] == 'West' ) lon*=-1;
   coordinatebox.value = 'boilerplate:'+lat+','+lon;
   showDetails();
  }
  boilerplate_filter = / ([0-9.,]+) Einwohner/;
  if( result = boilerplate_filter.exec(editbox.value) )
  {
   optionalNumber.value = result[1].replace(/[,\.]/, "");
   typeSelect.selectedIndex = 1;
   toggleOptional();
  }  
  if( editbox.value.indexOf('[[Kategorie:Ort in Kalifornien]]') > -1 )
  {
   regionSelect.selectedIndex = 3;
  }
 }
}

function toggleOptional()
{
 optionalBox.style.visibility="hidden";

 if(typeSelect.value == 'city')
 {
  optionalBoxLabel.innerHTML='Einwohnerzahl:';
  optionalBox.style.visibility="visible";
 }
 if(typeSelect.value == 'mountain')
 {
  optionalBoxLabel.innerHTML='H&ouml;he (in Metern &uuml;ber Normalnull):';
  optionalBox.style.visibility="visible";
 }
}

function hideDetails()
{
 //detailBox.style.visibility="hidden";
 detailBox.style.display="none";
 return false;
}
function showDetails()
{
 //detailBox.style.visibility="visible";
 detailBox.style.display="block";
}

//
// Hook up installation function
//
$(coordinatesInstall);

//
// Coordinate interpretation
//
function interpretCoordinates()
{
 var coordinate1 = coordinatebox.value;
 var coordinate2 = '';
 var from_ll, result;
 var coord_filter = /http:\/\/www\.google\.([a-zA-Z]+)\/maps/;
 var latlon = new Array;
 
 // magic!
 if(coordinate1.substr(0,19)=='http://maps.google.' || coord_filter.test(coordinate1) )
 {
  from_ll = coordinate1.substr(coordinate1.indexOf("ll=")+3);
  var ampers = from_ll.indexOf('&');
  if(ampers==-1) 
  {
   latlon = from_ll.split(",");
  }
  else
  {
   latlon = (from_ll.substr(0,ampers)).split(",");
  }
 }
 
 //http://tools.wikimedia.de/~magnus/geo/geohack.php?params=39_18_S_175_35_E_type:mountain_region:NZ
 if(coordinate1.substr(0,49)=='http://tools.wikimedia.de/~magnus/geo/geohack.php')
 {
  latlon = from_ll.split(",");
 }

 // gefundene boilerplate daten
 if( coordinate1.substr(0,12) == 'boilerplate:' )
 {
  from_ll = coordinate1.substr(12);
  latlon = from_ll.split(",");
 }

 //31°46'14.44"N ; 35°14'5.88"E
 coord_filter = /([\d.,]+)°\s*([\d.,]+)['`]\s*([\d.,]+)"\s*([nNsS])\s*[;,]\s*([\d.,]+)°\s*([\d.,]+)['`]\s*([\d.,]+)"\s*([eOwWeE])/;
 if( result = coord_filter.exec(coordinate1 ) )
 {
  latlon[0] = result[1]*1.0 + result[2]/60.0 + result[3]/3600.0;
  if( result[4]=='s' || result[4]=='S' ) latlon[0] *= -1.0;
  latlon[1] = result[5]*1.0 + result[6]/60.0 + result[7]/3600.0;
  if( result[8]=='w' || result[8]=='W' ) latlon[1] *= -1.0;
 }

 // N 54 20' 56" E 9 13' 2"
 coord_filter = /\s*([NnSs])\s+([\d.,]+)\s+([\d.,]+)['`]\s*([\d.,]+)"\s+([eOwWeE])\s+([\d.,]+)\s+([\d.,]+)['`]\s+([\d.,]+)"\s*/;
 if( result = coord_filter.exec(coordinate1 ) )
 {
  latlon[0] = result[2]*1.0 + result[3]/60.0 + result[4]/3600.0;
  if( result[1]=='s' || result[1]=='S' ) latlon[0] *= -1.0;
  latlon[1] = result[6]*1.0 + result[7]/60.0 + result[8]/3600.0;
  if( result[5]=='w' || result[5]=='W' ) latlon[1] *= -1.0;
 }
 var mark_ns = 'N';
 var mark_ew = 'E';
 var mark_ew_d = 'O';

 lat = latlon[0];
 lon = latlon[1];

 if(lat<0) { lat*=-1; mark_ns='S'; }
 if(lon<0) { lon*=-1; mark_ew='W'; mark_ew_d='W';}

 var lat_m = (( lat - Math.floor(lat) ) * 60.0).toPrecision(10);
 var lon_m = (( lon - Math.floor(lon) ) * 60.0).toPrecision(10);

 var lat_s = ( lat_m - Math.floor(lat_m) ) * 60.0;
 var lon_s = ( lon_m - Math.floor(lon_m) ) * 60.0;

 coordinate2 = '\n{{Coordinate|NS=' + Math.floor(lat) + '/' + Math.floor(lat_m) + '/' + lat_s.toPrecision(5) + '/' + mark_ns + '|EW=' + Math.floor(lon) + '/' + Math.floor(lon_m) + '/' + lon_s.toPrecision(5) + '/' + mark_ew + '|type=' + typeSelect.value;

 if( typeSelect.value=='city' && optionalNumber.value!='' )
  coordinate2 += '|pop=' + optionalNumber.value;

 if( typeSelect.value=='mountain' && optionalNumber.value!='' )
  coordinate2 += '|elevation=' + optionalNumber.value;

 if( regionSelect.value!='' )
  coordinate2 += '|region=' + regionSelect.value;

 coordinate2 += '}}\n';

 var editbox_content = editbox.value.replace(/\{\{Koordinate[\s_]Artikel.*\}\}/, "");
 editbox_content = editbox_content.replace(/\{\{Coordinate.*\}\}/, "");
 editbox.value = editbox_content + coordinate2;

 if( wpSummary.value == "" ) wpSummary.value="+Koord mit [[Benutzer:Dschwen/Koordinatenhelferlein]]";

 cohel_config.save();
}
//</pre>