logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git

swipe_click.js (2613B)


  1. import GestureService from '../../services/gesture_service/gesture_service'
  2. /**
  3. * props:
  4. * direction: a vector that indicates the direction of the intended swipe
  5. * threshold: the minimum distance in pixels the swipe has moved on `direction'
  6. * for swipe-finished() to have a non-zero sign
  7. * disableClickThreshold: the minimum distance in pixels for the swipe to
  8. * not trigger a click
  9. * perpendicularTolerance: see gesture_service
  10. *
  11. * Events:
  12. * preview-requested(offsets)
  13. * Emitted when the pointer has moved.
  14. * offsets: the offsets from the start of the swipe to the current cursor position
  15. *
  16. * swipe-canceled()
  17. * Emitted when the swipe has been canceled due to a pointercancel event.
  18. *
  19. * swipe-finished(sign: 0|-1|1)
  20. * Emitted when the swipe has finished.
  21. * sign: if the swipe does not meet the threshold, 0
  22. * if the swipe meets the threshold in the positive direction, 1
  23. * if the swipe meets the threshold in the negative direction, -1
  24. *
  25. * swipeless-clicked()
  26. * Emitted when there is a click without swipe.
  27. * This and swipe-finished() cannot be emitted for the same pointerup event.
  28. */
  29. const SwipeClick = {
  30. props: {
  31. direction: {
  32. type: Array
  33. },
  34. threshold: {
  35. type: Function,
  36. default: () => 30
  37. },
  38. disableClickThreshold: {
  39. type: Function,
  40. default: () => 1
  41. },
  42. perpendicularTolerance: {
  43. type: Number,
  44. default: 1.0
  45. }
  46. },
  47. methods: {
  48. handlePointerDown (event) {
  49. this.$gesture.start(event)
  50. },
  51. handlePointerMove (event) {
  52. this.$gesture.move(event)
  53. },
  54. handlePointerUp (event) {
  55. this.$gesture.end(event)
  56. },
  57. handlePointerCancel (event) {
  58. this.$gesture.cancel(event)
  59. },
  60. handleNativeClick (event) {
  61. this.$gesture.click(event)
  62. },
  63. preview (offsets) {
  64. this.$emit('preview-requested', offsets)
  65. },
  66. end (sign) {
  67. this.$emit('swipe-finished', sign)
  68. },
  69. click () {
  70. this.$emit('swipeless-clicked')
  71. },
  72. cancel () {
  73. this.$emit('swipe-canceled')
  74. }
  75. },
  76. created () {
  77. this.$gesture = new GestureService.SwipeAndClickGesture({
  78. direction: this.direction,
  79. threshold: this.threshold,
  80. disableClickThreshold: this.disableClickThreshold,
  81. perpendicularTolerance: this.perpendicularTolerance,
  82. swipePreviewCallback: this.preview,
  83. swipeEndCallback: this.end,
  84. swipeCancelCallback: this.cancel,
  85. swipelessClickCallback: this.click
  86. })
  87. }
  88. }
  89. export default SwipeClick