mui.gestures.longtap.js 823 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /**
  2. * mui gesture longtap
  3. * @param {type} $
  4. * @param {type} name
  5. * @returns {undefined}
  6. */
  7. (function($, name) {
  8. var timer;
  9. var handle = function(event, touch) {
  10. var session = $.gestures.session;
  11. var options = this.options;
  12. switch (event.type) {
  13. case $.EVENT_START:
  14. clearTimeout(timer);
  15. timer = setTimeout(function() {
  16. $.trigger(session.target, name, touch);
  17. }, options.holdTimeout);
  18. break;
  19. case $.EVENT_MOVE:
  20. if (touch.distance > options.holdThreshold) {
  21. clearTimeout(timer);
  22. }
  23. break;
  24. case $.EVENT_END:
  25. case $.EVENT_CANCEL:
  26. clearTimeout(timer);
  27. break;
  28. }
  29. };
  30. /**
  31. * mui gesture longtap
  32. */
  33. $.addGesture({
  34. name: name,
  35. index: 10,
  36. handle: handle,
  37. options: {
  38. fingers: 1,
  39. holdTimeout: 500,
  40. holdThreshold: 2
  41. }
  42. });
  43. })(mui, 'longtap');