From 32cc04fa5cddda8e06412830ef7a9238544c6721 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Mon, 17 May 2021 18:57:48 +0100 Subject: [PATCH] Switch to using js-cookie to manage cookies from javascript --- app/assets/javascripts/application.js | 2 +- app/assets/javascripts/index.js | 10 +++++----- app/assets/javascripts/index/directions.js | 6 +++--- app/assets/javascripts/osm.js.erb | 2 +- package.json | 2 +- yarn.lock | 8 ++++---- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index cbb69119c..8e6bf0790 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -1,8 +1,8 @@ //= require jquery3 //= require jquery_ujs //= require jquery.timers -//= require jquery.cookie/jquery.cookie //= require jquery.throttle-debounce +//= require js-cookie/src/js.cookie //= require popper //= require bootstrap-sprockets //= require osm diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index a2169643f..9305a5415 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -188,17 +188,17 @@ $(document).ready(function () { map.getLayersCode(), map._object); - $.removeCookie("_osm_location"); - $.cookie("_osm_location", OSM.locationCookie(map), { secure: true, expires: expiry, path: "/" }); + Cookies.remove("_osm_location"); + Cookies.set("_osm_location", OSM.locationCookie(map), { secure: true, expires: expiry, path: "/" }); }); - if ($.cookie("_osm_welcome") !== "hide") { + if (Cookies.get("_osm_welcome") !== "hide") { $(".welcome").addClass("visible"); } $(".welcome .close").on("click", function () { $(".welcome").removeClass("visible"); - $.cookie("_osm_welcome", "hide", { secure: true, expires: expiry, path: "/" }); + Cookies.set("_osm_welcome", "hide", { secure: true, expires: expiry, path: "/" }); }); var bannerExpiry = new Date(); @@ -209,7 +209,7 @@ $(document).ready(function () { $("#banner").hide(); e.preventDefault(); if (cookieId) { - $.cookie(cookieId, "hide", { secure: true, expires: bannerExpiry, path: "/" }); + Cookies.set(cookieId, "hide", { secure: true, expires: bannerExpiry, path: "/" }); } }); diff --git a/app/assets/javascripts/index/directions.js b/app/assets/javascripts/index/directions.js index a58b0af16..93024d0a9 100644 --- a/app/assets/javascripts/index/directions.js +++ b/app/assets/javascripts/index/directions.js @@ -327,14 +327,14 @@ OSM.Directions = function (map) { } var chosenEngineIndex = findEngine("fossgis_osrm_car"); - if ($.cookie("_osm_directions_engine")) { - chosenEngineIndex = findEngine($.cookie("_osm_directions_engine")); + if (Cookies.get("_osm_directions_engine")) { + chosenEngineIndex = findEngine(Cookies.get("_osm_directions_engine")); } setEngine(chosenEngineIndex); select.on("change", function (e) { chosenEngine = engines[e.target.selectedIndex]; - $.cookie("_osm_directions_engine", chosenEngine.id, { secure: true, expires: expiry, path: "/" }); + Cookies.set("_osm_directions_engine", chosenEngine.id, { secure: true, expires: expiry, path: "/" }); getRoute(true, true); }); diff --git a/app/assets/javascripts/osm.js.erb b/app/assets/javascripts/osm.js.erb index 5c15e08e6..529ac3bea 100644 --- a/app/assets/javascripts/osm.js.erb +++ b/app/assets/javascripts/osm.js.erb @@ -107,7 +107,7 @@ OSM = { mapParams.lon = parseFloat(params.mlon); mapParams.lat = parseFloat(params.mlat); mapParams.zoom = parseInt(params.zoom || 12); - } else if (loc = $.cookie('_osm_location')) { + } else if (loc = Cookies.get('_osm_location')) { loc = loc.split("|"); mapParams.lon = parseFloat(loc[0]); mapParams.lat = parseFloat(loc[1]); diff --git a/package.json b/package.json index 79f324107..d5e2b7f34 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "bs-custom-file-input": "^1.3.4", "html5shiv": "^3.7.3", "jquery-simulate": "^1.0.2", - "jquery.cookie": "^1.4.1", + "js-cookie": "^2.2.1", "leaflet": "^1.6.0", "leaflet.locatecontrol": "^0.73.0", "ohauth": "^1.0.0", diff --git a/yarn.lock b/yarn.lock index 93e2a99c7..3d22856b7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -522,10 +522,10 @@ jquery-simulate@^1.0.2: resolved "https://registry.yarnpkg.com/jquery-simulate/-/jquery-simulate-1.0.2.tgz#2174b859b75123a0ac6d8ab3a9a6fb4ad7e82898" integrity sha512-Bq610fSrwTwvH5d06z5oskYaX/79s0BNrKiJZjZOiXRib3iL4ZkSn/wvLwzhf3P9KeXCEpk9wlIaGui/1arOpQ== -jquery.cookie@^1.4.1: - version "1.4.1" - resolved "https://registry.yarnpkg.com/jquery.cookie/-/jquery.cookie-1.4.1.tgz#d63dce209eab691fe63316db08ca9e47e0f9385b" - integrity sha1-1j3OIJ6raR/mMxbbCMqeR+D5OFs= +js-cookie@^2.2.1: + version "2.2.1" + resolved "https://registry.yarnpkg.com/js-cookie/-/js-cookie-2.2.1.tgz#69e106dc5d5806894562902aa5baec3744e9b2b8" + integrity sha512-HvdH2LzI/EAZcUwA8+0nKNtWHqS+ZmijLA30RwZA0bo7ToCckjK5MkGhjED9KoRcXO6BaGI3I9UIzSA1FKFPOQ== js-tokens@^4.0.0: version "4.0.0" -- 2.45.1