File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -106,22 +106,7 @@ Cash can parse `<script>` tags and execute their code when they are attached to
106106
107107However we do not support script tags inside iframes or script tags with a ` src ` attribute.
108108
109- If you need to load arbitrary JavaScript files you could use something like this:
110-
111- ``` javascript
112- function loadScript ( url ) {
113- return new Promise ( ( resolve , reject ) => {
114- const script = document .createElement ( ' script' );
115- const head = document .getElementsByTagName ( ' head' )[0 ];
116- const anchor = document .getElementsByTagName ( ' script' )[0 ];
117- script .async = true ;
118- script .onload = resolve;
119- script .onerror = reject;
120- script .src = url;
121- head .insertBefore ( script, anchor );
122- });
123- }
124- ```
109+ If you need to load arbitrary JavaScript files you can find a reference implementation for ` $.getScript ` [ here] ( https://github.com/kenwheeler/cash/blob/master/src/extra/get_script.ts ) .
125110
126111### No CSS auto-suffixing support for ` zoom `
127112
Original file line number Diff line number Diff line change 22 "browsers" : [" ie >= 10" ],
33 "components" : {
44 "core/export_esm" : false ,
5+ "extra/get_script" : false ,
56 "extra/shorthands" : false
67 },
78 "paths" : {
Original file line number Diff line number Diff line change 1+
2+ // @require core/cash.ts
3+ // @require core/variables.ts
4+
5+ function getScript ( url : string , success ?: Function ) : void {
6+
7+ const script = doc . createElement ( 'script' ) ,
8+ $anchor = cash ( 'script' ) ;
9+
10+ script . async = true ;
11+ script . src = url ;
12+
13+ if ( success ) script . onload = ( ) => success ( ) ;
14+
15+ $anchor . before ( script ) ;
16+
17+ }
18+
19+ interface CashStatic {
20+ getScript ( url : string , success ?: Function ) : void ;
21+ }
22+
23+ cash . getScript = getScript ;
You can’t perform that action at this time.
0 commit comments