diff options
| author | Shishkevich D. <135337715+shishkevichd@users.noreply.github.com> | 2025-04-08 18:17:29 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-08 18:17:29 +0300 |
| commit | 8ef447a997aa3ad0e2f333b1b71c2cbc91a40395 (patch) | |
| tree | dd95a15bdc3f988d240b25c422b0c03caf8bc3c3 /web/assets | |
| parent | 520f7a2d15faae41b2ae33d09fb4af8a499aebef (diff) | |
chore: create `FileManager` class for downloading files
Diffstat (limited to 'web/assets')
| -rw-r--r-- | web/assets/js/util/index.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/web/assets/js/util/index.js b/web/assets/js/util/index.js index 93416abe..dedf5c64 100644 --- a/web/assets/js/util/index.js +++ b/web/assets/js/util/index.js @@ -799,4 +799,24 @@ const MediaQueryMixin = { beforeDestroy() { window.removeEventListener('resize', this.updateDeviceType); }, +} + +class FileManager { + static downloadTextFile(content, filename='file.txt', options = { type: "text/plain" }) { + let link = window.document.createElement('a'); + + link.download = filename; + link.style.border = '0'; + link.style.padding = '0'; + link.style.margin = '0'; + link.style.position = 'absolute'; + link.style.left = '-9999px'; + link.style.top = `${window.pageYOffset || window.document.documentElement.scrollTop}px`; + link.href = URL.createObjectURL(new Blob([content], options)); + link.click(); + + URL.revokeObjectURL(link.href); + + link.remove(); + } }
\ No newline at end of file |
