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.

66 lines
1.8 KiB

8 years ago
  1. /**
  2. * Register a touch event, taking place before a gesture
  3. * @param {Hammer} hammer A hammer instance
  4. * @param {function} callback Callback, called as callback(event)
  5. */
  6. exports.onTouch = function (hammer, callback) {
  7. callback.inputHandler = function (event) {
  8. if (event.isFirst) {
  9. callback(event);
  10. }
  11. };
  12. hammer.on('hammer.input', callback.inputHandler);
  13. };
  14. /**
  15. * Register a release event, taking place after a gesture
  16. * @param {Hammer} hammer A hammer instance
  17. * @param {function} callback Callback, called as callback(event)
  18. */
  19. exports.onRelease = function (hammer, callback) {
  20. callback.inputHandler = function (event) {
  21. if (event.isFinal) {
  22. callback(event);
  23. }
  24. };
  25. return hammer.on('hammer.input', callback.inputHandler);
  26. };
  27. /**
  28. * Unregister a touch event, taking place before a gesture
  29. * @param {Hammer} hammer A hammer instance
  30. * @param {function} callback Callback, called as callback(event)
  31. */
  32. exports.offTouch = function (hammer, callback) {
  33. hammer.off('hammer.input', callback.inputHandler);
  34. };
  35. /**
  36. * Unregister a release event, taking place before a gesture
  37. * @param {Hammer} hammer A hammer instance
  38. * @param {function} callback Callback, called as callback(event)
  39. */
  40. exports.offRelease = exports.offTouch;
  41. /**
  42. * Hack the PinchRecognizer such that it doesn't prevent default behavior
  43. * for vertical panning.
  44. *
  45. * Yeah ... this is quite a hack ... see https://github.com/hammerjs/hammer.js/issues/932
  46. *
  47. * @param {Hammer.Pinch} pinchRecognizer
  48. * @return {Hammer.Pinch} returns the pinchRecognizer
  49. */
  50. exports.disablePreventDefaultVertically = function (pinchRecognizer) {
  51. var TOUCH_ACTION_PAN_Y = 'pan-y';
  52. pinchRecognizer.getTouchAction = function() {
  53. // default method returns [TOUCH_ACTION_NONE]
  54. return [TOUCH_ACTION_PAN_Y];
  55. };
  56. return pinchRecognizer;
  57. };