My app has two panels as a master layout, so all the child pages will have those two panels. Now, I want to register swipe event for all my pages in the application so that a user will be able to access those two panel from anywhere. I have created this function here so that I can just call this to register from different places:
function registerSwipeEvents() {
//panel swipe from left and right for categories, favs.
$(document).on("swipeleft swiperight", '[data-role=page]', function (e) {
// We check if there is no open panel on the page because otherwise
// a swipe to close the left panel would also open the right panel.
// We do this by checking the data that the framework stores on the page element (panel: open).
if ($.mobile.activePage.jqmData("panel") !== "open") {
if (e.type === "swipeleft") {
$(".right-panel").panel("open");
} else if (e.type === "swiperight") {
$(".left-panel").panel("open");
}
}
});
}
I have tried calling this function from pageinit (runs script only once), pagebeforeshow and pageshow (always runs) like this:
$('#HomePage').on('pageshow', function () {
getFavouritesFromClient();
});
But the event doesn't work for all the pages when I go from one page to another for the second time! Maybe I am not using the events properly but the best one that has worked till now for the first round of navigation is pageshow.