MediaWiki:Common.js
Jump to navigation
Jump to search
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.
/* Any JavaScript here will be loaded for all users on every page load. */ function cb(json) { //do what you want with the json document.getElementById('output').innerHTML = json.address.road + ',' + json.address.city; } function nominatimsearch(lat,long) { var s = document.createElement('script'); s.src = 'http://nominatim.openstreetmap.org/reverse?json_callback=cb&format=json&lat='+lat+'&lon='+long+'&addressdetails=1'; document.getElementsByTagName('head')[0].appendChild(s); }; function chr(x){ return String.fromCharCode(x); } function floor(x){ return Math.floor(x); } function coord2loc(lat, long){ var ychr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; var ynum = "0123456789"; var yqth, yi, yk, ydiv, yres, ylp, y; var y = 0; var ycalc = new Array(0,0,0); var yn = new Array(0,0,0,0,0,0,0); ycalc[1] = long + 0; ycalc[2] = lat + 0; for (yi = 1; yi < 3; ++yi) { for (yk = 1; yk < 4; ++yk) { if (yk != 3) { if (yi == 1) { if (yk == 1) ydiv = 20; if (yk == 2) ydiv = 2; } if (yi == 2) { if (yk == 1) ydiv = 10; if (yk == 2) ydiv = 1; } yres = ycalc[yi] / ydiv; ycalc[yi] = yres; if (ycalc[yi]>0) ylp = Math.floor(yres) else ylp = Math.ceil(yres); ycalc[yi] = (ycalc[yi] - ylp) * ydiv; } else { if (yi == 1) ydiv = 12 else ydiv = 24; yres = ycalc[yi] * ydiv; ycalc[yi] = yres; if (ycalc[yi] > 0) ylp = Math.floor(yres) else ylp = Math.ceil(yres); } ++y; yn[y] = ylp; } } yqth = ychr.charAt(yn[1]) + ychr.charAt(yn[4]) + ynum.charAt(yn[2]); yqth += ynum.charAt(yn[5]) + ychr.charAt(yn[3])+ ychr.charAt(yn[6]); return yqth; } $(window).bind("load", function() { // code here var coordinates = document.getElementById("locator").innerHTML; var splitcoord = coordinates.split(","); document.getElementById("locator").innerHTML = coord2loc(splitcoord[0].trim().slice(0,-1),splitcoord[1].trim().slice(0,-1)); });