$("#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\"]")
if (callback) {
callback();
}
- }
- });
+ });
};
var params = OSM.mapParams();
}
function update() {
- var data = { list: "1" };
+ const data = new URLSearchParams();
if (window.location.pathname === "/history") {
- data.bbox = map.getBounds().wrap().toBBoxString();
+ data.set("bbox", map.getBounds().wrap().toBBoxString());
var feedLink = $("link[type=\"application/atom+xml\"]"),
feedHref = feedLink.attr("href").split("?")[0];
- feedLink.attr("href", feedHref + "?bbox=" + data.bbox);
+ feedLink.attr("href", feedHref + "?" + data);
}
- $.ajax({
- url: window.location.pathname,
- method: "GET",
- data: data,
- success: function (html) {
+ data.set("list", "1");
+
+ fetch(window.location.pathname + "?" + data)
+ .then(response => response.text())
+ .then(function (html) {
displayFirstChangesets(html);
updateMap();
- }
- });
+ });
}
function loadMore(e) {
function getData() {
var bounds = map.getBounds();
- var url = "/api/" + OSM.API_VERSION + "/map?bbox=" + bounds.toBBoxString();
+ var url = "/api/" + OSM.API_VERSION + "/map.json?bbox=" + bounds.toBBoxString();
/*
* Modern browsers are quite happy showing far more than 100 features in
- * the data browser, so increase the limit to 4000 by default.
+ * the data browser, so increase the limit to 4000.
*/
const maxFeatures = 4000;
if (dataLoader) dataLoader.abort();
- dataLoader = $.ajax({
- url: url,
- dataType: "json",
- success: function (data) {
+ dataLoader = new AbortController();
+ fetch(url, { signal: dataLoader.signal })
+ .then(response => {
+ if (response.ok) return response.json();
+ const status = response.statusText || response.status;
+ if (response.status !== 400) throw new Error(status);
+ return response.text().then(text => {
+ throw new Error(text || status);
+ });
+ })
+ .then(function (data) {
dataLayer.clearLayers();
var features = dataLayer.buildFeatures(data);
if (map._objectLayer) {
map._objectLayer.bringToFront();
}
+ })
+ .catch(function (error) {
+ if (error.name === "AbortError") return;
- dataLoader = null;
- },
- error: function (XMLHttpRequest, textStatus) {
- dataLoader = null;
- if (textStatus === "abort") return;
-
- function closeError() {
+ displayLoadError(error?.message, () => {
$("#browse_status").empty();
- }
-
- if (XMLHttpRequest.status === 400 && XMLHttpRequest.responseText) {
- displayLoadError(XMLHttpRequest.responseText, closeError);
- } else if (XMLHttpRequest.statusText) {
- displayLoadError(XMLHttpRequest.statusText, closeError);
- } else {
- displayLoadError(String(XMLHttpRequest.status), closeError);
- }
- }
- });
+ });
+ })
+ .finally(() => dataLoader = null);
}
function onSelect(layer) {
if (noteLoader) noteLoader.abort();
- noteLoader = $.ajax({
- url: url,
- success: success
- });
+ noteLoader = new AbortController();
+ fetch(url, { signal: noteLoader.signal })
+ .then(response => response.json())
+ .then(success)
+ .catch(() => {})
+ .finally(() => noteLoader = null);
}
function success(json) {
for (var id in oldNotes) {
noteLayer.removeLayer(oldNotes[id]);
}
-
- noteLoader = null;
}
}
};
$section.data("ajax").abort();
}
- $section.data("ajax", $.ajax({
- url: url,
+ $section.data("ajax", new AbortController());
+ fetch(url, {
method: "POST",
- data: {
+ body: new URLSearchParams({
data: "[timeout:10][out:json];" + query
- },
- xhrFields: {
- withCredentials: credentials
- },
- success: function (results) {
+ }),
+ credentials: credentials ? "include" : "same-origin",
+ signal: $section.data("ajax").signal
+ })
+ .then(response => response.json())
+ .then(function (results) {
var elements;
$section.find(".loader").hide();
.text(I18n.t("javascripts.query.nothing_found"))
.appendTo($ul);
}
- },
- error: function (xhr, status, error) {
+ })
+ .catch(function (error) {
+ if (error.name === "AbortError") return;
+
$section.find(".loader").hide();
$("<li>")
.addClass("list-group-item")
- .text(I18n.t("javascripts.query." + status, { server: url, error: error }))
+ .text(I18n.t("javascripts.query.error", { server: url, error: error.message }))
.appendTo($ul);
- }
- }));
+ });
}
function compareSize(feature1, feature2) {
var div = $(this).parents(".search_more"),
csrf_param = $("meta[name=csrf-param]").attr("content"),
csrf_token = $("meta[name=csrf-token]").attr("content"),
- params = {};
+ params = new URLSearchParams();
$(this).hide();
div.find(".loader").show();
- params[csrf_param] = csrf_token;
+ params.set(csrf_param, csrf_token);
- $.ajax({
- url: $(this).attr("href"),
+ fetch($(this).attr("href"), {
method: "POST",
- data: params,
- success: function (data) {
- div.replaceWith(data);
- }
- });
+ body: params
+ })
+ .then(response => response.text())
+ .then(data => div.replaceWith(data));
}
function showSearchResult() {
var entry = $(this),
csrf_param = $("meta[name=csrf-param]").attr("content"),
csrf_token = $("meta[name=csrf-token]").attr("content"),
- params = {
+ params = new URLSearchParams({
zoom: map.getZoom(),
minlon: map.getBounds().getWest(),
minlat: map.getBounds().getSouth(),
maxlon: map.getBounds().getEast(),
maxlat: map.getBounds().getNorth()
- };
- params[csrf_param] = csrf_token;
- $.ajax({
- url: entry.data("href"),
+ });
+ params.set(csrf_param, csrf_token);
+ fetch(entry.data("href"), {
method: "POST",
- data: params,
- success: function (html) {
+ body: params
+ })
+ .then(response => response.text())
+ .then(function (html) {
entry.html(html);
// go to first result of first geocoder
if (index === 0) {
panToSearchResult(firstResult.data());
}
}
- }
- });
+ });
});
return map.getState();
this.removeObject();
if (object.type === "note" || object.type === "changeset") {
- this._objectLoader = {
- abort: function () {}
- };
+ this._objectLoader = { abort: () => {} };
this._object = object;
this._objectLayer = L.featureGroup().addTo(this);
this.fire("overlayadd", { layer: this._objectLayer });
} else { // element handled by L.OSM.DataLayer
var map = this;
- this._objectLoader = $.ajax({
- url: OSM.apiUrl(object),
- dataType: "json",
- success: function (data) {
+ this._objectLoader = new AbortController();
+ fetch(OSM.apiUrl(object), {
+ headers: { accept: "application/json" },
+ signal: this._objectLoader.signal
+ })
+ .then(response => response.json())
+ .then(function (data) {
map._object = object;
map._objectLayer = new L.OSM.DataLayer(null, {
if (callback) callback(map._objectLayer.getBounds());
map.fire("overlayadd", { layer: map._objectLayer });
- }
- });
+ })
+ .catch(() => {});
}
},