Skip to content

Commit

Permalink
Generate iOS popup at top
Browse files Browse the repository at this point in the history
  • Loading branch information
exupero committed May 9, 2019
1 parent ba5c562 commit f0df944
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/saveSvgAsPng.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@
return inlineFonts(fontList).then(fontCss => css.join('\n') + fontCss);
};

const downloadOptions = () => {
if (!navigator.msSaveOrOpenBlob && !('download' in document.createElement('a'))) {
return {popup: window.open()};
}
};

out$.prepareSvg = (el, options, done) => {
requireDomNode(el);
const {
Expand Down Expand Up @@ -347,7 +353,7 @@
});
};

out$.download = (name, uri) => {
out$.download = (name, uri, options) => {
if (navigator.msSaveOrOpenBlob) navigator.msSaveOrOpenBlob(uriToBlob(uri), name);
else {
const saveLink = document.createElement('a');
Expand All @@ -367,23 +373,24 @@
}
saveLink.click();
document.body.removeChild(saveLink);
} else {
const popup = window.open();
popup.document.title = name;
popup.location.replace(uri);
} else if (options && options.popup) {
options.popup.document.title = name;
options.popup.location.replace(uri);
}
}
};

out$.saveSvg = (el, name, options) => {
const downloadOpts = downloadOptions(); // don't inline, can't be async
return requireDomNodePromise(el)
.then(el => out$.svgAsDataUri(el, options || {}))
.then(uri => out$.download(name, uri));
.then(uri => out$.download(name, uri, downloadOpts));
};

out$.saveSvgAsPng = (el, name, options) => {
const downloadOpts = downloadOptions(); // don't inline, can't be async
return requireDomNodePromise(el)
.then(el => out$.svgAsPngUri(el, options || {}))
.then(uri => out$.download(name, uri));
.then(uri => out$.download(name, uri, downloadOpts));
};
})();

0 comments on commit f0df944

Please sign in to comment.