X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/c50e4f50c4fef0b11970202d3c7f95cdc5b620ba..31ff6090206711b01ef8d9838c9de1b60babc0d6:/app/assets/javascripts/index.js diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index 0fa85a0cc..b79c33088 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -24,7 +24,7 @@ //= require index/home //= require router -$(document).ready(function () { +$(function () { const map = new L.OSM.Map("map", { zoomControl: false, layerControl: false, @@ -37,7 +37,7 @@ $(document).ready(function () { map.setSidebarOverlaid(false); - $("#sidebar_loader").show().addClass("delayed-fade-in"); + $("#sidebar_loader").prop("hidden", false).addClass("delayed-fade-in"); // Prevent caching the XHR response as a full-page URL // https://github.com/openstreetmap/openstreetmap-website/issues/5663 @@ -53,7 +53,7 @@ $(document).ready(function () { fetch(content_path, { headers: { "accept": "text/html", "x-requested-with": "XMLHttpRequest" } }) .then(response => { $("#flash").empty(); - $("#sidebar_loader").removeClass("delayed-fade-in").hide(); + $("#sidebar_loader").removeClass("delayed-fade-in").prop("hidden", true); const title = response.headers.get("X-Page-Title"); if (title) document.title = decodeURIComponent(title); @@ -236,20 +236,20 @@ $(document).ready(function () { }); if (object && object.type !== "note") query.set("select", object.type + object.id); // can't select notes - sendRemoteEditCommand(remoteEditHost + "/load_and_zoom?" + query, function () { - if (object && object.type === "note") { - const noteQuery = new URLSearchParams({ url: osmHost + OSM.apiUrl(object) }); - sendRemoteEditCommand(remoteEditHost + "/import?" + noteQuery); - } - }); + sendRemoteEditCommand(remoteEditHost + "/load_and_zoom?" + query) + .then(() => { + if (object && object.type === "note") { + const noteQuery = new URLSearchParams({ url: osmHost + OSM.apiUrl(object) }); + sendRemoteEditCommand(remoteEditHost + "/import?" + noteQuery); + } + }) + .catch(() => { + // eslint-disable-next-line no-alert + alert(I18n.t("site.index.remote_failed")); + }); - function sendRemoteEditCommand(url, callback) { - fetch(url, { mode: "no-cors", signal: AbortSignal.timeout(5000) }) - .then(callback) - .catch(function () { - // eslint-disable-next-line no-alert - alert(I18n.t("site.index.remote_failed")); - }); + function sendRemoteEditCommand(url) { + return fetch(url, { mode: "no-cors", signal: AbortSignal.timeout(5000) }); } return false; @@ -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("/"); } @@ -380,6 +380,11 @@ $(document).ready(function () { return; } + // Open local anchor links as normal. + if ($(this).attr("href")?.startsWith("#")) { + return; + } + // Ignore cross-protocol and cross-origin links. if (location.protocol !== this.protocol || location.host !== this.host) { return;