Solution slider change swipeleft events
Hello everyone,
I have found a "workaround" for the next situation, but i'm interested in hearing alternative solutions.
Context:
A jqm dashboard page which listens to the swipeleft event.
A jqm slider on the dashboard page.
Challenge:
When sliding the handler of the slider to the left....swipeleft is triggered and i'm gone off to the next page...
So, how to prevent swipeleft in this case from doing what is does? Of course, when swipingleft on the rest of the page this should work as normal.
Question:
I aspected to handle this by binding the swipeleft event to the slider and stop propagation...(so it would not bubble up to the dashboard div, where it could be catched and handled).
Swipe (left, right) cannot be bound to the slider (=<a></a> element)?
My solution:
This works for me:
Store a "changed" flag in the DOM when the change event on the slider is triggered.
I bind the swipeleft event to the dashboard. When the swipeleft is triggered, the swipeleft is only being executed when the "changed"-flag is set false.
(BTW: I know I could also use the stored events in the DOM to check if the event was fired.)
- $('#mySlider').live("change", function(event) {
$("#dashboard").data("hasSliderChanged", true);
});
$("#dashboard").live("swipeleft",function(event){
//was Change event fired first? If so, do nothing except resetting the flag.
if($("#dashboard").data("hasSliderChanged")){
//reset
$("#dashboard").data("hasSliderChanged", false);
}else{
$.mobile.changePage($("#nextPage"), "slide", false, true);
}
});
Hope to hear from you!
regards
EricB