From 483854f411ce7106144883824adb7e49060424c2 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Mon, 10 Jun 2013 13:58:15 -0700 Subject: [PATCH] Start to refactor updatelinks --- app/assets/javascripts/application.js | 20 ++++++++++++-------- app/assets/javascripts/browse.js | 9 +++------ app/assets/javascripts/index.js | 3 +-- app/views/site/_potlatch2.html.erb | 4 ++-- app/views/site/id.html.erb | 7 ++++--- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 2ea378787..7e9584d09 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -31,12 +31,12 @@ function zoomPrecision(zoom) { * 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,object) { +function updatelinks(loc, zoom, layers, minlon, minlat, maxlon, maxlat, object) { var toPrecision = zoomPrecision(zoom); var node; - lat = toPrecision(lat); - lon = toPrecision(lon); + var lat = toPrecision(loc.lat), + lon = toPrecision(loc.lon || loc.lng); if (minlon) { minlon = toPrecision(minlon); @@ -74,18 +74,22 @@ function updatelinks(lon,lat,zoom,layers,minlon,minlat,maxlon,maxlat,object) { $(link).off("click.minzoom"); if (zoom >= minzoom) { - $(link).attr("title", I18n.t("javascripts.site." + name + "_tooltip")); - $(link).removeClass("disabled"); + $(link).attr("title", I18n.t("javascripts.site." + name + "_tooltip")) + .removeClass("disabled"); } else { - $(link).on("click.minzoom", function () { alert(I18n.t("javascripts.site." + name + "_zoom_alert")); return false; }); - $(link).attr("title", I18n.t("javascripts.site." + name + "_disabled_tooltip")); - $(link).addClass("disabled"); + $(link).on("click.minzoom", minZoomAlert) + .attr("title", I18n.t("javascripts.site." + name + "_disabled_tooltip")) + .addClass("disabled"); } } link.href = setArgs(link.href, args); } + function minZoomAlert() { + alert(I18n.t("javascripts.site." + name + "_zoom_alert")); return false; + } + function setShortlink() { var args = getArgs(this.href); var code = makeShortCode(lat, lon, zoom); diff --git a/app/assets/javascripts/browse.js b/app/assets/javascripts/browse.js index 0b60778d6..c459b77a5 100644 --- a/app/assets/javascripts/browse.js +++ b/app/assets/javascripts/browse.js @@ -53,8 +53,7 @@ $(document).ready(function () { return remoteEditHandler(bbox); }); - var centre = bbox.getCenter(); - updatelinks(centre.lng, centre.lat, 16, null, params.minlon, params.minlat, params.maxlon, params.maxlat); + updatelinks(map.getCenter(), 16, null, params.minlon, params.minlat, params.maxlon, params.maxlat); } else if (params.type == "note") { var object = {type: params.type, id: params.id}; @@ -71,7 +70,7 @@ $(document).ready(function () { return remoteEditHandler(bbox); }); - updatelinks(params.lon, params.lat, 16, null, + updatelinks(params, 16, null, bbox.getWest(), bbox.getSouth(), bbox.getEast(), bbox.getNorth(), object); @@ -103,9 +102,7 @@ $(document).ready(function () { $("#object_larger_map").show(); $("#object_edit").show(); - var centre = extent.getCenter(); - updatelinks(centre.lng, - centre.lat, + updatelinks(map.getCenter(), 16, null, extent.getWest(), extent.getSouth(), diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index ba2aa2644..e4dbb84d0 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -114,8 +114,7 @@ $(document).ready(function () { var layers = getMapLayers(); var extents = map.getBounds().wrap(); - updatelinks(center.lng, - center.lat, + updatelinks(center, zoom, layers, extents.getWest(), diff --git a/app/views/site/_potlatch2.html.erb b/app/views/site/_potlatch2.html.erb index f77f67f52..a7fa1bac6 100644 --- a/app/views/site/_potlatch2.html.erb +++ b/app/views/site/_potlatch2.html.erb @@ -64,7 +64,7 @@ // 700,600 for fixed size, 100%,100% for resizable if (lat && lon) { - updatelinks(lon, lat, zoom); + updatelinks({ lon: lon, lat: lat }, zoom); } } @@ -86,6 +86,6 @@ }); function mapMoved(lon, lat, zoom, minlon, minlat, maxlon, maxlat) { - updatelinks(lon, lat, zoom, null, minlon, minlat, maxlon, maxlat); + updatelinks({ lon: lon, lat: lat }, zoom, null, minlon, minlat, maxlon, maxlat); } diff --git a/app/views/site/id.html.erb b/app/views/site/id.html.erb index aaa3927a9..3db8b80be 100644 --- a/app/views/site/id.html.erb +++ b/app/views/site/id.html.erb @@ -36,9 +36,10 @@ zoom = ~~id.map().zoom(), center = id.map().center(); - parent.updatelinks( - center[0], - center[1], + parent.updatelinks({ + lon: center[0], + lat: center[1] + }, zoom, null, extent[0][0], -- 2.39.5