Skip to content

Instantly share code, notes, and snippets.

@Omar-Gonzalez
Last active September 7, 2017 16:52
Show Gist options
  • Save Omar-Gonzalez/d70c8973fb148629c6508e5529a76b30 to your computer and use it in GitHub Desktop.
Save Omar-Gonzalez/d70c8973fb148629c6508e5529a76b30 to your computer and use it in GitHub Desktop.
Custom Document Ready
!function(t, n) {
function e() {
if (!a) {
a = !0;
for (var t = 0; t < d.length; t++) d[t].fn.call(window, d[t].ctx);
d = [];
}
}
function o() {
"complete" === document.readyState && e();
}
t = t || "docReady";
var d = [], a = !1, c = !1;
(n = n || window)[t] = function(t, n) {
if ("function" != typeof t) throw new TypeError("callback for docReady(fn) must be a function");
a ? setTimeout(function() {
t(n);
}, 1) : (d.push({
fn: t,
ctx: n
}), "complete" === document.readyState ? setTimeout(e, 1) : c || (document.addEventListener ? (document.addEventListener("DOMContentLoaded", e, !1),
window.addEventListener("load", e, !1)) : (document.attachEvent("onreadystatechange", o),
window.attachEvent("onload", e)), c = !0));
};
}("docReady", window);
docReady(function(){
//do your stuff
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment