As I'm learning JQM, I discover that JQM doesn't load pages as a normal browser does. It just fetches the content and updates the DOM.
When the requested page loads, jQuery Mobile parses the document for an element with the data-role="page" attribute and inserts that code into the DOM of the original page.
I mix between physical pages and JQM pages. Pages are loaded using PHP and my tempalte code loosk like this:
include('views/widgets/head.php');
include($view);
include('views/widgets/footer.php');
A view is the same as a PHP page.
Front page
URL: mysite.com
Pages: #frontPage
Page B
URL: mysite.com/page-b
Pages: #listPage, #infoPage, #mapPage
Page C
URL: mysite.com/page-c
Pages: #listPage, #infoPage, #mapPage
My current solutions was to wrap the multipage in a container:
That might explain why I'm having issues with this code:
if($('#frontPage').length > 0) { Lib.setTitle('Front Page'); }
if($('#pageB').length > 0) { Lib.setTitle('Page B'); }
if($('#pageC').length > 0) { Lib.setTitle('Page C'); }
Whenever I navigate back to my front page, it seems the first statement is triggered, then overridden by the last statement triggered. I know because the headline flickers when it is first set to "Front Page" and then overriden by "Page C".
I should probably be using events like pageload, pagebeforeload, pagebeforeshow, but they are so many and "similar" that I'm unsure which one to use.
What is the "correct" way of identifying what page I'm loading so that I can execute the correct functions?
What is the correct code to do execute global functions for any page loaded?
Update
All custom JS files are loaded in the global / external footer.