How to stop panel from opening under certain conditions
To whom it may concern,
I'm trying to stop a JQM1.3 panel from opening if a certain condition is met. So far I have an event that checks before the panel is open and check a global variable if it equals a condition should prevent the panel from opening. This is the what I have so far
JSFiddle Link.
HTML:
- <a data-role='button' onclick='openPanel();'>OPEN</a>
- <a data-role='button' onclick='closePanel();'>CLOSE</a>
- <div data-role="panel" class="rightPanel" data-theme='d' data-position="right" data-display="overlay" data-animate="false" data-swipe-close='false' data-dismissible='false'>
- <p>PANEL</p>
- </div>
JavaScript:
- $(document).on("pageshow", function(){
- $(document).on("panelbeforeopen", ".rightPanel", panelBeforeOpenEvent);
- });
- var stopPanelFromOpening = true;
- function panelBeforeOpenEvent(event){
- console.log("BEFORE PANEL OPEN:", event);
- if(stopPanelFromOpening){
- console.log("NEED TO STOP PANEL FROM OPENING");
- event.stopImmediatePropagation();
- event.stopPropagation();
- event.preventDefault();
- return false;
- }
- }
- function openPanel(){
- $(".rightPanel").panel("open");
- }
- function closePanel(){
- $(".rightPanel").panel("close");
- }
Does anyone know how to make this work? I can't find anything online.
Please and Thank you