Skip to content

Instantly share code, notes, and snippets.

@WebReflection
Created November 3, 2013 21:10
Show Gist options
  • Select an option

  • Save WebReflection/7294841 to your computer and use it in GitHub Desktop.

Select an option

Save WebReflection/7294841 to your computer and use it in GitHub Desktop.
simplifies ready behavior with modern browsers
/*! (C) Andrea Giammarchi */
(function(window, add, dom, load){
function ready(collection) {
return function(e) {
while(collection.length) {
collection.shift().call(window, e);
}
collection.K = true;
};
}
function on(collection) {
return function(fn){
collection.K ?
fn.call(window) :
collection.push(fn)
;
}
}
window.onDOM = on(dom);
window.onLoad = on(load);
document[add]('DOMContentLoaded', ready(dom));
window[add]('load', ready(load));
}(this, 'addEventListener', [], []));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment