Skip to content

Commit

Permalink
chore: remove file-saver polyfill
Browse files Browse the repository at this point in the history
Simply use a.download and a.href
  • Loading branch information
simon04 authored and erictheise committed Dec 31, 2023
1 parent 9702c87 commit 9b5d5d2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 37 deletions.
54 changes: 24 additions & 30 deletions js/ide.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import "mapbox-gl-leaflet";
import "codemirror/lib/codemirror";
import tokml from "tokml";
import togpx from "togpx";
import {saveAs} from "file-saver";
import configs from "./configs";
import Query from "./query";
import Nominatim from "./nominatim";
Expand Down Expand Up @@ -1639,14 +1638,22 @@ var ide = new (function () {
.replace(/!/g, "%21")
.replace(/\(/g, "%28")
.replace(/\)/g, "%29");
function toDataURL(text) {
function toDataURL(text, mediatype) {
return (
"data:text/plain;charset=" +
"data:" +
(mediatype || "text/plain") +
";charset=" +
(document.characterSet || document.charset) +
";base64," +
Base64.encode(text, true)
);
}
function saveAs(text, mediatype, filename) {
var save_link = document.createElement("a");
save_link.href = toDataURL(text, mediatype);
save_link.download = filename;
save_link.dispatchEvent(new MouseEvent("click"));
}
function copyHandler(text, successMessage) {
return function () {
// selector
Expand Down Expand Up @@ -1873,10 +1880,7 @@ var ide = new (function () {

// make content downloadable as file
if (overpass.geojson) {
var blob = new Blob([geoJSON_str], {
type: "application/json;charset=utf-8"
});
saveAs(blob, "export.geojson");
saveAs(geoJSON_str, "application/geo+json", "export.geojson");
} else {
d.addClass("is-active");
$(".message", d).text(geoJSON_str);
Expand Down Expand Up @@ -1999,10 +2003,7 @@ var ide = new (function () {
var gpx_str = constructGpxString(geojson);
// make content downloadable as file
if (geojson) {
var blob = new Blob([gpx_str], {
type: "application/xml;charset=utf-8"
});
saveAs(blob, "export.gpx");
saveAs(gpx_str, "application/gpx+xml", "export.gpx");
} else {
var d = $("#export-download-dialog");
d.addClass("is-active");
Expand Down Expand Up @@ -2061,10 +2062,11 @@ var ide = new (function () {
var kml_str = constructKmlString(geojson);
// make content downloadable as file
if (geojson) {
var blob = new Blob([kml_str], {
type: "application/xml;charset=utf-8"
});
saveAs(blob, "export.kml");
saveAs(
kml_str,
"application/vnd.google-earth.kml+xml",
"export.kml"
);
} else {
$("#export-download-dialog").addClass("is-active");
$("#export-download-dialog .message").text(kml_str);
Expand Down Expand Up @@ -2132,20 +2134,11 @@ var ide = new (function () {
// make content downloadable as file
if (geojson) {
if (raw_type == "osm" || raw_type == "xml") {
var blob = new Blob([raw_str], {
type: "application/xml;charset=utf-8"
});
saveAs(blob, "export." + raw_type);
saveAs(raw_str, "application/xml", "export." + raw_type);
} else if (raw_type == "json") {
var blob = new Blob([raw_str], {
type: "application/json;charset=utf-8"
});
saveAs(blob, "export.json");
saveAs(raw_str, "application/json", "export.json");
} else {
var blob = new Blob([raw_str], {
type: "application/octet-stream;charset=utf-8"
});
saveAs(blob, "export.dat");
saveAs(raw_str, "application/octet-stream", "export.dat");
}
} else {
var d = $("#export-download-dialog");
Expand Down Expand Up @@ -2431,9 +2424,10 @@ var ide = new (function () {
"</a>--></p>" +
attrib_message;
showDialog(i18n.t("export.image.title"), content, dialog_buttons);
canvas.toBlob(function (blob) {
saveAs(blob, "export.png");
});
var save_link = document.createElement("a");
save_link.href = imgstr;
save_link.download = "export.png";
save_link.dispatchEvent(new MouseEvent("click"));
};
this.onFfsClick = function () {
$("#ffs-dialog #ffs-dialog-parse-error").hide();
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"bulma": "^0.8.1",
"canvg": "4.0.1",
"codemirror": "https://github.com/codemirror/CodeMirror/archive/v2.38.tar.gz",
"file-saver": "^1.3.3",
"html2canvas": "^1.4.1",
"jquery": "3.6.1",
"jquery-ui": "1.13.2",
Expand Down
7 changes: 1 addition & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1140,11 +1140,6 @@ figures@^3.2.0:
dependencies:
escape-string-regexp "^1.0.5"

file-saver@^1.3.3:
version "1.3.8"
resolved "https://registry.yarnpkg.com/file-saver/-/file-saver-1.3.8.tgz#e68a30c7cb044e2fb362b428469feb291c2e09d8"
integrity sha512-spKHSBQIxxS81N/O21WmuXA2F6wppUCsutpzenOeZzOCCJ5gEfcbqJP983IrpLXzYmXnMUa6J03SubcNPdKrlg==

filename-reserved-regex@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/filename-reserved-regex/-/filename-reserved-regex-2.0.0.tgz#abf73dfab735d045440abfea2d91f389ebbfa229"
Expand Down Expand Up @@ -2529,7 +2524,7 @@ sshpk@^1.7.0:
stackblur-canvas@^2.0.0:
version "2.5.0"
resolved "https://registry.yarnpkg.com/stackblur-canvas/-/stackblur-canvas-2.5.0.tgz#aa87bbed1560fdcd3138fff344fc6a1c413ebac4"
integrity "sha1-qoe77RVg/c0xOP/zRPxqHEE+usQ= sha512-EeNzTVfj+1In7aSLPKDD03F/ly4RxEuF/EX0YcOG0cKoPXs+SLZxDawQbexQDBzwROs4VKLWTOaZQlZkGBFEIQ=="
integrity sha512-EeNzTVfj+1In7aSLPKDD03F/ly4RxEuF/EX0YcOG0cKoPXs+SLZxDawQbexQDBzwROs4VKLWTOaZQlZkGBFEIQ==

stackblur@^1.0.0:
version "1.0.0"
Expand Down

0 comments on commit 9b5d5d2

Please sign in to comment.