soyjavi / QuoJS

Micro #JavaScript Library for Mobile Devices
MIT License
2.07k stars 236 forks source link

Release 2.3.6 crashes if QuoJS is inserted after the DOM is ready #105

Closed warpdesign closed 10 years ago

warpdesign commented 10 years ago

How to reproduce ?

  1. Load a page without Quo.
  2. append a "script" tag for Quo lib after the page is loaded

    What happens ?

Quo crashes: Uncaught TypeError: undefined is not a function quo.debug.js:804

Line 804 is:

$$(document).ready(function() { return _listenTouches(); });

_listenTouches is defined just below. Moving the ready() call at the end of the closure right before return _hold =... fixes this first problem.

After this fix the lib crashes because _listenTouches() calls $$.fn.bind which calls $$.fn.each which isn't defined yet. Replacing the call:

return this.each(function() { _subscribe(this, event, callback); });

with:

return this.forEach(function(element) { _subscribe(element, event, callback); });

definitely fixes the problem.

ericdevries commented 10 years ago

This is not yet been pulled in. Quo.js also breaks when you load scripts with the async attribute, because the document state is already interactive when it executes the script.

Please fix this as soon as possible, it is useless for us now

dominikwilkowski commented 10 years ago

:+1: for this fix

soyjavi commented 10 years ago

Fixed :)