Merge remote-tracking branch 'upstream/pull/5739'

This commit is contained in:
Tom Hughes 2025-03-01 12:27:36 +00:00
commit cf3c627c1a
14 changed files with 27 additions and 27 deletions

View file

@ -16,7 +16,7 @@ I18n.default_locale = <%= I18n.default_locale.to_json %>;
I18n.fallbacks = true; I18n.fallbacks = true;
window.onload = function () { window.onload = function () {
const args = Object.fromEntries(new URLSearchParams(window.location.search)); const args = Object.fromEntries(new URLSearchParams(location.search));
const tileOptions = { const tileOptions = {
mapnik: { mapnik: {

View file

@ -311,7 +311,7 @@ $(document).ready(function () {
}; };
function addObject(type, id, version, center) { 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) { map.addObject({ type: type, id: parseInt(id, 10), version: version && parseInt(version, 10) }, function (bounds) {
if (!hashParams.center && bounds.isValid() && if (!hashParams.center && bounds.isValid() &&
(center || !map.getBounds().contains(bounds))) { (center || !map.getBounds().contains(bounds))) {
@ -363,7 +363,7 @@ $(document).ready(function () {
"/account/home": OSM.Home(map) "/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); remoteEditHandler(map.getBounds(), params.object);
OSM.router.setCurrentPath("/"); OSM.router.setCurrentPath("/");
} }

View file

@ -12,7 +12,7 @@ OSM.Changeset = function (map) {
const changesetData = content.find("[data-changeset]").data("changeset"); const changesetData = content.find("[data-changeset]").data("changeset");
changesetData.type = "changeset"; changesetData.type = "changeset";
const hashParams = OSM.parseHash(window.location.hash); const hashParams = OSM.parseHash(location.hash);
initialize(); initialize();
map.addObject(changesetData, function (bounds) { map.addObject(changesetData, function (bounds) {
if (!hashParams.center && bounds.isValid()) { if (!hashParams.center && bounds.isValid()) {
@ -45,7 +45,7 @@ OSM.Changeset = function (map) {
}); });
}) })
.then(() => { .then(() => {
OSM.loadSidebarContent(window.location.pathname, page.load); OSM.loadSidebarContent(location.pathname, page.load);
}) })
.catch(error => { .catch(error => {
content.find("button[data-method][data-url]").prop("disabled", false); content.find("button[data-method][data-url]").prop("disabled", false);

View file

@ -346,7 +346,7 @@ OSM.Directions = function (map) {
OSM.Directions.engines = []; OSM.Directions.engines = [];
OSM.Directions.addEngine = function (engine, supportsHTTPS) { OSM.Directions.addEngine = function (engine, supportsHTTPS) {
if (document.location.protocol === "http:" || supportsHTTPS) { if (location.protocol === "http:" || supportsHTTPS) {
engine.id = engine.provider + "_" + engine.mode; engine.id = engine.provider + "_" + engine.mode;
OSM.Directions.engines.push(engine); OSM.Directions.engines.push(engine);
} }

View file

@ -58,7 +58,7 @@ OSM.History = function (map) {
function update() { function update() {
const data = new URLSearchParams(); const data = new URLSearchParams();
if (window.location.pathname === "/history") { if (location.pathname === "/history") {
data.set("bbox", map.getBounds().wrap().toBBoxString()); data.set("bbox", map.getBounds().wrap().toBBoxString());
const feedLink = $("link[type=\"application/atom+xml\"]"), const feedLink = $("link[type=\"application/atom+xml\"]"),
feedHref = feedLink.attr("href").split("?")[0]; feedHref = feedLink.attr("href").split("?")[0];
@ -67,7 +67,7 @@ OSM.History = function (map) {
data.set("list", "1"); data.set("list", "1");
fetch(window.location.pathname + "?" + data) fetch(location.pathname + "?" + data)
.then(response => response.text()) .then(response => response.text())
.then(function (html) { .then(function (html) {
displayFirstChangesets(html); displayFirstChangesets(html);
@ -137,7 +137,7 @@ OSM.History = function (map) {
updateBounds(); updateBounds();
if (window.location.pathname !== "/history") { if (location.pathname !== "/history") {
const bounds = group.getBounds(); const bounds = group.getBounds();
if (bounds.isValid()) map.fitBounds(bounds); if (bounds.isValid()) map.fitBounds(bounds);
} }
@ -150,7 +150,7 @@ OSM.History = function (map) {
page.load = function () { page.load = function () {
map.addLayer(group); map.addLayer(group);
if (window.location.pathname === "/history") { if (location.pathname === "/history") {
map.on("moveend", update); map.on("moveend", update);
} }

View file

@ -79,7 +79,7 @@ OSM.Note = function (map) {
const data = $(".details").data(); const data = $(".details").data();
if (data) { if (data) {
const hashParams = OSM.parseHash(window.location.hash); const hashParams = OSM.parseHash(location.hash);
map.addObject({ map.addObject({
type: "note", type: "note",
id: parseInt(id, 10), id: parseInt(id, 10),

View file

@ -326,7 +326,7 @@ OSM.Query = function (map) {
const params = new URLSearchParams(path.substring(path.indexOf("?"))), const params = new URLSearchParams(path.substring(path.indexOf("?"))),
latlng = L.latLng(params.get("lat"), params.get("lon")); 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 () { OSM.router.withoutMoveListener(function () {
map.setView(latlng, 15); map.setView(latlng, 15);
}); });

View file

@ -155,7 +155,7 @@ L.OSM.Map = L.Map.extend({
[params.mlat, params.mlon] = OSM.cropLocation(marker.getLatLng(), this.getZoom()); [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), const query = new URLSearchParams(params),
hash = OSM.formatHash(this); 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. // and drops the last 4 bits of the full 64 bit Morton code.
c1 = interlace(x >>> 17, y >>> 17), c1 = interlace(x >>> 17, y >>> 17),
c2 = interlace((x >>> 2) & 0x7fff, (y >>> 2) & 0x7fff); 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) { for (let i = 0; i < Math.ceil((zoom + 8) / 3.0) && i < 5; ++i) {
const digit = (c1 >> (24 - (6 * i))) & 0x3f; const digit = (c1 >> (24 - (6 * i))) & 0x3f;

View file

@ -1,6 +1,6 @@
$(document).ready(function () { $(document).ready(function () {
// Preserve location hash in referer // Preserve location hash in referer
if (window.location.hash) { if (location.hash) {
$("#referer").val($("#referer").val() + window.location.hash); $("#referer").val($("#referer").val() + location.hash);
} }
}); });

View file

@ -1,6 +1,6 @@
if (OSM.MATOMO) { if (OSM.MATOMO) {
$(document).ready(function () { $(document).ready(function () {
const base = document.location.protocol + "//" + OSM.MATOMO.location + "/"; const base = location.protocol + "//" + OSM.MATOMO.location + "/";
let matomoTracker; let matomoTracker;
const matomoLoader = $.ajax({ const matomoLoader = $.ajax({

View file

@ -57,7 +57,7 @@ OSM = {
}, },
params: function (search) { params: function (search) {
const query = search || window.location.search; const query = search || location.search;
return Object.fromEntries(new URLSearchParams(query)); return Object.fromEntries(new URLSearchParams(query));
}, },

View 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), currentRoute = routes.recognize(currentPath),
currentHash = location.hash || OSM.formatHash(map); currentHash = location.hash || OSM.formatHash(map);
@ -101,7 +101,7 @@ OSM.Router = function (map, rts) {
function updateSecondaryNav() { function updateSecondaryNav() {
$("header nav.secondary > ul > li > a").each(function () { $("header nav.secondary > ul > li > a").each(function () {
const active = $(this).attr("href") === window.location.pathname; const active = $(this).attr("href") === location.pathname;
$(this) $(this)
.toggleClass("text-secondary", !active) .toggleClass("text-secondary", !active)
@ -111,7 +111,7 @@ OSM.Router = function (map, rts) {
$(window).on("popstate", function (e) { $(window).on("popstate", function (e) {
if (!e.originalEvent.state) return; // Is it a real popstate event or just a hash change? 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); route = routes.recognize(path);
if (path === currentPath) return; if (path === currentPath) return;
currentRoute.run("unload", null, route === currentRoute); currentRoute.run("unload", null, route === currentRoute);
@ -142,7 +142,7 @@ OSM.Router = function (map, rts) {
}; };
router.stateChange = function (state) { 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); window.history.replaceState(state, document.title, url);
}; };

View file

@ -27,7 +27,7 @@ $(document).ready(function () {
} }
function geoSuccess(position) { function geoSuccess(position) {
window.location = "/edit" + OSM.formatHash({ location = "/edit" + OSM.formatHash({
zoom: 17, zoom: 17,
lat: position.coords.latitude, lat: position.coords.latitude,
lon: position.coords.longitude lon: position.coords.longitude
@ -35,6 +35,6 @@ $(document).ready(function () {
} }
function manualEdit() { function manualEdit() {
window.location = "/?edit_help=1"; location = "/?edit_help=1";
} }
}); });

View file

@ -33,7 +33,7 @@ describe("OSM", function () {
beforeEach(function () { beforeEach(function () {
delete OSM.home; delete OSM.home;
delete OSM.location; delete OSM.location;
document.location.hash = ""; location.hash = "";
document.cookie = "_osm_location=; expires=Thu, 01 Jan 1970 00:00:00 GMT"; document.cookie = "_osm_location=; expires=Thu, 01 Jan 1970 00:00:00 GMT";
// Test with another cookie set. // Test with another cookie set.
@ -83,7 +83,7 @@ describe("OSM", function () {
}); });
it("parses lat/lon/zoom from the hash", 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("?"); const params = OSM.mapParams("?");
expect(params).to.have.property("lat", 57.6247); expect(params).to.have.property("lat", 57.6247);
expect(params).to.have.property("lon", -3.6845); expect(params).to.have.property("lon", -3.6845);
@ -133,7 +133,7 @@ describe("OSM", function () {
params = OSM.mapParams("?"); params = OSM.mapParams("?");
expect(params).to.have.property("layers", "C"); 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("?"); params = OSM.mapParams("?");
expect(params).to.have.property("layers", "M"); expect(params).to.have.property("layers", "M");
}); });