0
0
mirror of https://github.com/jellyfin/jellyfin-web.git synced 2025-05-19 00:37:07 +00:00
Files

52 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

2020-08-14 08:46:34 +02:00
import browser from '../scripts/browser';
2018-10-23 01:05:09 +03:00
function fallback(urls) {
2020-10-07 21:12:14 +09:00
let i = 0;
(function createIframe() {
2020-10-07 21:12:14 +09:00
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
2020-10-08 00:47:23 +09:00
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) {
2020-10-07 21:12:14 +09:00
const a = document.createElement('a');
a.download = '';
a.href = url;
a.click();
}
export default function (urls) {
if (!urls) {
throw new Error('`urls` required');
2018-10-23 01:05:09 +03:00
}
if (typeof document.createElement('a').download === 'undefined' || browser.iOS) {
return fallback(urls);
2018-10-23 01:05:09 +03:00
}
2020-10-07 21:12:14 +09:00
let delay = 0;
urls.forEach(function (url) {
setTimeout(download.bind(null, url), 100 * ++delay);
});
}