mirror of
https://github.com/jellyfin/jellyfin-web.git
synced 2025-05-13 03:32:57 +00:00
Fix "Download All" for Safari
Original-merge: 4071c44437
Merged-by: thornbill <thornbill@users.noreply.github.com>
Backported-by: thornbill <thornbill@users.noreply.github.com>
52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
import browser from '../scripts/browser';
|
|
|
|
function fallback(urls) {
|
|
let i = 0;
|
|
|
|
(function createIframe() {
|
|
const frame = document.createElement('iframe');
|
|
frame.style.display = 'none';
|
|
frame.src = urls[i++];
|
|
document.documentElement.appendChild(frame);
|
|
|
|
// the download init has to be sequential otherwise IE only use the first
|
|
const interval = setInterval(function () {
|
|
if (frame.contentWindow.document.readyState === 'complete' || frame.contentWindow.document.readyState === 'interactive') {
|
|
clearInterval(interval);
|
|
|
|
// Safari needs a timeout
|
|
setTimeout(function () {
|
|
frame.parentNode.removeChild(frame);
|
|
}, 1000);
|
|
|
|
if (i < urls.length) {
|
|
createIframe();
|
|
}
|
|
}
|
|
}, 100);
|
|
})();
|
|
}
|
|
|
|
function download(url) {
|
|
const a = document.createElement('a');
|
|
a.download = '';
|
|
a.href = url;
|
|
a.click();
|
|
}
|
|
|
|
export default function (urls) {
|
|
if (!urls) {
|
|
throw new Error('`urls` required');
|
|
}
|
|
|
|
if (typeof document.createElement('a').download === 'undefined' || browser.iOS) {
|
|
return fallback(urls);
|
|
}
|
|
|
|
let delay = 0;
|
|
|
|
urls.forEach(function (url) {
|
|
setTimeout(download.bind(null, url), 100 * ++delay);
|
|
});
|
|
}
|