menu-gestures.js 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { GESTURE_MENU_SWIPE, GESTURE_PRIORITY_MENU_SWIPE } from '../../gestures/gesture-controller';
  2. import { SlideEdgeGesture } from '../../gestures/slide-edge-gesture';
  3. /**
  4. * Gesture attached to the content which the menu is assigned to
  5. */
  6. export class MenuContentGesture extends SlideEdgeGesture {
  7. constructor(plt, menu, gestureCtrl, domCtrl) {
  8. super(plt, plt.doc().body, {
  9. direction: 'x',
  10. edge: menu.side,
  11. threshold: 5,
  12. maxEdgeStart: menu.maxEdgeStart || 50,
  13. zone: false,
  14. passive: true,
  15. domController: domCtrl,
  16. gesture: gestureCtrl.createGesture({
  17. name: GESTURE_MENU_SWIPE,
  18. priority: GESTURE_PRIORITY_MENU_SWIPE,
  19. disableScroll: true
  20. })
  21. });
  22. this.menu = menu;
  23. }
  24. canStart(ev) {
  25. const menu = this.menu;
  26. if (!menu.canSwipe()) {
  27. return false;
  28. }
  29. if (menu.isOpen) {
  30. return true;
  31. }
  32. else if (menu.getMenuController().getOpen()) {
  33. return false;
  34. }
  35. return super.canStart(ev);
  36. }
  37. // Set CSS, then wait one frame for it to apply before sliding starts
  38. onSlideBeforeStart() {
  39. (void 0) /* console.debug */;
  40. this.menu._swipeBeforeStart();
  41. }
  42. onSlideStart() {
  43. (void 0) /* console.debug */;
  44. this.menu._swipeStart();
  45. }
  46. onSlide(slide) {
  47. const z = (this.menu.isRightSide !== this.plt.isRTL ? slide.min : slide.max);
  48. const stepValue = (slide.distance / z);
  49. this.menu._swipeProgress(stepValue);
  50. }
  51. onSlideEnd(slide) {
  52. let z = (this.menu.isRightSide !== this.plt.isRTL ? slide.min : slide.max);
  53. const currentStepValue = (slide.distance / z);
  54. const velocity = slide.velocity;
  55. z = Math.abs(z * 0.5);
  56. const shouldCompleteRight = (velocity >= 0)
  57. && (velocity > 0.2 || slide.delta > z);
  58. const shouldCompleteLeft = (velocity <= 0)
  59. && (velocity < -0.2 || slide.delta < -z);
  60. (void 0) /* console.debug */;
  61. this.menu._swipeEnd(shouldCompleteLeft, shouldCompleteRight, currentStepValue, velocity);
  62. }
  63. getElementStartPos(slide) {
  64. const menu = this.menu;
  65. if (menu.isRightSide !== this.plt.isRTL) {
  66. return menu.isOpen ? slide.min : slide.max;
  67. }
  68. // left menu
  69. return menu.isOpen ? slide.max : slide.min;
  70. }
  71. getSlideBoundaries() {
  72. const menu = this.menu;
  73. if (menu.isRightSide !== this.plt.isRTL) {
  74. return {
  75. min: -menu.width(),
  76. max: 0
  77. };
  78. }
  79. // left menu
  80. return {
  81. min: 0,
  82. max: menu.width()
  83. };
  84. }
  85. }
  86. //# sourceMappingURL=menu-gestures.js.map