I am trying to only load jquery and jqueryui if they do not already
exist. If they do exist, then I load a bunch of plug-ins used by the
app. However, the below is not working and I have no idea why. Can
anyone provide some insight?

if (typeof jQuery == 'undefined') {
        console.log("loading local jquery files");

        var head = document.getElementsByTagName("head")[0];
        var script = document.createElement("script");
        script.type = "text/javascript";
        script.src = "/cml/js/jquery.min.js";
        script.onload = loadPlugins();
        head.appendChild(script);
        var script2 = document.createElement("script");
        script2.type = "text/javascript";
        script2.src = "/cml/js/jquery-ui.min.js";
        head.appendChild(script2);
    }

        function loadPlugins(){
                if(typeof jQuery != 'undefined'){
                        console.log("jquery is defined");

                        jQuery.noConflict();

                        //load the plugins
                        if(!jQuery().maxlength){
                                jQuery("head").append('<scr' + 'ipt 
type="text/javascript" src="<
%=response.encodeURL(cntxPath + "/js/jquery.maxlength-min.js")%>"></
scr' + 'ipt>');
                                console.log("loaded maxlength plugin");
                        }

                        if(!jQuery().address){
                                jQuery("head").append('<scr' + 'ipt 
type="text/javascript" src="<
%=response.encodeURL(cntxPath + "/js/jquery.address-1.1.min.js")%>"></
scr' + 'ipt>');
                                console.log("loaded address plugin");
                        }

                        if(!jQuery().delay){
                                jQuery("head").append('<scr' + 'ipt 
type="text/javascript" src="<
%=response.encodeURL(cntxPath + "/js/jquery.delay.js")%>"></scr' +
'ipt>');
                                console.log("loaded delay plugin");
                        }

                        if(!jQuery().ajaxSubmit){
                                jQuery("head").append('<scr' + 'ipt 
type="text/javascript" src="<
%=response.encodeURL(cntxPath + "/js/jquery.form.js")%>"></scr' +
'ipt>');
                                console.log("loaded form plugin");
                        }
        ....

Thanks everyone.

Reply via email to