X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/6094a97ce6297d390e5bbf733f5c2b4cc6b2076c..aebacc88de18c24c583a12b589eb98cf0b826627:/app/assets/javascripts/index.js diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index 56495b31a..c3ee1e3bc 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -22,7 +22,6 @@ //= require index/changeset //= require index/query //= require router -//= require qs/dist/qs $(document).ready(function () { var map = new L.OSM.Map("map", { @@ -39,30 +38,21 @@ $(document).ready(function () { $("#sidebar_loader").show().addClass("delayed-fade-in"); - // IE<10 doesn't respect Vary: X-Requested-With header, so - // prevent caching the XHR response as a full-page URL. - if (content_path.indexOf("?") >= 0) { - content_path += "&xhr=1"; - } else { - content_path += "?xhr=1"; - } - $("#sidebar_content") .empty(); - $.ajax({ - url: content_path, - dataType: "html", - complete: function (xhr) { + fetch(content_path, { headers: { "accept": "text/html", "x-requested-with": "XMLHttpRequest" } }) + .then(response => { $("#flash").empty(); $("#sidebar_loader").removeClass("delayed-fade-in").hide(); - var content = $(xhr.responseText); + const title = response.headers.get("X-Page-Title"); + if (title) document.title = decodeURIComponent(title); - if (xhr.getResponseHeader("X-Page-Title")) { - var title = xhr.getResponseHeader("X-Page-Title"); - document.title = decodeURIComponent(title); - } + return response.text(); + }) + .then(html => { + const content = $(html); $("head") .find("link[type=\"application/atom+xml\"]") @@ -76,8 +66,7 @@ $(document).ready(function () { if (callback) { callback(); } - } - }); + }); }; var params = OSM.mapParams(); @@ -98,9 +87,7 @@ $(document).ready(function () { var position = $("html").attr("dir") === "rtl" ? "topleft" : "topright"; function addControlGroup(controls) { - controls.forEach(function (control) { - control.addTo(map); - }); + for (const control of controls) control.addTo(map); var firstContainer = controls[0].getContainer(); $(firstContainer).find(".control-button").first() @@ -173,7 +160,7 @@ $(document).ready(function () { var expiry = new Date(); expiry.setYear(expiry.getFullYear() + 10); - map.on("moveend layeradd layerremove", function () { + map.on("moveend baselayerchange overlayadd overlayremove", function () { updateLinks( map.getCenter().wrap(), map.getZoom(), @@ -205,7 +192,7 @@ $(document).ready(function () { }); if (OSM.MATOMO) { - map.on("layeradd", function (e) { + map.on("baselayerchange overlayadd", function (e) { if (e.layer.options) { var goal = OSM.MATOMO.goals[e.layer.options.layerId]; @@ -239,18 +226,18 @@ $(document).ready(function () { function remoteEditHandler(bbox, object) { var remoteEditHost = "http://127.0.0.1:8111", osmHost = location.protocol + "//" + location.host, - query = { + query = new URLSearchParams({ left: bbox.getWest() - 0.0001, top: bbox.getNorth() + 0.0001, right: bbox.getEast() + 0.0001, bottom: bbox.getSouth() - 0.0001 - }; + }); - if (object && object.type !== "note") query.select = object.type + object.id; // can't select notes - sendRemoteEditCommand(remoteEditHost + "/load_and_zoom?" + Qs.stringify(query), 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") { - var noteQuery = { url: osmHost + OSM.apiUrl(object) }; - sendRemoteEditCommand(remoteEditHost + "/import?" + Qs.stringify(noteQuery)); + const noteQuery = new URLSearchParams({ url: osmHost + OSM.apiUrl(object) }); + sendRemoteEditCommand(remoteEditHost + "/import?" + noteQuery); } }); @@ -258,6 +245,7 @@ $(document).ready(function () { 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")); }); } @@ -294,9 +282,9 @@ $(document).ready(function () { }; page.load = function () { - var params = Qs.parse(location.search.substring(1)); - if (params.query) { - $("#sidebar .search_form input[name=query]").value(params.query); + const params = new URLSearchParams(location.search); + if (params.has("query")) { + $("#sidebar .search_form input[name=query]").value(params.get("query")); } if (!("autofocus" in document.createElement("input"))) { $("#sidebar .search_form input[name=query]").focus();