I am loading jQuery and jQuery UI dynamically into a page, and I need to know when jQuery UI successfully expanded jQuery .
I am currently using the readystate script element that loads the jQuery UI to start running my code, but I think the script was loading at that moment, but the jQuery UI not initialized correctly.
Is the only choice to poll until $.ui is defined?
Here is the code I'm struggling with right now:
(load_ui = (callback) -> script2 = document.createElement("script") script2.type = "text/javascript" script2.src = "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.js" script2.onload = script2.onreadystatechange = -> console.log 'readystate:', @readystate if @readystate == "loaded" or @readystate == "complete" console.log "jquery ui is loaded" callback ($ = window.jQuery).noConflict(1), done = 1 $(script,script2).remove() document.documentElement.childNodes[0].appendChild script2 console.log 'jquery ui script element appended to page' (window, document, req_version, callback, $, script, done, readystate) -> if not ($ = window.jQuery) or req_version > $.fn.jquery or callback($) console.log "begin loading jquery" script = document.createElement("script") script.type = "text/javascript" script.src = "http://ajax.googleapis.com/ajax/libs/jquery/" + req_version + "/jquery.min.js" script.onload = script.onreadystatechange = -> if not done and (not (readystate = @readyState) or readystate == "loaded" or readystate == "complete") console.log "jquery is loaded, now loading jquery ui" load_ui(callback) document.documentElement.childNodes[0].appendChild script console.log 'jquery script element appended to page' ) window, document, "1.6.1", ($, L) -> console.log $ console.log $.ui.version
For some reason, the readistate of the jquery ui script element returns undefined.
Acorn source share