various page events do not fire on first load. #508

Closed
mrubinsk opened this Issue Nov 18, 2010 · 6 comments

Comments

Projects
None yet
2 participants
Contributor

mrubinsk commented Nov 18, 2010

When loading a file for the first time, the various page events do not fire. Example, the following structure:

 <div data-role="page" id="pageOne">
     <div data-role="header"><h3>Page One</h3></div>
     <div data-role="content" class="ui-body"><a href="#pageTwo">Page One</a></div>
 </div>
 <div data-role="page" id="pageTwo">
     <div data-role="header"><h3>Page Two</h3></div>
     <div data-role="content" class="ui-body">Page Two</div>
 </div>

and the following javascript:

<script type="text/javascript">
 $(function() {
   $('#pageOne').live('pageshow', function() { alert('showing pageone'); });
   $('#pageTwo').live('pageshow', function() { alert('showing pagetwo'); });
   alert($.mobile.currentPage);
 });
</script>

Neither of the pageshow events will fire (neither pageOne on first load, or pageTwo, if the url includes the #pageTwo hash). The $.mobile.currentPage alert fires, but shows undefined. Navigating after the page is loaded works as expected.

Contributor

scottjehl commented Dec 6, 2010

Did you place your script between jquery and jquery mobile? These events must be bound before jQuery mobile executes. I just tested on my end and it seems to be working as expected...

Contributor

mrubinsk commented Dec 6, 2010

Nope. The script is placed after both jquery and jquery mobile in the head. It also occurs if I place the script at the end of the body as well.

I put my test script up at:
http://theupstairsroom.com/jq/index.html

Expected behavior:
pagebeforecreate, beforepageshow, pageshow events should fire during initial page load, and beforepageshow, pageshow events should fire at appropriate times during subsequent navigation.

Demonstrated behavior:
No events at all are fired during initial page load, and only the pageshow events are fired during subsequent navigation. The page initialization events are never fired.

Contributor

mrubinsk commented Dec 6, 2010

Oh, wait, all of these have to be bound before jquery mobile is loaded?

Contributor

mrubinsk commented Dec 6, 2010

Ok, I guess that makes sense now that I think about it. Still, how about updating the documentation to make this more obvious?

Thanks for the help.

Contributor

scottjehl commented Dec 6, 2010

The third paragraph on this page explains it, but please send us a pull request if you figure out a better way: http://jquerymobile.com/test/#docs/api/globalconfig.html

Thanks!

Contributor

mrubinsk commented Dec 7, 2010

Done:

#628

Thanks!

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment