JSFiddle - React, Tailwind, and code Playground
by lbstr
JavaScript
var InsertModule = function(ContainerID, HTML, JS, CSSPaths, JSPaths){
// Insert HTML
$("div#" + ContainerID).append($(HTML));
// Insert CSS
//alert(CSSPaths);
if (CSSPaths && CSSPaths.length > 0) {
var headNode = document.getElementsByTagName("head")[0];
var linkNode;
// alert(CSSPaths.length);
for (var i=0; i<CSSPaths.length;i++) {
if(document.createStyleSheet){
document.createStyleSheet(CSSPaths[i]);
}
else {
linkNode = document.createElement("link");
linkNode.type = "text/css";
linkNode.rel = "Stylesheet";
linkNode.href = CSSPaths[i];
headNode.appendChild(linkNode);
// alert(CSSPaths[i]);
}
}
}
// Insert Javascript
if (JSPaths && JSPaths.length > 0) {
var i = 0,
numPaths = JSPaths.length,
serialLoad = function(i){
if (i < numPaths) { // if there are files left to load
$.getScript(
paths[i], // load the script
function(){ // run this callback when the file has finished loading and executing
i++;
serialLoad(i); // load the next file
}
);
}
else { // else, all of the JSPaths have been loaded and executed
if (JS && JS.length) { // if there is any JS to eval
eval(JS); // Init Javascript
}
}
};
serialLoad(i);
}
else if (JS && JS.length) { // in case there are no JS files, but there is some JS to eval
eval(JS); // Init Javascript
}
};