MediaWiki:GeoHack.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/** * The file is used by GeoHack on Tool Labs (linked from [[Template:GeoTemplate]]). * * This file is not loaded within a wiki context. Standard libraries (jQuery, mediawiki.js etc) are not available. */ /** * Copy of standard library function */ function appendCSS(text) { var s = document.createElement('style'); s.type = 'text/css'; s.rel = 'stylesheet'; if (s.styleSheet) s.styleSheet.cssText = text //IE else s.appendChild(document.createTextNode(text + '')) //Safari sometimes borks on null document.getElementsByTagName('head')[0].appendChild(s); } window.onload = function() { /* Add row hover effect */ appendCSS(".directory tr:hover {background:#fdc !important;}"); } var head = document.getElementsByTagName('head')[0]; var style = document.createElement('link'); style.rel = 'stylesheet'; style.type = 'text/css'; style.href = '//maps.wikimedia.org/leaflet/leaflet.css'; head.appendChild(style); var script = document.createElement('script'); script.type = 'text/javascript'; script.src = '//maps.wikimedia.org/leaflet/leaflet.js'; head.appendChild(script); var OSM_class_R = /\bOSM:([\d.+-]+)_([\d.+-]+)_([\d.+-]+)_(\w+)/; function embedOpenStreetMap() { clearInterval(osmtimer); var osmTarget = document.getElementById('osmEmbed'); if (osmTarget && OSM_class_R.exec(osmTarget.className)) { var lat = 1.0 * RegExp.$1, lon = 1.0 * RegExp.$2, zoom = RegExp.$3; var map = L.map('osmEmbed').setView([lat, lon], zoom); map.attributionControl.setPrefix( '' ); L.tileLayer('//maps.wikimedia.org/osm-intl/{z}/{x}/{y}{r}.png', { attribution: 'Wikimedia maps beta | Map data © <a href="http://osm.org/copyright">OpenStreetMap contributors</a>' }).addTo(map); L.marker([lat, lon]).addTo(map); } } osmtimer = setInterval("if (document.getElementById('osmEmbed') && L) { embedOpenStreetMap(); }", 200); setTimeout('clearInterval(osmtimer)', 5000);