mui.gestures.tap.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * mui gesture tap and doubleTap
  3. * @param {type} $
  4. * @param {type} name
  5. * @returns {undefined}
  6. */
  7. (function($, name) {
  8. var lastTarget;
  9. var lastTapTime;
  10. var handle = function(event, touch) {
  11. var session = $.gestures.session;
  12. var options = this.options;
  13. switch (event.type) {
  14. case $.EVENT_END:
  15. if (!touch.isFinal) {
  16. return;
  17. }
  18. var target = session.target;
  19. if (!target || (target.disabled || (target.classList && target.classList.contains($.className('disabled'))))) {
  20. return;
  21. }
  22. if (touch.distance < options.tapMaxDistance && touch.deltaTime < options.tapMaxTime) {
  23. if ($.options.gestureConfig.doubletap && lastTarget && (lastTarget === target)) { //same target
  24. if (lastTapTime && (touch.timestamp - lastTapTime) < options.tapMaxInterval) {
  25. $.trigger(target, 'doubletap', touch);
  26. lastTapTime = $.now();
  27. lastTarget = target;
  28. return;
  29. }
  30. }
  31. $.trigger(target, name, touch);
  32. lastTapTime = $.now();
  33. lastTarget = target;
  34. }
  35. break;
  36. }
  37. };
  38. /**
  39. * mui gesture tap
  40. */
  41. $.addGesture({
  42. name: name,
  43. index: 30,
  44. handle: handle,
  45. options: {
  46. fingers: 1,
  47. tapMaxInterval: 300,
  48. tapMaxDistance: 5,
  49. tapMaxTime: 250
  50. }
  51. });
  52. })(mui, 'tap');