scottschiller/SoundManager2 — pull request #43 by eml (2013-12-31 00:48:15+00:00)
Title: DOMContentLoaded/readyState=='interactive' fix

We use SM2 internally with requirejs and also we bundle up SM2 with our own library that is loaded in a script tag. To keep initialization of SM2 consistent in the diff environments we use 'SM2_DEFER = true' and then create and 'setup' the SoundManager instance ourselves rather than have it initialize things as soon as the file is loaded.

We ran into a problem when using the deferred setup and jQuery's document ready handler, where the 'ready' event is never called:

```

```

It seems that the document.readyState at the point in time we call 'soundManager.setup()' is 'interactive', and not 'complete', but the 'DOMContentLoaded' event has already been sent, so 'domContentLoaded' is never called and we get no sound.

This fix basically duplicates what the jquery guys did, which is add a fallback 'load' handler for the window object. See the inspiration here:

https://github.com/jquery/jquery/blob/master/src/core/ready.js