// HOWTO: load LABjs itself dynamically! // inline this code in your page to load LABjs itself dynamically, if you're so inclined. (function (global, oDOC, handler) { var head = document.getElementsByTagName("head") , sOnLoad = "onload" , sReadyState = "readyState" , sDomContentLoaded = "DOMContentLoaded" , sLoaded = "loaded" , sComplete = "complete" , sOnReadyStateChange = "onreadystatechange"; , bFalse = false , bTrue = true; function LABjsLoaded() { // do cool stuff with $LAB here } // loading code borrowed directly from LABjs itself setTimeout(function() { if ("item" in head) { // check if ref is still a live node list if (!head[0]) { // append_to node not yet ready setTimeout(arguments.callee, 25); return; } head = head[0]; // reassign from live node list ref to pure node ref -- avoids nasty IE bug where changes to DOM invalidate live node lists } var scriptElem = oDOC.createElement("script"), scriptdone = bFalse; scriptElem.type = "text/javascript"; scriptElem[sOnload] = scriptElem[sOnReadyStateChange] = function () { if ((scriptElem[sReadyState] && scriptElem[sReadyState] !== sComplete && scriptElem[sReadyState] !== sLoaded) || scriptdone) { return bFalse; } scriptElem[sOnload] = scriptElem[sOnReadyStateChange] = nNull; scriptdone = bTrue; LABjsLoaded(); }; scriptElem.src = "/path/to/LAB.js"; head.insertBefore(scriptElem, head.firstChild); }, 0); // required: shim for FF <= 3.5 not having document.readyState if (oDOC[sReadyState] == nNull && oDOC.addEventListener) { oDOC[sReadyState] = "loading"; oDOC.addEventListener(sDOMContentLoaded, handler = function () { oDOC.removeEventListener(sDOMContentLoaded, handler, bFalse); oDOC[sReadyState] = sComplete; }, bFalse); } })(window, document);