0

I am trying to make my app (which uses Jquery Mobile 1.4) able to run

  • either as a Phonegap app (using Phonegap Build, not Xcode)

  • or as a pure webapp on a standard browser by starting my js file like below.

But none of the Jquery Mobile events are bound...

Can you help me see why ?

var deviceReadyDeferred = $.Deferred();
var jqmReadyDeferred = $.Deferred();

$(document).one("mobileinit", function () {
    console.log('mobileinit just fired');
    jqmReadyDeferred.resolve();
});

document.addEventListener("deviceReady", onDeviceReady, false);
function onDeviceReady() {
    deviceReadyDeferred.resolve();
}

if ( isPhoneGap() ) {
    alert("isPhoneGap yes");
    $.when(deviceReadyDeferred, jqmReadyDeferred).then( EVERYTHING );
} else {
    console.log("NOT Running on PhoneGap!");
    $.when(jqmReadyDeferred).then( EVERYTHING );
}

function EVERYTHING() {

    //all the JQM bindings here:
    $(document).on('pagecontainershow', function (e, ui) {
        //...
    });
    $(document).on('pagecreate','#splash-page', function(){
        //...
    });
    $(document).on('pagecreate','#faq-page', function(){
        //...
    });
    //etc.
}

PS: I use the function isPhoneGap from here and this works fine.

Community
  • 1
  • 1
Louis
  • 2,548
  • 10
  • 63
  • 120

1 Answers1

0

It should not be. Your description is quite common and I could not find anything wrong. Note that you do not need to declare the Deffered object in $(document).ready() function, just let it be.

I think you need to add popup message in 2 places: onDeviceReady: to know whether the deviceready event works. EVERYTHING: to know whether these 2 Deffered object are both resolved.

BTW, I do not think isPhoneGap is a perfect one to detect whether an app is a Phonegap one or not. Sometime, you use Phonegap build to compile an app project but you forget to add cordova.js declaration, this function will still tell you "it is a Phonegap app"(This maybe current condition for you). This function is only based on the url of the link. However, as for my opinion, whether deviceready event is working is the only and best way to judge if it is a Phonegap app.

Jack He
  • 1,683
  • 3
  • 18
  • 29
  • Ok thanks for your answer. I tried to pop message in a lots of spots in the code. And onDeviceReady is well fired, and the function EVERYTHING is well started. Is there something about JQM not liking to bind events from within a function or something ? – Louis Jul 22 '14 at 07:32