Skip to Content | Skip to Navigation


dojo.touch

Project owner:Evan Huang
since:V.1.7

Introduction

This module provides an unified set of touch events - “press | move | release | cancel”, which can run well across a wide range of devices(including desktops).

The rationale is very simple - “press | move | release | cancel” are mapped to:

  • “touchstart | touchmove | touchend | touchcancel” on touch devices(W3C Touch Events Specification)
  • “mousedown | mousemove | mouseup | mouseleave” on desktops.

So by using dojo/touch, we don’t need to worry about appropriate native events when switching running platforms.

Usages

dojo/touch is based on dojo/on and provides “press | move | release | cancel” 4 event handles. Following below are detail usages:

  1. Used with dojo/on
<script type="text/javascript">
    define(["dojo/on", "dojo/touch"], function(on, touch){
      on(node, touch.press, function(e){});
      on(node, touch.move, function(e){});
      on(node, touch.release, function(e){});
      on(node, touch.cancel, function(e){});
    }
</style>
  1. Used with dojo/touch directly
<script type="text/javascript">
    define(["dojo/touch"], function(touch){
      touch.press(node, function(e){});
      touch.move(node, function(e){});
      touch.release(node, function(e){});
      touch.cancel(node, function(e){});
    }
</style>
  1. Or used with the traditional dojo/connect
<script type="text/javascript">
      dojo.connect(node, dojo.touch.press, function(e){});
      dojo.connect(node, dojo.touch.move, function(e){});
      dojo.connect(node, dojo.touch.release, function(e){});
      dojo.connect(node, dojo.touch.cancel, function(e){});
</style>

Relationship with dojo/gesture

dojo/touch is the underneath basis for dojox/gesture

Known Issues

If a device (like blackberry phones or some high end desktop computers) has both mouse and touch, dojo.touch will only monitor touch events, ideally it should be monitoring both. Please also See #13048.