slide-edge-gesture.js 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { SlideGesture } from './slide-gesture';
  2. import { defaults } from '../util/util';
  3. import { pointerCoord } from '../util/dom';
  4. /**
  5. * @hidden
  6. */
  7. export class SlideEdgeGesture extends SlideGesture {
  8. constructor(plt, element, opts = {}) {
  9. defaults(opts, {
  10. edge: 'start',
  11. maxEdgeStart: 50
  12. });
  13. super(plt, element, opts);
  14. // Can check corners through use of eg 'left top'
  15. this.setEdges(opts.edge);
  16. this.maxEdgeStart = opts.maxEdgeStart;
  17. }
  18. setEdges(edges) {
  19. const isRTL = this.plt.isRTL;
  20. this.edges = edges.split(' ').map((value) => {
  21. switch (value) {
  22. case 'start': return isRTL ? 'right' : 'left';
  23. case 'end': return isRTL ? 'left' : 'right';
  24. default: return value;
  25. }
  26. });
  27. }
  28. canStart(ev) {
  29. const coord = pointerCoord(ev);
  30. this._d = this.getContainerDimensions();
  31. return this.edges.every(edge => this._checkEdge(edge, coord));
  32. }
  33. getContainerDimensions() {
  34. const plt = this.plt;
  35. return {
  36. left: 0,
  37. top: 0,
  38. width: plt.width(),
  39. height: plt.height()
  40. };
  41. }
  42. _checkEdge(edge, pos) {
  43. const data = this._d;
  44. const maxEdgeStart = this.maxEdgeStart;
  45. switch (edge) {
  46. case 'left': return pos.x <= data.left + maxEdgeStart;
  47. case 'right': return pos.x >= data.width - maxEdgeStart;
  48. case 'top': return pos.y <= data.top + maxEdgeStart;
  49. case 'bottom': return pos.y >= data.height - maxEdgeStart;
  50. }
  51. return false;
  52. }
  53. }
  54. //# sourceMappingURL=slide-edge-gesture.js.map