]> git.openstreetmap.org Git - rails.git/commitdiff
Use location instead of window.location and document.location
authorAnton Khorev <tony29@yandex.ru>
Sat, 1 Mar 2025 09:01:31 +0000 (12:01 +0300)
committerAnton Khorev <tony29@yandex.ru>
Sat, 1 Mar 2025 09:01:31 +0000 (12:01 +0300)
14 files changed:
app/assets/javascripts/embed.js.erb
app/assets/javascripts/index.js
app/assets/javascripts/index/changeset.js
app/assets/javascripts/index/directions.js
app/assets/javascripts/index/history.js
app/assets/javascripts/index/note.js
app/assets/javascripts/index/query.js
app/assets/javascripts/leaflet.map.js
app/assets/javascripts/login.js
app/assets/javascripts/matomo.js
app/assets/javascripts/osm.js.erb
app/assets/javascripts/router.js
app/assets/javascripts/welcome.js
test/javascripts/osm_test.js

index aff13add80debee64834bcf9b8852a0c4201840e..7596e89a438dd3aa29ff17dedc4057167f05a12c 100644 (file)
@@ -16,7 +16,7 @@ I18n.default_locale = <%= I18n.default_locale.to_json %>;
 I18n.fallbacks = true;
 
 window.onload = function () {
-  const args = Object.fromEntries(new URLSearchParams(window.location.search));
+  const args = Object.fromEntries(new URLSearchParams(location.search));
 
   const tileOptions = {
     mapnik: {
index 96870f600869ab92c99a550820eeaecf499edebc..9888b3a7e5fc0abaefb76c141e289e1ce297f390 100644 (file)
@@ -311,7 +311,7 @@ $(document).ready(function () {
     };
 
     function addObject(type, id, version, center) {
-      const hashParams = OSM.parseHash(window.location.hash);
+      const hashParams = OSM.parseHash(location.hash);
       map.addObject({ type: type, id: parseInt(id, 10), version: version && parseInt(version, 10) }, function (bounds) {
         if (!hashParams.center && bounds.isValid() &&
             (center || !map.getBounds().contains(bounds))) {
@@ -363,7 +363,7 @@ $(document).ready(function () {
     "/account/home": OSM.Home(map)
   });
 
-  if (OSM.preferred_editor === "remote" && document.location.pathname === "/edit") {
+  if (OSM.preferred_editor === "remote" && location.pathname === "/edit") {
     remoteEditHandler(map.getBounds(), params.object);
     OSM.router.setCurrentPath("/");
   }
index 6c1c6a2df7a2df382120f7c23da38b2cf4be859f..6feefbc2dc0217d7645de3f0b8464a8b1d355a19 100644 (file)
@@ -12,7 +12,7 @@ OSM.Changeset = function (map) {
     const changesetData = content.find("[data-changeset]").data("changeset");
     changesetData.type = "changeset";
 
-    const hashParams = OSM.parseHash(window.location.hash);
+    const hashParams = OSM.parseHash(location.hash);
     initialize();
     map.addObject(changesetData, function (bounds) {
       if (!hashParams.center && bounds.isValid()) {
@@ -45,7 +45,7 @@ OSM.Changeset = function (map) {
         });
       })
       .then(() => {
-        OSM.loadSidebarContent(window.location.pathname, page.load);
+        OSM.loadSidebarContent(location.pathname, page.load);
       })
       .catch(error => {
         content.find("button[data-method][data-url]").prop("disabled", false);
index c6f83a575e04bc2cc9f0a84a95bdf35666306f81..97fa961d6993f141addd4718fef24839a9fbec66 100644 (file)
@@ -344,7 +344,7 @@ OSM.Directions = function (map) {
 OSM.Directions.engines = [];
 
 OSM.Directions.addEngine = function (engine, supportsHTTPS) {
-  if (document.location.protocol === "http:" || supportsHTTPS) {
+  if (location.protocol === "http:" || supportsHTTPS) {
     engine.id = engine.provider + "_" + engine.mode;
     OSM.Directions.engines.push(engine);
   }
index c36ae5f185683d58eddf99946e90bab7bd1bcc3c..6e4e73a23fa7e5564bcad943a6b78f4111a96680 100644 (file)
@@ -58,7 +58,7 @@ OSM.History = function (map) {
   function update() {
     const data = new URLSearchParams();
 
-    if (window.location.pathname === "/history") {
+    if (location.pathname === "/history") {
       data.set("bbox", map.getBounds().wrap().toBBoxString());
       const feedLink = $("link[type=\"application/atom+xml\"]"),
             feedHref = feedLink.attr("href").split("?")[0];
@@ -67,7 +67,7 @@ OSM.History = function (map) {
 
     data.set("list", "1");
 
-    fetch(window.location.pathname + "?" + data)
+    fetch(location.pathname + "?" + data)
       .then(response => response.text())
       .then(function (html) {
         displayFirstChangesets(html);
@@ -137,7 +137,7 @@ OSM.History = function (map) {
 
     updateBounds();
 
-    if (window.location.pathname !== "/history") {
+    if (location.pathname !== "/history") {
       const bounds = group.getBounds();
       if (bounds.isValid()) map.fitBounds(bounds);
     }
@@ -150,7 +150,7 @@ OSM.History = function (map) {
   page.load = function () {
     map.addLayer(group);
 
-    if (window.location.pathname === "/history") {
+    if (location.pathname === "/history") {
       map.on("moveend", update);
     }
 
index b9310a1af9e159d159dcef7254988d8623dc3983..3e8cbce1ba7870da38c2d4e070222a84c154a806 100644 (file)
@@ -79,7 +79,7 @@ OSM.Note = function (map) {
     const data = $(".details").data();
 
     if (data) {
-      const hashParams = OSM.parseHash(window.location.hash);
+      const hashParams = OSM.parseHash(location.hash);
       map.addObject({
         type: "note",
         id: parseInt(id, 10),
index ee9d3f41560c9a6ef9441b9fcac2d36dc1c13154..c0395c70182438a55854a8ce2068f552807d2f6b 100644 (file)
@@ -326,7 +326,7 @@ OSM.Query = function (map) {
     const params = new URLSearchParams(path.substring(path.indexOf("?"))),
           latlng = L.latLng(params.get("lat"), params.get("lon"));
 
-    if (!window.location.hash && !noCentre && !map.getBounds().contains(latlng)) {
+    if (!location.hash && !noCentre && !map.getBounds().contains(latlng)) {
       OSM.router.withoutMoveListener(function () {
         map.setView(latlng, 15);
       });
index 34c0bd449174a962e61124d3bd14f575999112ce..6adf2138d79c65c3826a10bce5b82a9617e0e3eb 100644 (file)
@@ -155,7 +155,7 @@ L.OSM.Map = L.Map.extend({
       [params.mlat, params.mlon] = OSM.cropLocation(marker.getLatLng(), this.getZoom());
     }
 
-    let url = window.location.protocol + "//" + OSM.SERVER_URL + "/";
+    let url = location.protocol + "//" + OSM.SERVER_URL + "/";
     const query = new URLSearchParams(params),
           hash = OSM.formatHash(this);
 
@@ -176,7 +176,7 @@ L.OSM.Map = L.Map.extend({
           // and drops the last 4 bits of the full 64 bit Morton code.
           c1 = interlace(x >>> 17, y >>> 17),
           c2 = interlace((x >>> 2) & 0x7fff, (y >>> 2) & 0x7fff);
-    let str = window.location.protocol + "//" + window.location.hostname.replace(/^www\.openstreetmap\.org/i, "osm.org") + "/go/";
+    let str = location.protocol + "//" + location.hostname.replace(/^www\.openstreetmap\.org/i, "osm.org") + "/go/";
 
     for (let i = 0; i < Math.ceil((zoom + 8) / 3.0) && i < 5; ++i) {
       const digit = (c1 >> (24 - (6 * i))) & 0x3f;
index 83ca4d440dd3b238797529b252a6684b5729dca6..078792821e69954c337bca8f220ec9212f5ef626 100644 (file)
@@ -1,6 +1,6 @@
 $(document).ready(function () {
   // Preserve location hash in referer
-  if (window.location.hash) {
-    $("#referer").val($("#referer").val() + window.location.hash);
+  if (location.hash) {
+    $("#referer").val($("#referer").val() + location.hash);
   }
 });
index 4ed3de941bfc05255f5bc33f228a00fb2c822c76..2c9968b08097ab7afd34266bdca38bef13be0941 100644 (file)
@@ -1,6 +1,6 @@
 if (OSM.MATOMO) {
   $(document).ready(function () {
-    const base = document.location.protocol + "//" + OSM.MATOMO.location + "/";
+    const base = location.protocol + "//" + OSM.MATOMO.location + "/";
     let matomoTracker;
 
     const matomoLoader = $.ajax({
index 25d6596c2cd6fb160ef54bdba6641ee79e6c8a76..a40ae6eb87995c1d031cf03330bcae422af0a58b 100644 (file)
@@ -57,7 +57,7 @@ OSM = {
   },
 
   params: function (search) {
-    const query = search || window.location.search;
+    const query = search || location.search;
     return Object.fromEntries(new URLSearchParams(query));
   },
 
index 2e4b375d79691b0bd7253fce4bcf8671530465b9..22795195cd06660c2593aa44abc741e7fb7c40a4 100644 (file)
@@ -93,7 +93,7 @@ OSM.Router = function (map, rts) {
     }
   };
 
-  let currentPath = window.location.pathname.replace(/(.)\/$/, "$1") + window.location.search,
+  let currentPath = location.pathname.replace(/(.)\/$/, "$1") + location.search,
       currentRoute = routes.recognize(currentPath),
       currentHash = location.hash || OSM.formatHash(map);
 
@@ -101,7 +101,7 @@ OSM.Router = function (map, rts) {
 
   function updateSecondaryNav() {
     $("header nav.secondary > ul > li > a").each(function () {
-      const active = $(this).attr("href") === window.location.pathname;
+      const active = $(this).attr("href") === location.pathname;
 
       $(this)
         .toggleClass("text-secondary", !active)
@@ -111,7 +111,7 @@ OSM.Router = function (map, rts) {
 
   $(window).on("popstate", function (e) {
     if (!e.originalEvent.state) return; // Is it a real popstate event or just a hash change?
-    const path = window.location.pathname + window.location.search,
+    const path = location.pathname + location.search,
           route = routes.recognize(path);
     if (path === currentPath) return;
     currentRoute.run("unload", null, route === currentRoute);
@@ -142,7 +142,7 @@ OSM.Router = function (map, rts) {
   };
 
   router.stateChange = function (state) {
-    const url = state.center ? OSM.formatHash(state) : window.location;
+    const url = state.center ? OSM.formatHash(state) : location;
     window.history.replaceState(state, document.title, url);
   };
 
index 3e2845bb3bda0e8a0404a30661cd1e07f27f377c..41d45bbf8ee9a40a212e94116c9bd32ebdd6a77f 100644 (file)
@@ -27,7 +27,7 @@ $(document).ready(function () {
   }
 
   function geoSuccess(position) {
-    window.location = "/edit" + OSM.formatHash({
+    location = "/edit" + OSM.formatHash({
       zoom: 17,
       lat: position.coords.latitude,
       lon: position.coords.longitude
@@ -35,6 +35,6 @@ $(document).ready(function () {
   }
 
   function manualEdit() {
-    window.location = "/?edit_help=1";
+    location = "/?edit_help=1";
   }
 });
index 877af5ad71adf783aaadc38e54447af99ffd34cd..2f96ccb3d4a2de806ab3bca1a806847672c42d74 100644 (file)
@@ -33,7 +33,7 @@ describe("OSM", function () {
     beforeEach(function () {
       delete OSM.home;
       delete OSM.location;
-      document.location.hash = "";
+      location.hash = "";
       document.cookie = "_osm_location=; expires=Thu, 01 Jan 1970 00:00:00 GMT";
 
       // Test with another cookie set.
@@ -83,7 +83,7 @@ describe("OSM", function () {
     });
 
     it("parses lat/lon/zoom from the hash", function () {
-      document.location.hash = "#map=16/57.6247/-3.6845";
+      location.hash = "#map=16/57.6247/-3.6845";
       const params = OSM.mapParams("?");
       expect(params).to.have.property("lat", 57.6247);
       expect(params).to.have.property("lon", -3.6845);
@@ -133,7 +133,7 @@ describe("OSM", function () {
       params = OSM.mapParams("?");
       expect(params).to.have.property("layers", "C");
 
-      document.location.hash = "#map=5/57.6247/-3.6845&layers=M";
+      location.hash = "#map=5/57.6247/-3.6845&layers=M";
       params = OSM.mapParams("?");
       expect(params).to.have.property("layers", "M");
     });