File tree 2 files changed +53
-0
lines changed
packages/angular_devkit/build_angular/src/angular-cli-files/models
2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * Safari 10.1 supports modules, but does not support the `nomodule` attribute - it will
3
+ * load <script nomodule> anyway. This snippet solve this problem, but only for script
4
+ * tags that load external code, e.g.: <script nomodule src="nomodule.js"></script>
5
+ *
6
+ * Again: this will **not** prevent inline script, e.g.:
7
+ * <script nomodule>alert('no modules');</script>.
8
+ *
9
+ * This workaround is possible because Safari supports the non-standard 'beforeload' event.
10
+ * This allows us to trap the module and nomodule load.
11
+ *
12
+ * Note also that `nomodule` is supported in later versions of Safari - it's just 10.1 that
13
+ * omits this attribute.
14
+ */
15
+ ( function ( ) {
16
+ var check = document . createElement ( 'script' ) ;
17
+ if ( ! ( 'noModule' in check ) && 'onbeforeload' in check ) {
18
+ var support = false ;
19
+ document . addEventListener ( 'beforeload' , function ( e ) {
20
+ if ( e . target === check ) {
21
+ support = true ;
22
+ } else if ( ! e . target . hasAttribute ( 'nomodule' ) || ! support ) {
23
+ return ;
24
+ }
25
+ e . preventDefault ( ) ;
26
+ } , true ) ;
27
+
28
+ check . type = 'module' ;
29
+ check . src = '.' ;
30
+ document . head . appendChild ( check ) ;
31
+ check . remove ( ) ;
32
+ }
33
+ } ( ) ) ;
Original file line number Diff line number Diff line change
1
+ ( function ( ) {
2
+ var d = document ;
3
+ var c = d . createElement ( 'script' ) ;
4
+ if ( ! ( 'noModule' in c ) && 'onbeforeload' in c ) {
5
+ var s = false ;
6
+ d . addEventListener ( 'beforeload' , function ( e ) {
7
+ if ( e . target === c ) {
8
+ s = true ;
9
+ } else if ( ! e . target . hasAttribute ( 'nomodule' ) || ! s ) {
10
+ return ;
11
+ }
12
+ e . preventDefault ( ) ;
13
+ } , true ) ;
14
+
15
+ c . type = 'module' ;
16
+ c . src = '.' ;
17
+ d . head . appendChild ( c ) ;
18
+ c . remove ( ) ;
19
+ }
20
+ } ( ) ) ;
You can’t perform that action at this time.
0 commit comments