Created
March 16, 2016 11:53
-
-
Save cloudscape-germany/9dcfad706305777a4fba to your computer and use it in GitHub Desktop.
Jquery OnReady
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
| /* | |
| * Copyright 2010, John Resig | |
| * Dual licensed under the MIT or GPL Version 2 licenses. | |
| * http://jquery.org/license | |
| */ | |
| // Cleanup functions for the document ready method | |
| // attached in the bindReady handler | |
| if ( document.addEventListener ) { | |
| DOMContentLoaded = function() { | |
| document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false ); | |
| //jQuery.ready(); | |
| yourcallback(); | |
| }; | |
| } else if ( document.attachEvent ) { | |
| DOMContentLoaded = function() { | |
| // Make sure body exists, at least, in case IE gets a little overzealous | |
| if ( document.readyState === "complete" ) { | |
| document.detachEvent( "onreadystatechange", DOMContentLoaded ); | |
| //jQuery.ready(); | |
| yourcallback(); | |
| } | |
| }; | |
| } | |
| // 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 ); | |
| // ^^ you may want to call *your* function here, similarly for the other calls to jQuery.ready | |
| setTimeout( yourcallback, 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 ); | |
| window.addEventListener( "load", yourcallback, 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", yourcallback ); | |
| } |
Author
cloudscape-germany
commented
Mar 16, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment