jquery - Chaining dynamically loaded javascript -
i have static page i'm trying add jquery , blockui plugin to. jquery needs loaded first before can use blockui, , while can load jquery fine, cant seem blockui load after , call loaded handler can work. see blockui script tag in html page, @ least being injected in okay far can see. here's code:
var jqueryscript = document.createelement( "script" ); jqueryscript.src = "/glptools/scripts/jquery-1.9.1.min.js"; if ( jqueryscript.addeventlistener ) { jqueryscript.addeventlistener( "load", jqueryready, false ); } else if ( jqueryscript.readystate ) { jqueryscript.onreadystatechange = jqueryready; } document.getelementsbytagname( 'head' )[0].appendchild( jqueryscript ); function jqueryready() { if ( typeof jquery != 'undefined' ) { $( document ).ready( function () { //initialize tabber tabberautomatic( "" ); // add blockui plugin var blockuiscript = document.createelement( "script" ); blockuiscript.src = "/glptools/scripts/blockui/jquery.blockui.js"; if ( blockuiscript.addeventlistener ) { blockuiscript.addeventlistener( "load", blockuiready, false ); } else if ( blockuiscript.readystate ) { blockuiscript.onreadystatechange = blockuiready; } document.getelementsbytagname( 'head' )[0].appendchild( blockuiscript ); } ); } } function blockuiready() { $( "#tabbertabhide" ).each( function ( index, elem ) { $( elem ).block(); } ); }
my goal use blockui block tabs located on page. tried putting block ui load code outside ready() call, loaded handler gets called before jquery has been loaded.
if blockui depends on jquery, need load sequentially. can this:
//this function creates script element using "resource" , //adds head. callback used onload callback //for script function loadscript(resource, callback) { var head = document.getelementsbytagname("head")[0]; var script = document.createelement("script"); script.type = "text/javascript"; script.src = resource + "?t=" + new date().gettime(); //prevent caching if (callback) { script.onload = callback; } head.appendchild(script); } //array of scripts load var resources = [ "/glptools/scripts/jquery-1.9.1.min.js", "/glptools/scripts/blockui/jquery.blockui.js" ]; //this function load scripts 1 after other, using callback //that calls function itself. function load(i) { if(i < resources.length) { loadresource(resources[i], function() { load(++i); }); } else { //everything has finished loading can start //using jquery , blockui } } load(0);
Comments
Post a Comment