vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.8 KiB

  1. var Hammer = require('./module/hammer');
  2. /**
  3. * Register a touch event, taking place before a gesture
  4. * @param {Hammer} hammer A hammer instance
  5. * @param {function} callback Callback, called as callback(event)
  6. */
  7. exports.onTouch = function (hammer, callback) {
  8. callback.inputHandler = function (event) {
  9. if (event.isFirst && !isTouching) {
  10. callback(event);
  11. isTouching = true;
  12. setTimeout(function () {
  13. isTouching = false;
  14. }, 0);
  15. }
  16. };
  17. hammer.on('hammer.input', callback.inputHandler);
  18. };
  19. // isTouching is true while a touch action is being emitted
  20. // this is a hack to prevent `touch` from being fired twice
  21. var isTouching = false;
  22. /**
  23. * Register a release event, taking place after a gesture
  24. * @param {Hammer} hammer A hammer instance
  25. * @param {function} callback Callback, called as callback(event)
  26. */
  27. exports.onRelease = function (hammer, callback) {
  28. callback.inputHandler = function (event) {
  29. if (event.isFinal && !isReleasing) {
  30. callback(event);
  31. isReleasing = true;
  32. setTimeout(function () {
  33. isReleasing = false;
  34. }, 0);
  35. }
  36. };
  37. return hammer.on('hammer.input', callback.inputHandler);
  38. };
  39. // isReleasing is true while a release action is being emitted
  40. // this is a hack to prevent `release` from being fired twice
  41. var isReleasing = false;
  42. /**
  43. * Unregister a touch event, taking place before a gesture
  44. * @param {Hammer} hammer A hammer instance
  45. * @param {function} callback Callback, called as callback(event)
  46. */
  47. exports.offTouch = function (hammer, callback) {
  48. hammer.off('hammer.input', callback.inputHandler);
  49. };
  50. /**
  51. * Unregister a release event, taking place before a gesture
  52. * @param {Hammer} hammer A hammer instance
  53. * @param {function} callback Callback, called as callback(event)
  54. */
  55. exports.offRelease = exports.offTouch;