1
+ let callbacks = [ ]
2
+
3
+ function loadedTinymce ( ) {
4
+ // to fixed https://github.com/PanJiaChen/vue-element-admin/issues/2144
5
+ // check is successfully downloaded script
6
+ return window . tinymce
7
+ }
8
+
1
9
const dynamicLoadScript = ( src , callback ) => {
2
10
const existingScript = document . getElementById ( src )
3
11
const cb = callback || function ( ) { }
@@ -7,31 +15,43 @@ const dynamicLoadScript = (src, callback) => {
7
15
script . src = src // src url for the third-party library being loaded.
8
16
script . id = src
9
17
document . body . appendChild ( script )
10
-
18
+ callbacks . push ( cb )
11
19
const onEnd = 'onload' in script ? stdOnEnd : ieOnEnd
12
- onEnd ( script , cb )
20
+ onEnd ( script )
13
21
}
14
22
15
- if ( existingScript && cb ) cb ( null , existingScript )
23
+ if ( existingScript && cb ) {
24
+ if ( loadedTinymce ( ) ) {
25
+ cb ( null , existingScript )
26
+ } else {
27
+ callbacks . push ( cb )
28
+ }
29
+ }
16
30
17
- function stdOnEnd ( script , cb ) {
31
+ function stdOnEnd ( script ) {
18
32
script . onload = function ( ) {
19
33
// this.onload = null here is necessary
20
34
// because even IE9 works not like others
21
35
this . onerror = this . onload = null
22
- cb ( null , script )
36
+ for ( const cb of callbacks ) {
37
+ cb ( null , script )
38
+ }
39
+ callbacks = null
23
40
}
24
41
script . onerror = function ( ) {
25
42
this . onerror = this . onload = null
26
43
cb ( new Error ( 'Failed to load ' + src ) , script )
27
44
}
28
45
}
29
46
30
- function ieOnEnd ( script , cb ) {
47
+ function ieOnEnd ( script ) {
31
48
script . onreadystatechange = function ( ) {
32
49
if ( this . readyState !== 'complete' && this . readyState !== 'loaded' ) return
33
50
this . onreadystatechange = null
34
- cb ( null , script ) // there is no way to catch loading errors in IE8
51
+ for ( const cb of callbacks ) {
52
+ cb ( null , script ) // there is no way to catch loading errors in IE8
53
+ }
54
+ callbacks = null
35
55
}
36
56
}
37
57
}
0 commit comments