Ghost/ghost/admin/app/services/utils.js
Kevin Ansfield fe48f7ed80 Added utils service with downloadFile() method
no issue

- pattern of downloading a file by creating an iframe and setting the `src` attribute was repeated throughout the codebase and was using a mix of native and jQuery patterns
- added a `utils` service for housing one-off utility methods like this to avoid repetition and mixed patterns becoming more widespread (we want to get rid of jQuery usage)
2021-10-05 14:21:19 +01:00

17 lines
445 B
JavaScript

import Service from '@ember/service';
export default class UtilsService extends Service {
downloadFile(url) {
let iframe = document.getElementById('iframeDownload');
if (!iframe) {
iframe = document.createElement('iframe');
iframe.id = 'iframeDownload';
iframe.style.display = 'none';
document.body.append(iframe);
}
iframe.setAttribute('src', url);
}
}