The bindReady()
event method is the current jQuery's implementation of the W3C DOM DOMContentLoaded
event. It is
as follows:
bindReady: function() { if ( readyBound ) { return; } readyBound = true; // Catch cases where $(document).ready() is called after the // browser event has already occurred. if ( document.readyState === "complete" ) { return jQuery.ready(); } // Mozilla, Opera and webkit nightlies currently support this event if ( document.addEventListener ) { // Use the handy event callback document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false ); // A fallback to window.onload, that will always work window.addEventListener( "load", jQuery.ready, false ); // If IE event model is used } else if ( document.attachEvent ) { // ensure firing before onload, // maybe late but safe also for iframes document.attachEvent("onreadystatechange", DOMContentLoaded); // A fallback to window.onload, that will always work window.attachEvent( "onload", jQuery.ready ); // If IE and not a frame // continually check to see if the document is ready var toplevel = false; try { toplevel = window.frameElement == null; } catch(e) {} if ( document.documentElement.doScroll && toplevel ) { doScrollCheck(); } } },
- sets the
readyBound
property totrue
- checks if
$(document).ready()
is invoked after the DOM statereadyState
is already set tocomplete
- uses object detection to target standard W3C DOM compliant browser and Internet Explorer by using
DOMContentLoaded
for the first group andonreadystatechange
for the latter - if something goes wrong during the previous step, it uses the common DOM
load
event - handles the case of HTML frames.