UI for Zipcoin Blue

item-sliding-gesture.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. var __extends = (this && this.__extends) || (function () {
  2. var extendStatics = Object.setPrototypeOf ||
  3. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  5. return function (d, b) {
  6. extendStatics(d, b);
  7. function __() { this.constructor = d; }
  8. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9. };
  10. })();
  11. import { GESTURE_ITEM_SWIPE, GESTURE_PRIORITY_SLIDING_ITEM } from '../../gestures/gesture-controller';
  12. import { PanGesture } from '../../gestures/pan-gesture';
  13. import { pointerCoord } from '../../util/dom';
  14. /**
  15. * @hidden
  16. */
  17. var ItemSlidingGesture = (function (_super) {
  18. __extends(ItemSlidingGesture, _super);
  19. function ItemSlidingGesture(plt, list, gestureCtrl, domCtrl) {
  20. var _this = _super.call(this, plt, list.getNativeElement(), {
  21. maxAngle: 20,
  22. threshold: 5,
  23. zone: false,
  24. domController: domCtrl,
  25. gesture: gestureCtrl.createGesture({
  26. name: GESTURE_ITEM_SWIPE,
  27. priority: GESTURE_PRIORITY_SLIDING_ITEM,
  28. disableScroll: true
  29. })
  30. }) || this;
  31. _this.list = list;
  32. _this.preSelectedContainer = null;
  33. _this.selectedContainer = null;
  34. _this.openContainer = null;
  35. return _this;
  36. }
  37. ItemSlidingGesture.prototype.canStart = function (ev) {
  38. if (this.selectedContainer) {
  39. return false;
  40. }
  41. // Get swiped sliding container
  42. var container = getContainer(ev);
  43. if (!container) {
  44. this.closeOpened();
  45. return false;
  46. }
  47. // Close open container if it is not the selected one.
  48. if (container !== this.openContainer) {
  49. this.closeOpened();
  50. }
  51. var coord = pointerCoord(ev);
  52. this.preSelectedContainer = container;
  53. this.firstCoordX = coord.x;
  54. this.firstTimestamp = Date.now();
  55. return true;
  56. };
  57. ItemSlidingGesture.prototype.onDragStart = function (ev) {
  58. ev.preventDefault();
  59. var coord = pointerCoord(ev);
  60. this.selectedContainer = this.openContainer = this.preSelectedContainer;
  61. this.selectedContainer.startSliding(coord.x);
  62. };
  63. ItemSlidingGesture.prototype.onDragMove = function (ev) {
  64. ev.preventDefault();
  65. this.selectedContainer.moveSliding(pointerCoord(ev).x);
  66. };
  67. ItemSlidingGesture.prototype.onDragEnd = function (ev) {
  68. ev.preventDefault();
  69. var coordX = pointerCoord(ev).x;
  70. var deltaX = (coordX - this.firstCoordX);
  71. var deltaT = (Date.now() - this.firstTimestamp);
  72. this.selectedContainer.endSliding(deltaX / deltaT);
  73. this.selectedContainer = null;
  74. this.preSelectedContainer = null;
  75. };
  76. ItemSlidingGesture.prototype.notCaptured = function (ev) {
  77. if (!clickedOptionButton(ev)) {
  78. this.closeOpened();
  79. }
  80. };
  81. ItemSlidingGesture.prototype.closeOpened = function () {
  82. this.selectedContainer = null;
  83. if (this.openContainer) {
  84. this.openContainer.close();
  85. this.openContainer = null;
  86. return true;
  87. }
  88. return false;
  89. };
  90. ItemSlidingGesture.prototype.destroy = function () {
  91. _super.prototype.destroy.call(this);
  92. this.closeOpened();
  93. this.list = null;
  94. this.preSelectedContainer = null;
  95. this.selectedContainer = null;
  96. this.openContainer = null;
  97. };
  98. return ItemSlidingGesture;
  99. }(PanGesture));
  100. export { ItemSlidingGesture };
  101. function getContainer(ev) {
  102. var ele = ev.target.closest('ion-item-sliding');
  103. if (ele) {
  104. return ele['$ionComponent'];
  105. }
  106. return null;
  107. }
  108. function clickedOptionButton(ev) {
  109. var ele = ev.target.closest('ion-item-options>button');
  110. return !!ele;
  111. }
  112. //# sourceMappingURL=item-sliding-gesture.js.map