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.

65 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) {
  10. callback(event);
  11. }
  12. };
  13. hammer.on('hammer.input', callback.inputHandler);
  14. };
  15. /**
  16. * Register a release event, taking place after a gesture
  17. * @param {Hammer} hammer A hammer instance
  18. * @param {function} callback Callback, called as callback(event)
  19. */
  20. exports.onRelease = function (hammer, callback) {
  21. callback.inputHandler = function (event) {
  22. if (event.isFinal) {
  23. callback(event);
  24. }
  25. };
  26. return hammer.on('hammer.input', callback.inputHandler);
  27. };
  28. /**
  29. * Unregister a touch event, taking place before a gesture
  30. * @param {Hammer} hammer A hammer instance
  31. * @param {function} callback Callback, called as callback(event)
  32. */
  33. exports.offTouch = function (hammer, callback) {
  34. hammer.off('hammer.input', callback.inputHandler);
  35. };
  36. /**
  37. * Unregister a release event, taking place before a gesture
  38. * @param {Hammer} hammer A hammer instance
  39. * @param {function} callback Callback, called as callback(event)
  40. */
  41. exports.offRelease = exports.offTouch;
  42. /**
  43. * Hack the PinchRecognizer such that it doesn't prevent default behavior
  44. * for vertical panning.
  45. * @param {Hammer.Pinch} pinchRecognizer
  46. * @return {Hammer.Pinch} returns the pinchRecognizer
  47. */
  48. exports.disablePreventDefaultVertically = function (pinchRecognizer) {
  49. var TOUCH_ACTION_PAN_Y = 'pan-y';
  50. pinchRecognizer.getTouchAction = function() {
  51. // default method returns [TOUCH_ACTION_NONE]
  52. return [TOUCH_ACTION_PAN_Y];
  53. };
  54. return pinchRecognizer;
  55. };