Fallback events for mouse based devices #2

coffeebite opened this Issue Oct 19, 2012 · 5 comments


None yet

4 participants


I would love to have automatic fallback events. At the moment, I have to define a dblclick event, as well as a doubletap event to make my application work in both touch and non-touch devices.


I agree that would make sense... I'll think about a solution


I currently apply the following snippet for nontouch devices.
You can do something similar for dblclick.

if (!Modernizr.touch) {
  $.event.special.tap = {
    setup: function(data, namespaces) {
      $(this).on('click', $.event.special.tap.handler );
    teardown: function(namespace) {
      $(this).off('click', $.event.special.tap.handler);
    handler: function(e) { 
      // set correct event type
      e.original = e.type;
      e.type = "tap";
      $.event.handle.apply( this, arguments ); 

@zawaideh Thanks.

e10jc commented Mar 19, 2013

i was getting $.event.handle was undefined. guess jquery switched to .dispatch during some version change. here's what worked for me in coffeescript:

if (!Modernizr.touch)
  $.event.special.tap =
    setup: (data, namespaces) -> $(@).on('click', $.event.special.tap.handler)
    teardown: (namespace) -> $(@).off('click', $.event.special.tap.handler)
    handler: (e) ->
      e.original = e.type
      e.type = "tap"
      $.event.dispatch.apply(@, arguments)

Yes that works and is described here: http://learn.jquery.com/events/event-extensions/

if somebody writes a proper module for it, I'd add it to toe as an addon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment