Use file blobs instead of data uri for saving

(This seems to be an easier path to IE11/Edge support)
This commit is contained in:
Bryan Housel
2017-09-16 22:39:52 -04:00
parent 2edc37b74e
commit 202354508e
2 changed files with 24 additions and 30 deletions
+12 -15
View File
@@ -100,7 +100,8 @@ export function uiCommitChanges(context) {
delete changeset.id; // Export without chnageset_id
var data = JXON.stringify(changeset.osmChangeJXON(changes)),
uri = 'data:text/xml;charset=utf-8,' + encodeURIComponent(data);
blob = new Blob([data], {type: 'text/xml;charset=utf-8;'}),
fileName = 'changes.osc';
var linkEnter = container.selectAll('.download-changes')
.data([0])
@@ -108,28 +109,24 @@ export function uiCommitChanges(context) {
.append('a')
.attr('class', 'download-changes');
if (detected.download) { // all except IE11 and Edge
linkEnter // download the data uri as a file
.attr('href', uri)
.attr('download', 'changes.osc')
.call(svgIcon('#icon-load', 'inline'))
.append('span')
.text(t('commit.download_changes'));
if (detected.download) { // All except IE11 and Edge
linkEnter // download the data as a file
.attr('href', window.URL.createObjectURL(blob))
.attr('download', fileName);
} else { // IE11 and Edge
linkEnter // open data uri in a new tab
.attr('target', '_blank')
.call(svgIcon('#icon-load', 'inline'))
.append('span')
.text(t('commit.download_changes'));
linkEnter
.on('click.download', function() {
var win = window.open(uri, '_blank');
win.focus();
navigator.msSaveBlob(blob, fileName);
});
}
linkEnter
.call(svgIcon('#icon-load', 'inline'))
.append('span')
.text(t('commit.download_changes'));
function mouseover(d) {
if (d.entity) {
+12 -15
View File
@@ -47,7 +47,8 @@ export function uiConflicts(context) {
delete changeset.id; // Export without chnageset_id
var data = JXON.stringify(changeset.osmChangeJXON(origChanges)),
uri = 'data:text/xml;charset=utf-8,' + encodeURIComponent(data);
blob = new Blob([data], {type: 'text/xml;charset=utf-8;'}),
fileName = 'changes.osc';
var linkEnter = conflictsHelp.selectAll('.download-changes')
.data([0])
@@ -55,28 +56,24 @@ export function uiConflicts(context) {
.append('a')
.attr('class', 'download-changes');
if (detected.download) { // all except IE11 and Edge
linkEnter // download the data uri as a file
.attr('href', uri)
.attr('download', 'changes.osc')
.call(svgIcon('#icon-load', 'inline'))
.append('span')
.text(t('save.conflict.download_changes'));
if (detected.download) { // All except IE11 and Edge
linkEnter // download the data as a file
.attr('href', window.URL.createObjectURL(blob))
.attr('download', fileName);
} else { // IE11 and Edge
linkEnter // open data uri in a new tab
.attr('target', '_blank')
.call(svgIcon('#icon-load', 'inline'))
.append('span')
.text(t('save.conflict.download_changes'));
linkEnter
.on('click.download', function() {
var win = window.open(uri, '_blank');
win.focus();
navigator.msSaveBlob(blob, fileName);
});
}
linkEnter
.call(svgIcon('#icon-load', 'inline'))
.append('span')
.text(t('save.conflict.download_changes'));
body
.append('div')