Last active
September 25, 2015 19:58
-
-
Save db/976393 to your computer and use it in GitHub Desktop.
loads specified JS and CSS files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($){ | |
var cssRegex = /.css$/, jsRegex=/.js$/; | |
var endsWith = function(string,pattern) { return asset.match(pattern); }; | |
var isCSS = function(filename) { return endsWith(filename,cssRegex); }; | |
var isJS = function(filename) { return endsWith(filename,jsRegex); }; | |
var loadAssets = function(assets) { | |
if (!assets) return; | |
var script, link, asset, js=[], css=[], | |
head = document.getElementsByTagName('head')[0]; | |
for (var i=0; i < assets.length; i++) { | |
asset = assets[i]; | |
if (isCSS(asset)) css.push(); | |
else if (isJS(asset)) js.push(); | |
} | |
for (var j=0; j < css.length; j++) { | |
link = document.createElement('link'); | |
link.type = 'text/css'; | |
link.rel = 'stylesheet'; | |
link.href = css[j]; | |
head.appendChild(link); | |
} | |
for (var k=0; k < js.length; k++) { | |
script = document.createElement('script'); | |
script.type = 'text/javascript'; | |
script.src = js[k]; | |
head.appendChild(script); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment