david-mark-llc / jessie

Javascript cross-browser library builder enabling (real) progressive enhancement
http://jessie.herokuapp.com
39 stars 13 forks source link

deferUntilReady uses reference to globalDocument (which is nullified) #259

Closed andrewscode closed 9 years ago

andrewscode commented 9 years ago

The 2nd rendition of deferUntilReady depends on the globalDocument variable

global.addEventListener('load', readyListener, false);
globalDocument.addEventListener('DOMContentLoaded', readyListener, false);

However, a build of jessie will nullify the globalDocument at the end of a build

globalDocument = html = null;

So when deferUntilReady is called, an error occurs.

Should the deferUntilReady simply call

global.document.addEventListener('DOMContentLoaded', readyListener, false);

?

adamsilver commented 9 years ago

Yes. I think this should be

window.addEventListener(...);
document.addEventListener(...);

Thanks Andrew. Feel free to open a pull request for this.

david-mark commented 9 years ago

Yes, not sure where that globalDocument reference came from.

Would be global and global.document in My Library as it doesn't reference the window object. I like having the document reference tied to the global reference as it easier to automate frames, run outside of browsers (e.g. on NodeJS), etc.

andrewscode commented 9 years ago

I just noticed one other thing, the comments regarding adding the following:

        <script type="text/javascript">
            if ('function' == typeof readyListener) {
                window.setTimeout(readyListener, 1);
            }
        </script>

However, readyListener isn't in the global scope, so this will never be called.

david-mark commented 9 years ago

The readyListener variable should be in the global scope for this purpose. If not, needs to be fixed.