incubator-callback-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Filip Maj (JIRA)" <>
Subject [jira] [Resolved] (CB-491) cordova-1.6.0 + jquery/zepto $(document).bind("deviceready") does not work
Date Sun, 22 Apr 2012 06:47:59 GMT


Filip Maj resolved CB-491.

    Resolution: Not A Problem

Hi everyone,

Spent a bit of time tracking this one down. I could reproduce the error message on iPhone

[INFO] Error in success callback: NetworkStatus0 = TypeError:
'undefined' is not an object

The undefined exception is caused by jQuery event handling code. I dug into jQuery's code
and found the root of the problem: when deviceready is internally dispatched in Cordova, it
fires all subscribed handlers with _no_ event parameter into the callbacks. It is this detail
that trips jQuery up. Specifically, when deviceready is fired, jQuery:

 1. [Calls its dispatch function|].
The first thing this function does is [call a fix function|]
that is supposed to normalize the event object parameter being passed into the subscribed
 2. jQuery passes either the event object parameter, OR {{window.event}} (see above link).
In cordova's case on the iPhone, *both* of these are {{undefined}}.
 3. If we then take a look at [jQuery's fix function|],
the first thing it does is check the existence of a {{jQuery.expando}} property on the passed-in
event object. Boom, undefined is not an object.

So bottom line: jQuery's assumption that all custom events being attached to using {{bind}}
provide some sort of object into the callback is probably bad. I tried a quick hack/fix by
adding another "|| {}" into the parameter short-circuit passed into {{fix}}, but that didn't
fix the issue completely (no exception was thrown but the deviceready alert still did not

Sorry folks but this isn't one that cordova can directly fix as it is a jQuery issue. Perhaps
if/when we tackle CB-514 then it would resolve this issue as well, but until then, I would
recommend filing this as an issue with the jQuery team and hoping something over there can
be fixed.
> cordova-1.6.0 + jquery/zepto $(document).bind("deviceready") does not work
> --------------------------------------------------------------------------
>                 Key: CB-491
>                 URL:
>             Project: Apache Callback
>          Issue Type: Bug
>          Components: CordovaJS
>    Affects Versions: 1.6.0
>         Environment: Tested on iOS 5.1
>            Reporter: Moisés Gramary
>            Assignee: Filip Maj
>            Priority: Minor
>              Labels: javascript, patch
>   Original Estimate: 2h
>  Remaining Estimate: 2h
> With Phonegap1.4 or 1.5, I have been OK with the code below, but now I stuck.
> Anyone has an idea? Thanks.
> <html>
> <head>
>     <meta name="viewport" content="width=device-width,
> initial-scale=1.0, maximum-scale=1.0, user-scalable=no;"/>
>     <meta charset="utf-8">
>     <script type="text/javascript" charset="utf-8"
> src="js/cordova-1.6.0.js"></script>
>     <script type="text/javascript" src="js/jquery.min.js"></script>
>     <script type="text/javascript">
>         $(document).ready(function()
>         {
>             alert("this Alert fires OK");
>             $(document).bind("deviceready", function()
>             {
>                 alert("Got the Error and this Alert Never fires");
>             });
>         });
>     </script>
> </head>
> <body>
> <p id="deviceProperties" style="font-size: 20px"></p>
> </body>
> </html>
> (by KenOKABE on!topic/phonegap/TImcr9kzlq0)
> Possible solution-->
> Hello, I had the same problem with the upgrade from 1.5 to 1.6...
> After a long day I found that that deviceready event begins a little "freak", try changing:
>     $(document).bind("deviceready", function()
>     {
>         //code
>     });
> by:
>     document.addEventListener("deviceready", function()
>     {
>         //code
>     }, false);
> It worked for me, even so, the most weird thing is that other events like touchmove or
orientationchange still works with $( document ).bind; even $( document ).ready function works....
> Appears to fail only with deviceready PG/CV event....
> (by Moisés Gramary Barbosa on same thread)

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:!default.jspa
For more information on JIRA, see:


View raw message