Skip to content

Instantly share code, notes, and snippets.

@patrixd
Last active March 27, 2016 22:04
Show Gist options
  • Save patrixd/7083503 to your computer and use it in GitHub Desktop.
Save patrixd/7083503 to your computer and use it in GitHub Desktop.
If you don't use jquery mobile because you think that you don't need all the features, I usually add plugins like the next one. In this case is doubleclick for touchable devices
// Example: this.$stage.doubleTab.on(this.$stage, this.onContainerClicked, 200, "touchstart", this.options.delegatedTagSel);
// this.$stage.doubleTab.off(this.$stage, "touchstart");
$.fn.doubleTab = (function() {
var timer, data, eventType = "touchend";
var timeout = 600;
var $itemClicked = null;
var onDoubleClickSTART = function(e) {
data = e.data;
data.$container.off(data.eventType, onDoubleClickSTART);
data.$container.off(data.eventType, onDoubleClickEND);
data.$container.off("dblclick", data.delegateSelector, data.callback);
if(data.delegateSelector) {
var eProperties = $.getEventMainProperties(e);
data.$itemClicked = eProperties.$target.closest(data.delegateSelector);
}
timer = setTimeout(function() { onDoubleClickReset(); }, data.timeout);
data.$container.on(data.eventType, data, onDoubleClickEND);
};
var onDoubleClickEND = function(e) {
data = e.data;
clearTimeout(timer);
data.$container.off(data.eventType, onDoubleClickEND);
if(data.callback)
data.callback(e);
onDoubleClickReset();
};
var onDoubleClickReset = function () {
data.$container.off(data.eventType, onDoubleClickEND);
data.$container.on(data.eventType, data, onDoubleClickSTART);
};
return {
on: function($container, targetSelector, callbackFN) {
if (Modernizr.touch)
$container.on(eventType, {
$container: $container,
callback: callbackFN || callback,
eventType: eventType,
timeout: timeout,
delegateSelector: targetSelector
}, onDoubleClickSTART);
$container.on("dblclick", targetSelector, callbackFN);
},
off: function($container, targetSelector, callbackFN) {
if (Modernizr.touch) {
clearTimeout(timer);
$container.off(eventType, onDoubleClickSTART);
$container.off(eventType, onDoubleClickEND);
}
$container.off("dblclick", targetSelector, callbackFN);
}
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment