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.9 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. * @returns {*}
  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. *
  46. * Yeah ... this is quite a hack ... see https://github.com/hammerjs/hammer.js/issues/932
  47. *
  48. * @param {Hammer.Pinch} pinchRecognizer
  49. * @return {Hammer.Pinch} returns the pinchRecognizer
  50. */
  51. exports.disablePreventDefaultVertically = function (pinchRecognizer) {
  52. var TOUCH_ACTION_PAN_Y = 'pan-y';
  53. pinchRecognizer.getTouchAction = function() {
  54. // default method returns [TOUCH_ACTION_NONE]
  55. return [TOUCH_ACTION_PAN_Y];
  56. };
  57. return pinchRecognizer;
  58. };