From 05bc2b70edaa9a36925139d481f0749436a4bd66 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Sat, 27 Jun 2009 16:07:53 +0000 Subject: [PATCH] Only hardcode http://osm.org/ in shortlinks when we're at openstreetmap.org (according to window.location.hostname). Solves ticket:1994 and my headaches when trying to hack railsport locally. --- public/javascripts/site.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/public/javascripts/site.js b/public/javascripts/site.js index 5340ea99e..f9c3e7a54 100644 --- a/public/javascripts/site.js +++ b/public/javascripts/site.js @@ -92,17 +92,36 @@ function updatelinks(lon,lat,zoom,layers,minlon,minlat,maxlon,maxlat, obj_type, if (node) { var args = getArgs(node.href); var code = makeShortCode(lat, lon, zoom); + var prefix = shortlinkPrefix(); + // 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("http://osm.org/go/" + code, args); + node.href = setArgs(prefix + "/go/" + code, args); } else { - node.href = "http://osm.org/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("?"); -- 2.43.2