Skip to content
This repository has been archived by the owner on Jun 17, 2021. It is now read-only.

Commit

Permalink
Improved downloads in Safari
Browse files Browse the repository at this point in the history
  • Loading branch information
zhukov committed Dec 8, 2017
1 parent 15fdefc commit 9042dab
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions app/js/lib/ng_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ angular.module('izhukov.utils', [])
.service('FileManager', function ($window, $q, $timeout, qSync) {
$window.URL = $window.URL || $window.webkitURL
$window.BlobBuilder = $window.BlobBuilder || $window.WebKitBlobBuilder || $window.MozBlobBuilder
var buggyUnknownBlob = navigator.userAgent.indexOf('Safari') != -1 &&
navigator.userAgent.indexOf('Chrome') == -1
var isSafari = 'safari' in window
var safariVersion = parseFloat(isSafari && (navigator.userAgent.match(/Version\/(\d+\.\d+).* Safari/) || [])[1])
var safariWithDownload = isSafari && safariVersion >= 11.0
var buggyUnknownBlob = isSafari && !safariWithDownload

var blobSupported = true

Expand Down Expand Up @@ -284,7 +286,7 @@ angular.module('izhukov.utils', [])
}

var popup = false
if (window.safari) {
if (isSafari && !safariWithDownload) {
popup = window.open()
}

Expand All @@ -297,7 +299,9 @@ angular.module('izhukov.utils', [])
}
var anchor = document.createElementNS('http://www.w3.org/1999/xhtml', 'a')
anchor.href = url
anchor.target = '_blank'
if (!safariWithDownload) {
anchor.target = '_blank'
}
anchor.download = fileName
if (anchor.dataset) {
anchor.dataset.downloadurl = ['video/quicktime', fileName, url].join(':')
Expand Down

0 comments on commit 9042dab

Please sign in to comment.