some page
I would like to use a Panel in a jqm site for my Choose Language component. So that component will need to be present on every page. Here is the setup for a single-page pane
with inspiration from Gajotres and the way AppFramework handles panels I've made this. It works by copying defined panels to the active page, the panels are defined by id in right-panel and left-panel attributes for the page div:
$(document).on('pagebeforeshow', '[data-role="page"]', function(){
// remove unused tmp panels from DOM
$("#tmpRightPanel").remove();
$("#tmpLeftPanel").remove();
// Hide buttons by default (I'm using a static header and footer on every page too)
$("#openRightPanel").css("display", "none");
$("#openLeftPanel").css("display", "none");
// check if right-panel attribute is set on the page
if ($(this).attr("right-panel")) {
// if it is, it should append the defined right-panel to the page
$("#"+$(this).attr("right-panel")).clone().appendTo($(this));
// rename it to tmpRightPanel
$.mobile.activePage.find('#'+$(this).attr("right-panel")).attr("id", "tmpRightPanel");
// make it a panel
$.mobile.activePage.find('#tmpRightPanel').panel();
// make it visible (the original right panel is set to display: none)
$.mobile.activePage.find('#tmpRightPanel').css("display", "block");
// make the button to open the panel visible
$("#openRightPanel").css("display", "block");
}
// same as right-panel above
if ($(this).attr("left-panel")) {
$("#"+$(this).attr("left-panel")).clone().appendTo($(this));
$.mobile.activePage.find('#'+$(this).attr("left-panel")).attr("id", "tmpLeftPanel");
$.mobile.activePage.find('#tmpLeftPanel').panel();
$.mobile.activePage.find('#tmpLeftPanel').css("display","block");
$("#openLeftPanel").css("display", "block");
}
});
// make the open panel buttons clickable
$(document).on('click', '#openRightPanel', function(){
$.mobile.activePage.find('#tmpRightPanel').panel("open");
});
$(document).on('click', '#openLeftPanel', function(){
$.mobile.activePage.find('#tmpLeftPanel').panel("open");
});
Make a page like this:
some page
and place the panels somewhere outside a page, and hide them like this: