]> git.openstreetmap.org Git - rails.git/blobdiff - public/javascripts/site.js
Make ?{node,way,relation}=id GET argumens work for the shortlink as
[rails.git] / public / javascripts / site.js
index 23ea3bc6839acf7bffe4226e7dce207454942001..66c5d81fc9814b19d8d8e912587d1f580bcc639f 100644 (file)
@@ -2,7 +2,7 @@
  * Called as the user scrolls/zooms around to aniplate hrefs of the
  * view tab and various other links
  */
-function updatelinks(lon,lat,zoom,layers,minlon,minlat,maxlon,maxlat) {
+function updatelinks(lon,lat,zoom,layers,minlon,minlat,maxlon,maxlat, obj_type, obj_id) {
   var decimals = Math.pow(10, Math.floor(zoom/3));
   var node;
 
@@ -18,6 +18,9 @@ function updatelinks(lon,lat,zoom,layers,minlon,minlat,maxlon,maxlat) {
     if (layers) {
       args["layers"] = layers;
     }
+    if (obj_type && obj_id) {
+      args[obj_type] = obj_id;
+    }
     node.href = setArgs(node.href, args);
   }
 
@@ -89,17 +92,41 @@ function updatelinks(lon,lat,zoom,layers,minlon,minlat,maxlon,maxlat) {
   if (node) {
     var args = getArgs(node.href);
     var code = makeShortCode(lat, lon, zoom);
+    var prefix = shortlinkPrefix();
+
+    // Add ?{node,way,relation}=id to the arguments
+    if (obj_type && obj_id) {
+      args[obj_type] = obj_id;
+    }
+
     // little hack. may the gods of hardcoding please forgive me, or 
     // show me the Right way to do it.
     if (layers && (layers != "B000FTF")) {
       args["layers"] = layers;
-      node.href = setArgs("/go/" + code, args);
+      node.href = setArgs(prefix + "/go/" + code, args);
     } else {
-      node.href = "/go/" + code;
+      node.href = prefix + "/go/" + code;
     }
   }
 }
 
+
+/*
+ * This is a hack to hardcode opestreetmap.org -> osm.org in the
+ * shortlink
+ */
+function shortlinkPrefix() {
+    var hostname = window.location.hostname;
+    var normalized_hostname = hostname.replace(/^:www\./i,'');
+    var prefix = '';
+
+    if (normalized_hostname.match(/^openstreetmap\.org$/i)) {
+        prefix = "http://osm.org";
+    }
+
+    return prefix;
+}
+
 function getArgs(url) {
   var args = new Object();
   var querystart = url.indexOf("?");