I'm running a dynamic page generator in JQM and am struggling to get it to work correctly.
When a user clicks on a link, I intercept the changePage
call like this:
...
.on("pagebeforechange", function (e, data) {
if (typeof data.toPage === "string") {
init.parsePage(util.parseLink(data.toPage), true);
e.preventDefault();
}
})
which will call my parsePage
method, which generates a new page, initializes and appends it to the DOM like so:
$(document).enhanceWithin();
$.mobile.initializePage();
// go to the new page
$.mobile.changePage("#" + config.id);
My problem is, using e.preventDefault()
and a new changePage call will get caught in my pagebeforechange
listener again and loop forever. I also tried to not preventing the initial changepage call and just modifying the data.toPage
parameters, but assembly of my page takes "too long" and there is no way to delay JQM until the page is assembled.
Question:
How do I trigger a new transition that is not being "caught" by my listener or better, how do I delay the JQM transition until everything is ready (promises would be nice to have here :-)
Thanks!