@@ -6,15 +6,27 @@ define(["exports"], function (_exports) {
66 } ) ;
77 _exports . default = void 0 ;
88
9+ function ownKeys ( object , enumerableOnly ) { var keys = Object . keys ( object ) ; if ( Object . getOwnPropertySymbols ) { var symbols = Object . getOwnPropertySymbols ( object ) ; if ( enumerableOnly ) { symbols = symbols . filter ( function ( sym ) { return Object . getOwnPropertyDescriptor ( object , sym ) . enumerable ; } ) ; } keys . push . apply ( keys , symbols ) ; } return keys ; }
10+
11+ function _objectSpread ( target ) { for ( var i = 1 ; i < arguments . length ; i ++ ) { var source = arguments [ i ] != null ? arguments [ i ] : { } ; if ( i % 2 ) { ownKeys ( Object ( source ) , true ) . forEach ( function ( key ) { _defineProperty ( target , key , source [ key ] ) ; } ) ; } else if ( Object . getOwnPropertyDescriptors ) { Object . defineProperties ( target , Object . getOwnPropertyDescriptors ( source ) ) ; } else { ownKeys ( Object ( source ) ) . forEach ( function ( key ) { Object . defineProperty ( target , key , Object . getOwnPropertyDescriptor ( source , key ) ) ; } ) ; } } return target ; }
12+
13+ function _defineProperty ( obj , key , value ) { if ( key in obj ) { Object . defineProperty ( obj , key , { value : value , enumerable : true , configurable : true , writable : true } ) ; } else { obj [ key ] = value ; } return obj ; }
14+
15+ var BODY = 'body' ;
16+ var HEAD = 'head' ;
17+
918 var _load = function _load ( tag ) {
1019 // attributes example: { 'data-test': 'new-attribute-here' }
1120 return function ( url ) {
1221 var attributes = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : { } ;
13- // This promise will be used by Promise.all to determine success or failure
22+ // this promise will be used by Promise.all to determine success or failure
1423 return new Promise ( function ( resolve , reject ) {
24+ // need to set different attributes depending on tag type
25+ var _tagToTagDetailsFuncs = tagToTagDetailsFuncs [ tag ] ( url , attributes ) ,
26+ parent = _tagToTagDetailsFuncs . parent ,
27+ tagAttributes = _tagToTagDetailsFuncs . attributes ;
28+
1529 var element = document . createElement ( tag ) ;
16- var parent = 'body' ;
17- var attr = 'src' ; // Important success and error for the promise
1830
1931 element . onload = function ( ) {
2032 return resolve ( url ) ;
@@ -23,31 +35,54 @@ define(["exports"], function (_exports) {
2335 element . onerror = function ( ) {
2436 return reject ( url ) ;
2537 } ; // maybe we should remove the broken node, who knows
26- // Need to set different attributes depending on tag type
2738
2839
29- switch ( tag ) {
30- case 'script' :
31- element . async = true ;
32- break ;
33-
34- case 'link' :
35- element . type = 'text/css' ;
36- element . rel = 'stylesheet' ;
37- attr = 'href' ;
38- parent = 'head' ;
39- }
40-
41- element [ attr ] = url ;
42- Object . keys ( attributes ) . forEach ( function ( name ) {
43- return element . setAttribute ( name , attributes [ name ] ) ;
44- } ) ; // Inject into document to kick off loading
40+ Object . keys ( tagAttributes ) . forEach ( function ( name ) {
41+ return element . setAttribute ( name , tagAttributes [ name ] ) ;
42+ } ) ; // inject into document to kick off loading
4543
4644 document [ parent ] . appendChild ( element ) ;
4745 } ) ;
4846 } ;
49- } ; // exporting a "default" would render the amd package to work differently
47+ } ;
5048
49+ var getScriptTagDetails = function getScriptTagDetails ( url , attributes ) {
50+ var hasNoAsyncOrDefer = ! ( 'async' in attributes || 'defer' in attributes ) ;
51+ return {
52+ parent : BODY ,
53+ attributes : _objectSpread ( _objectSpread ( {
54+ src : url
55+ } , hasNoAsyncOrDefer && {
56+ async : ''
57+ } ) , attributes )
58+ } ;
59+ } ;
60+
61+ var getLinkTagDetails = function getLinkTagDetails ( url , attributes ) {
62+ return {
63+ parent : HEAD ,
64+ attributes : _objectSpread ( {
65+ href : url ,
66+ type : 'text/css' ,
67+ rel : 'stylesheet'
68+ } , attributes )
69+ } ;
70+ } ;
71+
72+ var getImgTagDetails = function getImgTagDetails ( url , attributes ) {
73+ return {
74+ parent : BODY ,
75+ attributes : _objectSpread ( {
76+ src : url
77+ } , attributes )
78+ } ;
79+ } ;
80+
81+ var tagToTagDetailsFuncs = {
82+ script : getScriptTagDetails ,
83+ link : getLinkTagDetails ,
84+ img : getImgTagDetails
85+ } ; // exporting a "default" would render the amd package to work differently
5186
5287 var _default = {
5388 css : _load ( 'link' ) ,
0 commit comments