From 1f22b625a045b7ce25a4668f404071aef8ab8b09 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 28 Feb 2014 00:10:55 +0000 Subject: [PATCH] Move cookieContent to OSM.locationCookie --- app/assets/javascripts/application.js | 6 ------ app/assets/javascripts/index.js | 2 +- app/assets/javascripts/osm.js.erb | 7 ++++++- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 75b48ac87..6ac398fc5 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -97,12 +97,6 @@ function updateLinks(loc, zoom, layers, object) { I18n.t('javascripts.site.edit_disabled_tooltip') : ''); } -// generate a cookie-safe string of map state -function cookieContent(map) { - var center = map.getCenter().wrap(); - return [center.lng, center.lat, map.getZoom(), map.getLayersCode()].join('|'); -} - function escapeHTML(string) { var htmlEscapes = { '&': '&', diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index 4a9abc4dc..dc3c93277 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -151,7 +151,7 @@ $(document).ready(function () { map._object); $.removeCookie("_osm_location"); - $.cookie("_osm_location", cookieContent(map), { expires: expiry, path: "/" }); + $.cookie("_osm_location", OSM.locationCookie(map), { expires: expiry, path: "/" }); }); if ($.cookie('_osm_welcome') == 'hide') { diff --git a/app/assets/javascripts/osm.js.erb b/app/assets/javascripts/osm.js.erb index 382e32bdf..bd65182a7 100644 --- a/app/assets/javascripts/osm.js.erb +++ b/app/assets/javascripts/osm.js.erb @@ -165,7 +165,12 @@ OSM = { return hash; }, - zoomPrecision: function (zoom) { + zoomPrecision: function(zoom) { return Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2)); + }, + + locationCookie: function(map) { + var center = map.getCenter().wrap(); + return [center.lng, center.lat, map.getZoom(), map.getLayersCode()].join('|'); } }; -- 2.39.5