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.

68 lines
1.9 KiB

8 years ago
  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. *
  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. };