I'm trying to prevent Jquery Mobile initialization until after the page content has been loaded, but I'm not getting the desired result. The project is a simple Question/Answer quiz. In my HTML document I have 3 containers div[data-role=page]:
div[data-role=page]#pg_title
div[data-role=page]#q0
div[data-role=page]#result
My document.ready() parses an external JSON file to load the content to these pages, duplicated #q0 to the number of questions in the quiz. The end result is something like:
div[data-role=page]#pg_title
div[data-role=page]#q0
div[data-role=page]#q1
div[data-role=page]#q2
div[data-role=page]#q3
div[data-role=page]#q4
div[data-role=page]#result
In my document head, I have:
<script>
$(document).bind("mobileinit", function () {
$.mobile.autoInitializePage = false;
});
</script>
<script src="js/quiz.js"></script>
<script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
http://jquerymobile.com/demos/1.1.0/docs/api/globalconfig.html says to configure settings before Jquery Mobile is loaded, which I had done. At the end of quiz.js I have the call to initialize the page:
$(document).ready(function(){
// ... all the code to load JSON quiz content is here
$.mobile.initializePage();
});
My problem is that when I proceed from the title page to the first question page, I see all of the questions rending at the same time. The rendered HTML looks like this:
<div data-role="page" id="q0" class="pg_type_question ui-page ui-body-c ui-page-active" data-title="Quiz Title" data-url="q0" tabindex="0" style="min-height: 826px; ">...</div>
<div data-role="page" id="q1" class="pg_type_question ui-page ui-body-c ui-page-active" data-title="Quiz Title" data-url="q0" tabindex="0" style="min-height: 826px; ">...</div>
<div data-role="page" id="q2" class="pg_type_question ui-page ui-body-c ui-page-active" data-title="Quiz Title" data-url="q0" tabindex="0" style="min-height: 826px; ">...</div>
<div data-role="page" id="q3" class="pg_type_question ui-page ui-body-c ui-page-active" data-title="Quiz Title" data-url="q0" tabindex="0" style="min-height: 826px; ">...</div>
<div data-role="page" id="q4" class="pg_type_question ui-page ui-body-c ui-page-active" data-title="Quiz Title" data-url="q0" tabindex="0" style="min-height: 826px; ">...</div>
After document.ready() but before mobile.initializePage is called the HTML renders as:
<div data-role="page" id="q1" class="pg_type_question" data-title="Quiz Title">...</div>
<div data-role="page" id="q2" class="pg_type_question" data-title="Quiz Title">...</div>
<div data-role="page" id="q3" class="pg_type_question" data-title="Quiz Title">...</div>
<div data-role="page" id="q4" class="pg_type_question" data-title="Quiz Title">...</div>
<div data-role="page" id="q5" class="pg_type_question" data-title="Quiz Title">...</div>
I don't understand why every question page is becoming active with a data-url of "q0".
Thanks in advance for your help!