Require.js Cordova 1.6 and deviceready

748 views
Skip to first unread message

Will

unread,
Apr 12, 2012, 7:37:58 PM4/12/12
to phon...@googlegroups.com
I'm trying to include require.js, but whenever I do, it seems that deviceready is never fired.

If I try to load cordova through require.js, Xcode complains that Cordova setinfo isn't available (like it's sending data to webkit before require has initialized the cordova). If I don't have require load a "main" script, it seems to catch the event.

I removed require.js and deviceready is being caught by my index inline javascript.

It seems that if I use require, the deviceready event is firing before my dom is ready, or require is done.

Is there a way to check if deviceready has fired directly through the cordova object? cordova.isDeviceReady() or something?

Jonathan Stevens

unread,
Apr 13, 2012, 1:26:52 AM4/13/12
to phonegap
We have this exact same problem. It worked fine in 1.5, but
deviceready no longer fires if require.js is referenced.

Ken OKABE

unread,
Apr 13, 2012, 3:28:30 AM4/13/12
to phon...@googlegroups.com
Probably this bug
https://issues.apache.org/jira/browse/CB-491

I reported on this ML, too.

On Fri, Apr 13, 2012 at 2:26 PM, Jonathan Stevens <jmsg...@gmail.com> wrote:
> We have this exact same problem.  It worked fine in 1.5, but
> deviceready no longer fires if require.js is referenced.
>

> --
> You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phon...@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/phonegap?hl=en?hl=en
>
> For more info on PhoneGap or to download the code go to www.phonegap.com

Dewang Shah

unread,
Apr 13, 2012, 6:21:51 AM4/13/12
to phon...@googlegroups.com
I don't think it's that bug. I have been using addEventListener all along. Cordova 1.5 worked fine (with a patch to the JS to get around the require/define method issue) with RequireJS.

I just tried to move to 1.6.0 and deviceready fires but all the libraries I try to load after Cordova fail with a timeout. I tried moving the Cordova library as the last one to be loaded but that still doesn't help. It fires deviceready much quicker than it used to with 1.5 and then the rest of the libraries cannot be loaded.


On Friday, April 13, 2012 8:28:30 AM UTC+1, KenOKABE wrote:
Probably this bug
https://issues.apache.org/jira/browse/CB-491

I reported on this ML, too.

On Fri, Apr 13, 2012 at 2:26 PM, Jonathan Stevens <jmsgofish at gmail.com> wrote:
> We have this exact same problem.  It worked fine in 1.5, but
> deviceready no longer fires if require.js is referenced.
>
> --
> You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phon...@googlegroups.com
> To unsubscribe from this group, send email to

> phonegap+unsubscribe@googlegroups.com

Jonathan Stevens

unread,
Apr 13, 2012, 3:43:46 PM4/13/12
to phonegap
That's not the same bug. My code for listening for deviceready looks
like this:

document.addEventListener("deviceready", function()
{ alert('device ready'); }, false);

It does not work unless I comment out my require.js reference.

Kelvin Law

unread,
Apr 14, 2012, 3:18:35 AM4/14/12
to phon...@googlegroups.com
I think the issue is with Cordova defining its own versions of require and define. 

I might have managed to get it working by running uglifyjs on cordova-1.6.0.js putting that in a separate <script> in my html file and including require.js after this.

seems to work for me

kamiseq

unread,
Apr 23, 2012, 4:37:31 PM4/23/12
to phonegap
hej,
I have the same problem - the deviceready is not called, but even I
removed requestJs completely from html. when I moved back to 1.5
everything works fine, so there must something about cordova1.6

I tried very basic example from http://docs.phonegap.com/en/1.6.0/cordova_events_events.md.html#deviceready
and it works on 1.5 and breaks on 1.6
Reply all
Reply to author
Forward
0 new messages