JSFiddle - React, Tailwind, and code Playground
by Andrew Gerst
JavaScript
/*
jQuery's document.ready/$(function(){}) should
you wish to use a cross-browser DOMReady solution
without opting for a library.
Demo: http://jsfiddle.net/zKLpb/
usage:
$(function(){
// your code
});
Parts: jQuery project, Diego Perini, Lucent M.
This version: Addy Osmani
*/
(function( window ) {
"use strict";
// Define a local copy of $
var $ = function( callback ) {
readyBound = false;
$.isReady = false;
if ( typeof callback === "function" ) {
DOMReadyCallback = callback;
}
bindReady();
},
// Use the correct document accordingly with window argument (sandbox)
document = window.document,
readyBound = false,
DOMReadyCallback = function() {},
// The ready event handler
DOMContentLoaded = function() {
if ( document.addEventListener ) {
document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false );
} else {
// we're here because readyState !== "loading" in oldIE
// which is good enough for us to call the dom ready!
document.detachEvent( "onreadystatechange", DOMContentLoaded );
}
DOMReady();
},
// Handle when the DOM is ready
DOMReady = function() {
// Make sure that the DOM is not already loaded
if ( !$.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
$.isReady = true;
// If there are functions bound, to execute
DOMReadyCallback();
// Execute all of them
}
}, // /ready()
...