Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Commit

Permalink
Adding callback capabilities to loadJS
Browse files Browse the repository at this point in the history
  • Loading branch information
tkadlec committed Sep 22, 2014
1 parent 71f84c5 commit 17824a7
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion loadJS.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
/*! loadJS: load a JS file asynchronously. [c]2014 @scottjehl, Filament Group, Inc. (Based on http://goo.gl/REQGQ by Paul Irish). Licensed MIT */
function loadJS( src ){
function loadJS( src, cb ){
"use strict";
var ref = window.document.getElementsByTagName( "script" )[ 0 ];
var script = window.document.createElement( "script" );
script.src = src;
ref.parentNode.insertBefore( script, ref );
if (cb) {
script.onload = function(){
try {
cb();
}
catch (e) {}
};
}
return script;
}

0 comments on commit 17824a7

Please sign in to comment.