javascript - Do something once jQuery plugin has loaded -


i'm dynamically loading jquery , jquery ui page, , need know when jquery ui has extended jquery.

at moment i'm using readystate of script element loads jquery ui trigger running of code, think @ point, script has loaded, jquery ui hasn't been initialised.

is choice poll until $.ui defined?

here's code i'm wrestling with:

(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 loaded"         callback ($ = window.jquery).noconflict(1), done = 1         $(script,script2).remove()     document.documentelement.childnodes[0].appendchild script2     console.log 'jquery ui script element appended 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 , (not (readystate = @readystate) or readystate == "loaded" or readystate == "complete")         console.log "jquery loaded, loading jquery ui"         load_ui(callback)              document.documentelement.childnodes[0].appendchild script     console.log 'jquery script element appended page' ) window, document, "1.6.1", ($, l) ->     console.log $     console.log $.ui.version 

for reason readystate of jquery ui script element returns undefined.

i think need, add more dependency as like.

(function () {         function getscript(url, success) {             var script = document.createelement('script');             script.src = url;              var head = document.getelementsbytagname('head')[0];             var completed = false;             script.onload = script.onreadystatechange = function () {                 if (!completed && (!this.readystate || this.readystate == 'loaded' || this.readystate == 'complete')) {                     completed = true;                     success();                     script.onload = script.onreadystatechange = null;                     head.removechild(script);                 }             };             head.appendchild(script);         }          getscript("scripts/jquery-1.6.1.js", function () {             getscript("scripts/jquery-ui-1.8.11.js", function () {                 alert($.ui);             });         }); })(); 

tested with ie7, ie8, ie9, firefox, safari, chrome , opera


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -