Created
August 25, 2009 09:07
-
-
Save slaskis/174574 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
714 function bindReady() { | |
715 if ( readyBound ) return; | |
716 readyBound = true; | |
717 | |
718 // Catch cases where $(document).ready() is called after the | |
719 // browser event has already occurred. | |
720 if ( document.readyState === "complete" ) { | |
721 return jQuery.ready(); | |
722 } | |
723 | |
724 // Mozilla, Opera and webkit nightlies currently support this event | |
725 if ( document.addEventListener ) { | |
726 // Use the handy event callback | |
727 document.addEventListener( "DOMContentLoaded", function() { | |
728 document.removeEventListener( "DOMContentLoaded", arguments.callee, false ); | |
729 jQuery.ready(); | |
730 }, false ); | |
731 | |
732 // If IE event model is used | |
733 } else if ( document.attachEvent ) { | |
734 // ensure firing before onload, | |
735 // maybe late but safe also for iframes | |
736 document.attachEvent("onreadystatechange", function() { | |
737 if ( document.readyState === "complete" ) { | |
738 document.detachEvent( "onreadystatechange", arguments.callee ); | |
739 jQuery.ready(); | |
740 } | |
741 }); | |
742 | |
743 // If IE and not an iframe | |
744 // continually check to see if the document is ready | |
745 if ( document.documentElement.doScroll && window === window.top ) (function() { | |
746 if ( jQuery.isReady ) { | |
747 return; | |
748 } | |
749 | |
750 try { | |
751 // If IE is used, use the trick by Diego Perini | |
752 // http://javascript.nwbox.com/IEContentLoaded/ | |
753 document.documentElement.doScroll("left"); | |
754 } catch( error ) { | |
755 setTimeout( arguments.callee, 0 ); | |
756 return; | |
757 } | |
758 | |
759 // and execute any waiting functions | |
760 jQuery.ready(); | |
761 })(); | |
762 } | |
763 | |
764 // A fallback to window.onload, that will always work | |
765 jQuery.event.add( window, "load", jQuery.ready ); | |
766 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment