Brukar:Jhs/koordinatar.js - Wikipedia

# Brukar:Jhs/koordinatar.js

### Frå Wikipedia – det frie oppslagsverket

< Brukar:Jhs

Merk: Etter lagring vil det kanskje vera naudsynt at nettlesaren omgår mellomlageret sitt for at endringane skal tre i kraft. Mozilla og Firefox: trykk Ctrl-Shift-R, Internet Explorer: Ctrl-F5, Safari: Cmd-Shift-R, Konqueror: F5.

    //<pre>
    // Kopiert frå [[:commons:User:Dschwen/coordinates.js]] via [[:nb:Bruker:Atluxity/koordinater.js]] og omsett
    // Script to embed Coordinate template generation in MediaWiki's edit page
    // inspired by [[:en:User:Pilaf/livepreview.js]]

    //
    // defaults
    //
    var coord_templatename = 'koord'; // can be overridden with 'coor_dms'

    //
    // Insert the coordinate Form into the edit box.
    //
    function coordinatesInstall()
    {
     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="Sett inn '+coord_templatename+'" onclick="interpretCoordinates();" /> ';
      CoordinatesHTML += '<input type="text" size="80" id="CoordinateBox" /></div>';
      copywarn.innerHTML = CoordinatesHTML + copywarn.innerHTML;
     }
    }

    //
    // Hook up instalation function
    //
    addOnloadHook(coordinatesInstall);

    //
    // Coordinate interpretation
    //
    function interpretCoordinates()
    {
     var coordinate1 = document.getElementById('CoordinateBox').value;
     var coordinate2 = '';
     var coord_filter = /http:\/\/www\.google\.([a-zA-Z]+)\/maps/;

     // magic!
     if(coordinate1.substr(0,19)=='http://maps.google.' || coord_filter.test(coordinate1) )
     {
      var from_ll = coordinate1.substr(coordinate1.indexOf("&ll=")+4);
      var ampers = from_ll.indexOf('&');
      var latlon;
      if(ampers==-1)
      {
       latlon = from_ll.split(",");
      }
      else
      {
       latlon = (from_ll.substr(0,ampers)).split(",");
      }
     }

     var mark_ns = 'N';
     var mark_ew = 'E';

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

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

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

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

     //coordinate2 = '{{coor_d|'+lat+'|'+mark_ns+'|'+lon+'|'+mark_ew+'|type:landmark}}';
     coordinate2 = '{{'+coord_templatename+'|'+Math.floor(lat)+'|'+Math.floor(lat_m)+'|'+lat_s.toPrecision(5)+'|'+mark_ns+'|'+
                        Math.floor(lon)+'|'+Math.floor(lon_m)+'|'+lon_s.toPrecision(5)+'|'+mark_ew+'|type:landmark}}\n';

     var editbox = document.getElementById('wpTextbox1');
     var information_template = (editbox.value).indexOf('{{Information')

     if(information_template >-1)
     {
      var editbox_content_1 = (editbox.value).substr(0,information_template);
      var editbox_content_2 = (editbox.value).substr(information_template);
      editbox.value = editbox_content_1 + coordinate2 + editbox_content_2;
     }
     else
     {
      var editbox_content = editbox.value;
      editbox.value = coordinate2 + editbox_content;
     }
     var summaryeditbox = document.getElementById('wpSummary');
     var summaryeditbox_content = summaryeditbox.value;
     summaryeditbox.value = summaryeditbox_content + "+" + coord_templatename;
    }
    //</pre>

Henta frå «http://nn.wikipedia.org../../../j/h/s/Brukar%7EJhs_koordinatar.js_424b.html»

##### Views

- Brukarside
- Diskusjon
- Noverande versjon

##### Søk