Skip to content
This repository was archived by the owner on Dec 31, 2022. It is now read-only.

Commit c0f57d7

Browse files
committed
LABjs.next: adding in the "page-level hack" for DOM-ready in FF3.5 and below
1 parent b09c6fd commit c0f57d7

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

next/LAB.src.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,4 +492,24 @@
492492
// create the main instance of $LAB
493493
global.$LAB = create_sandbox();
494494

495+
496+
/* The following "hack" was suggested by Andrea Giammarchi and adapted from: http://webreflection.blogspot.com/2009/11/195-chars-to-help-lazy-loading.html
497+
NOTE: this hack only operates in FF and then only in versions where document.readyState is not present (FF < 3.6?).
498+
499+
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
500+
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
501+
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.
502+
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
503+
fixed by this hack, and should therefore **not** be lazy-loaded by script loader tools such as LABjs.
504+
*/
505+
(function(addEvent,domLoaded,handler){
506+
if (document.readyState == null && document[addEvent]){
507+
document.readyState = "loading";
508+
document[addEvent](domLoaded,handler = function(){
509+
document.removeEventListener(domLoaded,handler,false);
510+
document.readyState = "complete";
511+
},false);
512+
}
513+
})("addEventListener","DOMContentLoaded");
514+
495515
})(this);

0 commit comments

Comments
 (0)