1 OSM.downloadBlob = function (blob, filename) {
2 const url = URL.createObjectURL(blob);
3 const a = document.createElement("a");
6 document.body.appendChild(a);
8 document.body.removeChild(a);
9 URL.revokeObjectURL(url);
12 OSM.showAlert = function (message) {
13 const modalBody = document.getElementById("osm_alert_message");
14 modalBody.textContent = message;
15 const alertModal = new bootstrap.Modal(document.getElementById("osm_alert_modal"));
19 OSM.getTurboBlobHandler = function (filename) {
20 function handleExportSuccess({ fetchResponse }) {
21 fetchResponse.response.blob()
22 .then(blob => OSM.downloadBlob(blob, filename))
23 .catch(() => notifyExportFailure("(blob error)"));
26 function handleExportError({ error, fetchResponse }) {
29 fetchResponse.responseText.then(extractTextFromHTML)
31 .then(notifyExportFailure)
32 .catch(() => notifyExportFailure("(unknown)"));
35 function extractTextFromHTML(htmlString) {
36 const parser = new DOMParser();
37 const doc = parser.parseFromString(htmlString, "text/html");
38 return doc.body ? doc.body.textContent.trim() : "(unknown)";
41 function notifyExportFailure(reason) {
42 OSM.showAlert(OSM.i18n.t("javascripts.share.export_failed", { reason }));
45 return function ({ detail }) {
47 handleExportSuccess(detail);
49 handleExportError(detail);