Changing the initial load page/div in jQuery Mobile

Changing the initial load page/div in jQuery Mobile

We have a page which is heavily data-driven and so users could be navigating to a HTML page which, depending on the user, could potentially see a different landing div (where data-role=div).

Currently, the solution I have worked out so far is as follows (this is a jQuery Mobile/PhoneGap application, hence the deferred bit at the beginning in order to combine the two events into one).

  1. var deviceReadyDeferred = $.Deferred();
  2. var jqmReadyDeferred = $.Deferred();
  3. document.addEventListener("deviceReady", deviceReady, false);
  4. function deviceReady() {
  5. deviceReadyDeferred.resolve();
  6. }
  7. $(document).one("mobileinit", function () {
  8. $.mobile.autoInitializePage = false;
  9. jqmReadyDeferred.resolve();
  10. });
  11. $.when(deviceReadyDeferred, jqmReadyDeferred).then(function() {
  12.             var startDivID = getStartDivID(sessionStorage.getItem("UserID");
  13.             $(startDivID).appendTo("body");
  14.             $.mobile.initializePage();
  15. });

    Thus what this is doing is waiting for both PhoneGap and jQuery to become ready (I use some bits from PhoneGap as part of my initialisation hence the need for both); when both are ready - I get the user's startDivID (based on some code below which you don't have to worry about) and then move it to the first DIV in the <body> and then initialise jQuery Mobile. Is there a better way to do this?

    Thanks
    Kelvin