Created
October 10, 2011 08:33
-
-
Save vjeux/1274869 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Handle when the DOM is ready | |
ready: function( wait ) { | |
// Either a released hold or an DOMready/load event and not yet ready | |
if ( (wait === true && !--jQuery.readyWait) || (wait !== true && !jQuery.isReady) ) { | |
// Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443). | |
if ( !document.body ) { | |
return setTimeout( jQuery.ready, 1 ); | |
} | |
// Remember that the DOM is ready | |
jQuery.isReady = true; | |
// If a normal DOM Ready event fired, decrement, and wait if need be | |
if ( wait !== true && --jQuery.readyWait > 0 ) { | |
return; | |
} | |
// If there are functions bound, to execute | |
readyList.resolveWith( document, [ jQuery ] ); | |
// Trigger any bound ready events | |
if ( jQuery.fn.trigger ) { | |
jQuery( document ).trigger( "ready" ).unbind( "ready" ); | |
} | |
} | |
}, | |
bindReady: function() { | |
if ( readyList ) { | |
return; | |
} | |
readyList = jQuery._Deferred(); | |
// Catch cases where $(document).ready() is called after the | |
// browser event has already occurred. | |
if ( document.readyState === "complete" ) { | |
// Handle it asynchronously to allow scripts the opportunity to delay ready | |
return setTimeout( jQuery.ready, 1 ); | |
} | |
// 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(); | |
} | |
} | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment