File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ ( function ( ) {
4
+
5
+ if ( ! window . fetch ) {
6
+ return ;
7
+ }
8
+
9
+ const $ = require ( 'jquery' ) ;
10
+
11
+ const download = ( url , name , errorCallback ) => {
12
+ fetch ( url )
13
+ . then ( response => response . blob ( ) )
14
+ . then ( blob => {
15
+ const a = document . createElement ( 'a' ) ;
16
+ a . href = URL . createObjectURL ( blob ) ;
17
+ a . style = 'display: none' ;
18
+ a . download = ( name && 0 < name . length ) ? name : '' ;
19
+
20
+ document . body . appendChild ( a ) ;
21
+ a . click ( ) ;
22
+ } )
23
+ . catch ( errorCallback ) ;
24
+ } ;
25
+
26
+ $ ( document ) . on ( 'click' , 'a[data-file-manager-download]' , function ( e ) {
27
+ const self = $ ( this ) ;
28
+ const url = self . attr ( 'href' ) ;
29
+
30
+ if ( url && ! self . data ( 'file-manager-download-failed' ) ) {
31
+ e . preventDefault ( ) ;
32
+ download ( url , self . data ( 'file-manager-download' ) , function ( ) {
33
+ self . data ( 'file-manager-download-failed' , true ) ;
34
+
35
+ const a = document . createElement ( 'a' ) ;
36
+ a . href = url ;
37
+ a . target = '_blank' ;
38
+ a . style = 'display: none' ;
39
+
40
+ document . body . appendChild ( a ) ;
41
+ a . click ( ) ;
42
+ } ) ;
43
+ }
44
+ } ) ;
45
+
46
+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments