Skip to content

Instantly share code, notes, and snippets.

View alano999's full-sized avatar

Alan O alano999

  • Wiltshire, UK
View GitHub Profile
@alano999
alano999 / gist:3658769
Created September 6, 2012 17:27
JavaScript - run a function once DOM has loaded, or straightaway if already loaded
document.addEventListener("DOMContentLoaded", DomIsLoaded, false);
//readystate :: loading --> interactive (document.DOMContentLoaded) --> complete (window.load)
if (document.readyState === "complete" || document.readyState === "interactive") {
document.removeEventListener("DOMContentLoaded", DomIsLoaded);
DomIsLoaded();
}
// usage----------------->
function DomIsLoaded() {
// do stuff once DOM has loaded
@alano999
alano999 / gist:3665444
Created September 7, 2012 11:41
JavaScript - run a function once document fully loaded, or straightaway if already loaded
window.addEventListener("load", WindowIsLoaded, false);
//readystate :: loading --> interactive (document.DOMContentLoaded) --> complete (window.load)
if (document.readyState === "complete") {
window.removeEventListener("load", WindowIsLoaded);
WindowIsLoaded();
}
// usage----------------->
function WindowIsLoaded() {
// do stuff once document has fully loaded and processed
@alano999
alano999 / README.md
Created September 15, 2012 15:12
Sequence (chain) multiple asynchronous jQuery operations, such as AJAX

MULTIPLE SEQUENTIAL ASYNCHRONOUS OPERATIONS IN JQUERY

Multiple asynchronous jQuery operations such as .ajax() and animations can be sequenced (chained) using the accompanying patterns which make use of jQuery Deferred techniques rather than the less extensible and non-ideal recursive call techniques.

There are three usage patterns, each implemented herein and tested using the supplied data for .ajax() transactions...

  1. Sequential in series using pre-defined data;
  2. Sequential in series, feeding each request using the response from previous request;
  3. Parallel request using pre-defined data, where responses are sequenced.