jsdefer
jsdefer copied to clipboard
isLoaded feature
When a script is loaded on the page via script tag and then jsdefer tries to include it jsdefer should test for it.
jsdefer should provide a boolean expression test configurable in the script definition via deferDef... The old Sys.loader had this feature and it allows conditionally including a script based on how you define it. There are lots of uses for this...
Load script B only if script A is there (assuming you're not using jsdefer exclusively for script loading (we can't totally enforce it in some of our scenarios).
Also ensure that jQuery version present on page is at least 1.5 due to failure of fail method otherwise.
deferDef has a loaded property on each definition that is an expression. This is a temporary way to use this for now:
jsDefer.deferDef({ jQuery: { bare: true, url: ASPNETCDN + "/jQuery/jquery-1.6.1.js", urlMin: ASPNETCDN + "/jQuery/jquery-1.6.1.min.js", loaded: !!window.jQuery },
...
The workaround here is to make loaded a string like:
jsDefer.deferDef({ jQuery: { bare: true, url: ASPNETCDN + "/jQuery/jquery-1.6.1.js", urlMin: ASPNETCDN + "/jQuery/jquery-1.6.1.min.js", loaded: "!!window.jQuery" },
This string then gets eval'd by jsdefer.
Also, there is a bug in jsdefer, the loaded gets set to false always, even if you specify it. Workaround is to put this in jsdefer in the defer function:
var i, readyName, asyncLoad, result, prevPromise,
runWait = 0,
delayDomReady = options.delayDomReady || deferSettings.delayDomReady,
min = options.min || deferSettings.min,
scriptDef = getScriptDef(scriptName, basePath),
url = scriptDef.url,
loadUrl = (min && scriptDef.minUrl) || scriptDef.url,
settings = jsDefer.extend(scriptDef, options),
bare = settings.bare || scriptDef["bare"],
contains = settings.contains || scriptDef["contains"],
loaded = settings.loaded || scriptDef["loaded"],
depends = settings.depends || scriptDef["depends"],
multiple = settings.multiple || scriptDef["multiple"],
parentPromise = scriptDef.prntPrms,
promise = scriptDef.promise,
runCb,
//thisPromise,
hasRun, hasRunPromise;