Skip to content

Commit bd040e6

Browse files
committed
add Lib.isSafari
1 parent ac5fe79 commit bd040e6

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/lib/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,11 @@ lib.isIE = function() {
733733
return typeof window.navigator.msSaveBlob !== 'undefined';
734734
};
735735

736+
var IS_SAFARI_REGEX = /Version\/[\d\.]+.*Safari/;
737+
lib.isSafari = function() {
738+
return IS_SAFARI_REGEX.test(window.navigator.userAgent);
739+
};
740+
736741
/**
737742
* Duck typing to recognize a d3 selection, mostly for IE9's benefit
738743
* because it doesn't handle instanceof like modern browsers

src/snapshot/filesaver.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,17 @@
2424
var fileSaver = function(url, name) {
2525
var saveLink = document.createElement('a');
2626
var canUseSaveLink = 'download' in saveLink;
27-
var isSafari = /Version\/[\d\.]+.*Safari/.test(navigator.userAgent);
2827
var promise = new Promise(function(resolve, reject) {
2928
// IE <10 is explicitly unsupported
3029
if(typeof navigator !== 'undefined' && /MSIE [1-9]\./.test(navigator.userAgent)) {
3130
reject(new Error('IE < 10 unsupported'));
3231
}
3332

3433
// First try a.download, then web filesystem, then object URLs
35-
if(isSafari) {
3634
// Safari doesn't allow downloading of blob urls
3735
document.location.href = 'data:application/octet-stream' + url.slice(url.search(/[,;]/));
3836
resolve(name);
37+
if(Lib.isSafari()) {
3938
}
4039

4140
if(!name) {

0 commit comments

Comments
 (0)