Lankide:Dschwen/wikiminiatlas2.js

Wikipedia, Entziklopedia askea

Oharra: Gorde ondoren zure nabigatzailearen katxea ekidin beharko duzu aldaketak ikusteko. Mozilla / Firefox / Safari: Shift tekla sakatu birkargatzeko momentuan, edo Ctrl-Shift-R sakatu (Cmd-Shift-R Apple Mac baten); IE: Ctrl tekla sakatu birkargatzeko momentuan, edo Ctrl-F5 sakatu; Konqueror:: Birkargatzeko klik egin, edo F5 sakatu, besterik ez; Opera erabiltzaileek Tresnak-Hobespenak atalera jo eta katxea garbitzeko aukera hautatu.

// [[image:Erioll_world.svg|18px]] '''WikiMiniAtlas''' <br>
// Script to embed interactive maps into pages that have coordinate templates <br>
// also check my commons page [[:commons:User:Dschwen]] for more tools<pre>

var wikiminiatlas =
{
 config:
 {
  width  : 500,
  height : 300,
  zoom : 1,
  iframeurl : 'http://tools.wikimedia.de/~dschwen/wikiminiatlas/iframe.html',
  imgbase   : 'http://tools.wikimedia.de/~dschwen/wikiminiatlas/tiles/',
  coordurls : new Array ( 
                'http://tools.wikimedia.de/~magnus/geo/geohack.php?',
                'http://www8.brinkster.com/erikbaas/wiki/maps.asp?',
                'http://www.nsesoftware.nl/wiki/maps.asp?' 
              ),
  buttonImage: 
'http://upload.wikimedia.org/wikipedia/commons/thumb/9/9a/Erioll_world.svg/18px-Erioll_world.svg.png'
 },

 strings:
 {
  buttonTooltip : {
   ca:'mostra la localització en un mapa interactiu',
   da:'vis beligenhed på interaktivt kort',
   de:'Ort auf interaktiver Karteanzeigen',
   en:'show location on an interactive map',
   eu:'erakutsi kokalekua mapa interaktibo batean',
   es:'mostrar el lugar en un mapa interactivo',
   fr:'Montrer la localisation sur une carte interactive',
   he:'הראה מיקום במפה האינטראקטיבית',
   it:'mostra la località su una carta interattiva',
   id:'Tunjukkan letak di peta interaktif',
   ja:'インタラクティブ地図上に位置を表示',
   mk:'Prikazi go mestoto na interaktivnata mapa',
   nl:'toon de locatie op een interactieve kaart',
   no:'vis beliggenhet på interaktivt kart',
   pl:'Pokaż lokalizację na mapie interaktywnej',
   pt:'mostrar a localidade num mapa interactivo',
   ru:'показать положение на интерактивной карте',
   sl:'prikaži lokacijo na interaktivnem zemljevidu',
   fi:'näytä paikka interaktiivisella kartalla',
   sv:'visa platsen på en interaktiv karta',
   zh:'显示该地在地图上的位置'
  },
  close : {
   ca:'tanca',
   da:'luk',
   de:'schlie&szlig;en',
   en:'close',
   eu:'itxi',
   es:'cerrar',
   fr:'Quitter',
   he:'לסגור',
   id:'tutup',
   it:'chiudi',
   ja:'閉じる',
   mk:'zatvori',
   nl:'sluiten',
   no:'lukk',
   pl:'zamknij',
   pt:'fechar',
   ru:'закрыть',
   sl:'zapri',
   fi:'sulje',
   sv:'stäng',
   zh:'关闭'
  }
 },

 link : null,
 links : null,

 language : '',
 iframe : { div: null, iframe: null, closebutton: null},
 mapbutton: null,
 marker : { lat:0, lon:0 },

 coordinates : null,
 coord_index: 0,
 coord_params: '',
 coord_filter: null,

 region_index : 0,
 coordinate_region : '',

 WikiMiniAtlasHTML : '',

 // cross-browser event attachment (John Resig)
 // http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
 addEvent : function ( obj, type, fn )
 {
  if (obj.addEventListener)
   obj.addEventListener( type, fn, false );
  else if (obj.attachEvent)
  {
   obj["e"+type+fn] = fn;
   obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
   obj.attachEvent( "on"+type, obj[type+fn] );
  }
 },
 
 // vertikale position auf der Seite bestimmen
 totalOffset : function( obj, offset )
 {
  if( obj.offsetParent == null || 
      obj.offsetParent.id == 'content' )
   return offset + obj.offsetTop;
  else
   return wikiminiatlas.totalOffset(obj.offsetParent, offset + obj.offsetTop );
 },

 // move iframe around and toggle visibility
 toggleIFrame : function( e )
 {
  with(wikiminiatlas)
  {
   var newurl = config.iframeurl + '?' + this.mapparam;

   if(iframe.div.style.visibility != "visible" ||
      ( ( iframe.iframe.src != newurl ) && ( this.mapparam != '' ) ) )
   {
    if( iframe.iframe.src != newurl )
    {
     iframe.iframe.src = newurl;
    }
    iframe.div.style.top = (totalOffset( this, 0 ) + 20 ) + 'px';
    iframe.div.style.visibility="visible";
   }
   else
    iframe.div.style.visibility="hidden";
  }
  return false;
 },
 
 // Check against coordinate urls
 isMaplink : function( url )
 {
  if( typeof(url) != 'string' ) return false;

  with(wikiminiatlas)
  {
   for( var key in config.coordurls ) {
    if( url.substr(0,config.coordurls[key].length) == config.coordurls[key] )
     return true;
   }
  }
  
  return false;
 },

 // Insert the IFrame into the page.
 loader : function()
 {
  // apply settings
  if( typeof(wma_settings) == 'object' )
   for (var key in wma_settings)
   {
    if( typeof(wma_settings[key]) == typeof(wikiminiatlas.config[key]) )
     wikiminiatlas.config[key] = wma_settings[key];
   }

  with(wikiminiatlas)
  {
   language = window.location.host.substr(0,2);

   // remove stupid icons from title coordinates
   var coord_title = document.getElementById('coordinates');
   if( coord_title ) {
    var icons = coord_title.getElementsByTagName('a');
    for( var key in icons ) {
     if( typeof(icons[key]) == 'object' && icons[key].getAttribute('class') == 'image' ) 
      icons[key].parentNode.removeChild(icons[key]);
    }
   }

   links = document.getElementsByTagName('a');
   for( var key in links )
   {
    link = links[key];
    if( isMaplink(link.href) )
    {
     coordinates = link.href;
     coord_index = coordinates.indexOf('params=');
     if(coord_index>-1)
     {
      coord_params = coordinates.substr(coord_index+7);

      // degrees
      coord_filter = /([\d+-.]+)_([NS])_([\d+-.]+)_([EOW])_/;
      if(coord_filter.test(coord_params))
      {
       coord_filter.exec(coord_params);
       marker.lat=RegExp.$1;
       if(RegExp.$2=='S') marker.lat*=-1;
       marker.lon=RegExp.$3;
       if(RegExp.$4=='W') marker.lon*=-1;
      }

      // degrees, minutes
      coord_filter = /([\d+-.]+)_([\d+-.]+)_([NS])_([\d+-.]+)_([\d+-.]+)_([EOW])_/;
      if(coord_filter.test(coord_params))
      {
       coord_filter.exec(coord_params);
       marker.lat=(1.0*RegExp.$1) + (RegExp.$2/60.0);
       if(RegExp.$3=='S') marker.lat*=-1;
       marker.lon=(1.0*RegExp.$4) + (RegExp.$5/60.0);
       if(RegExp.$6=='W') marker.lon*=-1;
      }

      // degrees, minutes, seconds
      coord_filter = /([\d+-.]+)_([\d+-.]+)_([\d+-.]*)_([NS])_([\d+-.]+)_([\d+-.]+)_([\d+-.]*)_([EOW])_/;
      if(coord_filter.test(coord_params))
      {
       coord_filter.exec(coord_params);
       marker.lat=(1.0*RegExp.$1) + (RegExp.$2/60.0) + (RegExp.$3/3600.0);
       if(RegExp.$4=='S') marker.lat*=-1;
       marker.lon=(1.0*RegExp.$5) + (RegExp.$6/60.0) + (RegExp.$6/3600.0);
       if(RegExp.$8=='W') marker.lon*=-1;
      }
 
/*
      region_index = coordinates.indexOf('region:');
      if(region_index>-1)
      {
       coordinate_region = coordinates.substr(region_index+7);
       coordinate_region = coordinate_region.substr(0,coordinate_region.indexOf('"'));
      }
*/

      mapbutton = document.createElement('img');
      mapbutton.title = strings.buttonTooltip[language];
      mapbutton.style.padding = '0px 3px 0px 0px';
      mapbutton.style.cursor = 'pointer';
      mapbutton.src = config.buttonImage;
      mapbutton.mapparam = 
      marker.lat + '_' + marker.lon + '_' + 
      config.width + '_' + config.height + '_' + 
      language+'_'+config.zoom;
      addEvent( mapbutton, 'click', toggleIFrame );

      // link.parentNode.insertBefore(mapbutton, link.nextSibling);
      link.parentNode.insertBefore(mapbutton,link);
     }

/*    var def_zoom = '';
    if( typeof(wikiminiatlas_defaultzoom) == 'number' ) 
     def_zoom = '_' + wikiminiatlas_defaultzoom; */

    }

   } //for


   // iframe vorbereiten
   iframe.div = document.createElement('div');
   iframe.div.style.visibility = 'hidden';
   iframe.div.style.width = (config.width+2)+'px';
   iframe.div.style.height = (config.height+2)+'px';
   iframe.div.style.margin = '0px';
   iframe.div.style.padding = '0px';
   iframe.div.style.backgroundColor = 'white';
   iframe.div.style.position = 'absolute';
   iframe.div.style.right = '2em';
   iframe.div.style.top = '1em';
   iframe.div.style.border = '1px solid gray';
   iframe.div.style.zIndex = 13;

   iframe.closebutton = document.createElement('img');
   iframe.closebutton.title = strings.close[language];
   iframe.closebutton.src = config.imgbase + 'button_hide.png'
   iframe.closebutton.style.zIndex = 15;
   iframe.closebutton.style.position = 'absolute';
   iframe.closebutton.style.right = '11px';
   iframe.closebutton.style.top = '9px';
   iframe.closebutton.style.width = '18px';
   iframe.closebutton.style.cursor = 'pointer';
   iframe.closebutton.mapparam = '';
   addEvent( iframe.closebutton, 'click', toggleIFrame );

   iframe.iframe = document.createElement('iframe');
   iframe.iframe.scrolling = 'no';
   iframe.iframe.frameBorder = '0';
   iframe.iframe.style.zIndex = 14;
   iframe.iframe.style.position = 'absolute';
   iframe.iframe.style.right = '1px';
   iframe.iframe.style.top = '1px';
   iframe.iframe.style.width = (config.width)+'px';
   iframe.iframe.style.height = (config.height)+'px';
   iframe.iframe.style.margin = '0px';
   iframe.iframe.style.padding = '0px';

   iframe.div.appendChild(iframe.iframe);
   iframe.div.appendChild(iframe.closebutton);

   var content = document.getElementById('content');
   content.insertBefore(iframe.div,content.childNodes[0]);
  } //with
 }

}

//
// Hook up installation function
//
$(wikiminiatlas.loader);

//</pre>