forked from filamentgroup/loadJS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloadJS.js
More file actions
31 lines (28 loc) · 785 Bytes
/
loadJS.js
File metadata and controls
31 lines (28 loc) · 785 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*! loadJS: load a JS file asynchronously. [c]2014 @scottjehl, Filament Group, Inc. (Based on http://goo.gl/REQGQ by Paul Irish). Licensed MIT */
(function( w ){
var loadJS = function( src, cb, ordered ){
"use strict";
var tmp;
var ref = w.document.getElementsByTagName( "script" )[ 0 ];
var script = w.document.createElement( "script" );
if (typeof(cb) === 'boolean') {
tmp = ordered;
ordered = cb;
cb = tmp;
}
script.src = src;
script.async = !ordered;
ref.parentNode.insertBefore( script, ref );
if (cb && typeof(cb) === "function") {
script.onload = cb;
}
return script;
};
// commonjs
if( typeof module !== "undefined" ){
module.exports = loadJS;
}
else {
w.loadJS = loadJS;
}
}( typeof global !== "undefined" ? global : this ));