Benutzer:Dschwen/coordinates.js

Im heutigen Artikel tauchen wir in die faszinierende Welt von Benutzer:Dschwen/coordinates.js ein. Von seinen Ursprüngen bis zu seinen Auswirkungen auf die heutige Gesellschaft werden wir alle Aspekte im Zusammenhang mit Benutzer:Dschwen/coordinates.js untersuchen. Wir werden uns mit seiner Geschichte befassen, seine Hauptmerkmale analysieren und seine heutige Relevanz untersuchen. Benutzer:Dschwen/coordinates.js ist seit Jahrzehnten Gegenstand von Interesse und Debatten, und es ist an der Zeit, sich mit seiner Bedeutung und Bedeutung zu befassen. Machen Sie sich bereit für eine faszinierende Reise durch Benutzer:Dschwen/coordinates.js und entdecken Sie alles, was dieses Thema zu bieten hat!
//<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 : ,
  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.substr(0,this.prefix.length) == this.prefix )
    {
     pos = cookies.indexOf('=');
     name = cookies.substring(this.prefix.length, pos);

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

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

      // boolean
      if( cookies.substr(pos+1,2) == 'B:' ) 
       if( cookies.substr(pos+3) > 0 ) 
        this.data = true;
       else
        this.data = 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) == 'object' ) && ( this.data.length > 0 ) )
   {
    // join geht nicht, weil ich uriencoden will
    var dummy = encodeURIComponent( this.data );
    for (var i = 1; i < this.data.length; i++)
     dummy += '+' + encodeURIComponent( this.data );
     document.cookie = this.prefix + key + '=' + 'A:' + dummy + params;
   }
   else if( typeof(this.data) == 'boolean' )
   { 
    if(this.data) 
     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) + 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+'">'+listRegions+'</option>';
  }
  CoordinatesHTML += '</select> Typ:<select onchange="toggleOptional()" title="Typ (bitte angeben)" id="CoordinateType">';
  for (i=0; i<listTypes.length; ++i) {
   CoordinatesHTML += '<option value="'+listTypes+'">'+listTypes+'</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.replace(/,/, ".");
   if( result == 'Süd' ) lat*=-1;
   lon = result.replace(/,/, ".");
   if( result == 'West' ) lon*=-1;
   coordinatebox.value = 'boilerplate:'+lat+','+lon;
   showDetails();
  }
  boilerplate_filter = / (+) Einwohner/;
  if( result = boilerplate_filter.exec(editbox.value) )
  {
   optionalNumber.value = result.replace(//, "");
   typeSelect.selectedIndex = 1;
   toggleOptional();
  }  
  if( editbox.value.indexOf(']') > -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\.(+)\/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 = /(+)°\s*(+)\s*(+)"\s*()\s*\s*(+)°\s*(+)\s*(+)"\s*()/;
 if( result = coord_filter.exec(coordinate1 ) )
 {
  latlon = result*1.0 + result/60.0 + result/3600.0;
  if( result=='s' || result=='S' ) latlon *= -1.0;
  latlon = result*1.0 + result/60.0 + result/3600.0;
  if( result=='w' || result=='W' ) latlon *= -1.0;
 }

 // N 54 20' 56" E 9 13' 2"
 coord_filter = /\s*()\s+(+)\s+(+)\s*(+)"\s+()\s+(+)\s+(+)\s+(+)"\s*/;
 if( result = coord_filter.exec(coordinate1 ) )
 {
  latlon = result*1.0 + result/60.0 + result/3600.0;
  if( result=='s' || result=='S' ) latlon *= -1.0;
  latlon = result*1.0 + result/60.0 + result/3600.0;
  if( result=='w' || result=='W' ) latlon *= -1.0;
 }
 var mark_ns = 'N';
 var mark_ew = 'E';
 var mark_ew_d = 'O';

 lat = latlon;
 lon = latlon;

 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(/\{\{KoordinateArtikel.*\}\}/, "");
 editbox_content = editbox_content.replace(/\{\{Coordinate.*\}\}/, "");
 editbox.value = editbox_content + coordinate2;

 if( wpSummary.value == "" ) wpSummary.value="+Koord mit ]";

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