Browse files adding in the "page-level hack" for DOM-ready in FF3.5 an…

…d below
  • Loading branch information...
getify committed May 18, 2011
1 parent b09c6fd commit c0f57d74906c1cd6ddd723194eff71c5fec7c871
Showing with 20 additions and 0 deletions.
  1. +20 −0 next/LAB.src.js
@@ -492,4 +492,24 @@
// create the main instance of $LAB
global.$LAB = create_sandbox();
+ /* The following "hack" was suggested by Andrea Giammarchi and adapted from:
+ NOTE: this hack only operates in FF and then only in versions where document.readyState is not present (FF < 3.6?).
+ The hack essentially "patches" the **page** that LABjs is loaded onto so that it has a proper conforming document.readyState, so that if a script which does
+ proper and safe dom-ready detection is loaded onto a page, after dom-ready has passed, it will still be able to detect this state, by inspecting the now hacked
+ document.readyState property. The loaded script in question can then immediately trigger any queued code executions that were waiting for the DOM to be ready.
+ For instance, jQuery 1.4+ has been patched to take advantage of document.readyState, which is enabled by this hack. But 1.3.2 and before are **not** safe or
+ fixed by this hack, and should therefore **not** be lazy-loaded by script loader tools such as LABjs.
+ */
+ (function(addEvent,domLoaded,handler){
+ if (document.readyState == null && document[addEvent]){
+ document.readyState = "loading";
+ document[addEvent](domLoaded,handler = function(){
+ document.removeEventListener(domLoaded,handler,false);
+ document.readyState = "complete";
+ },false);
+ }
+ })("addEventListener","DOMContentLoaded");

0 comments on commit c0f57d7

Please sign in to comment.