a zip code crypto-currency system good for red ONLY

item-reorder-gesture.js 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. (function (factory) {
  2. if (typeof module === "object" && typeof module.exports === "object") {
  3. var v = factory(require, exports);
  4. if (v !== undefined) module.exports = v;
  5. }
  6. else if (typeof define === "function" && define.amd) {
  7. define(["require", "exports", "./item-reorder-util", "../../util/dom", "../../gestures/ui-event-manager"], factory);
  8. }
  9. })(function (require, exports) {
  10. "use strict";
  11. Object.defineProperty(exports, "__esModule", { value: true });
  12. var item_reorder_util_1 = require("./item-reorder-util");
  13. var dom_1 = require("../../util/dom");
  14. var ui_event_manager_1 = require("../../gestures/ui-event-manager");
  15. /**
  16. * @hidden
  17. */
  18. var ItemReorderGesture = (function () {
  19. function ItemReorderGesture(plt, reorderList) {
  20. this.plt = plt;
  21. this.reorderList = reorderList;
  22. this.selectedItemEle = null;
  23. this.events = new ui_event_manager_1.UIEventManager(plt);
  24. this.events.pointerEvents({
  25. element: this.reorderList.getNativeElement(),
  26. pointerDown: this.onDragStart.bind(this),
  27. pointerMove: this.onDragMove.bind(this),
  28. pointerUp: this.onDragEnd.bind(this),
  29. zone: false
  30. });
  31. }
  32. ItemReorderGesture.prototype.onDragStart = function (ev) {
  33. if (this.selectedItemEle) {
  34. return false;
  35. }
  36. var reorderElement = ev.target;
  37. if (reorderElement.nodeName !== 'ION-REORDER') {
  38. return false;
  39. }
  40. var reorderMark = reorderElement['$ionComponent'];
  41. if (!reorderMark) {
  42. console.error('ion-reorder does not contain $ionComponent');
  43. return false;
  44. }
  45. this.reorderList._reorderPrepare();
  46. var item = reorderMark.getReorderNode();
  47. if (!item) {
  48. console.error('reorder node not found');
  49. return false;
  50. }
  51. ev.preventDefault();
  52. // Preparing state
  53. this.selectedItemEle = item;
  54. this.selectedItemHeight = item.offsetHeight;
  55. this.lastYcoord = -100;
  56. this.lastToIndex = item_reorder_util_1.indexForItem(item);
  57. this.windowHeight = this.plt.height() - AUTO_SCROLL_MARGIN;
  58. this.lastScrollPosition = this.reorderList._scrollContent(0);
  59. this.offset = dom_1.pointerCoord(ev);
  60. this.offset.y += this.lastScrollPosition;
  61. item.classList.add(ITEM_REORDER_ACTIVE);
  62. this.reorderList._reorderStart();
  63. return true;
  64. };
  65. ItemReorderGesture.prototype.onDragMove = function (ev) {
  66. var selectedItem = this.selectedItemEle;
  67. if (!selectedItem) {
  68. return;
  69. }
  70. ev.preventDefault();
  71. // Get coordinate
  72. var coord = dom_1.pointerCoord(ev);
  73. var posY = coord.y;
  74. // Scroll if we reach the scroll margins
  75. var scrollPosition = this.scroll(posY);
  76. // Only perform hit test if we moved at least 30px from previous position
  77. if (Math.abs(posY - this.lastYcoord) > 30) {
  78. var overItem = this.itemForCoord(coord);
  79. if (overItem) {
  80. var toIndex = item_reorder_util_1.indexForItem(overItem);
  81. if (toIndex !== undefined && (toIndex !== this.lastToIndex || this.emptyZone)) {
  82. var fromIndex = item_reorder_util_1.indexForItem(selectedItem);
  83. this.lastToIndex = toIndex;
  84. this.lastYcoord = posY;
  85. this.emptyZone = false;
  86. this.reorderList._reorderMove(fromIndex, toIndex, this.selectedItemHeight);
  87. }
  88. }
  89. else {
  90. this.emptyZone = true;
  91. }
  92. }
  93. // Update selected item position
  94. var ydiff = Math.round(posY - this.offset.y + scrollPosition);
  95. selectedItem.style[this.plt.Css.transform] = "translateY(" + ydiff + "px)";
  96. };
  97. ItemReorderGesture.prototype.onDragEnd = function (ev) {
  98. var _this = this;
  99. var selectedItem = this.selectedItemEle;
  100. if (!selectedItem) {
  101. return;
  102. }
  103. if (ev) {
  104. ev.preventDefault();
  105. ev.stopPropagation();
  106. }
  107. var toIndex = this.lastToIndex;
  108. var fromIndex = item_reorder_util_1.indexForItem(selectedItem);
  109. var reorderInactive = function () {
  110. _this.selectedItemEle.style.transition = '';
  111. _this.selectedItemEle.classList.remove(ITEM_REORDER_ACTIVE);
  112. _this.selectedItemEle = null;
  113. };
  114. if (toIndex === fromIndex) {
  115. selectedItem.style.transition = 'transform 200ms ease-in-out';
  116. setTimeout(reorderInactive, 200);
  117. }
  118. else {
  119. reorderInactive();
  120. }
  121. this.reorderList._reorderEmit(fromIndex, toIndex);
  122. };
  123. ItemReorderGesture.prototype.itemForCoord = function (coord) {
  124. var sideOffset = this.reorderList._isStart === this.plt.isRTL ? -100 : 100;
  125. var x = this.offset.x + sideOffset;
  126. var y = coord.y;
  127. var element = this.plt.getElementFromPoint(x, y);
  128. return item_reorder_util_1.findReorderItem(element, this.reorderList.getNativeElement());
  129. };
  130. ItemReorderGesture.prototype.scroll = function (posY) {
  131. if (posY < AUTO_SCROLL_MARGIN) {
  132. this.lastScrollPosition = this.reorderList._scrollContent(-SCROLL_JUMP);
  133. }
  134. else if (posY > this.windowHeight) {
  135. this.lastScrollPosition = this.reorderList._scrollContent(SCROLL_JUMP);
  136. }
  137. return this.lastScrollPosition;
  138. };
  139. /**
  140. * @hidden
  141. */
  142. ItemReorderGesture.prototype.destroy = function () {
  143. this.onDragEnd(null);
  144. this.events.destroy();
  145. this.events = null;
  146. this.reorderList = null;
  147. };
  148. return ItemReorderGesture;
  149. }());
  150. exports.ItemReorderGesture = ItemReorderGesture;
  151. var AUTO_SCROLL_MARGIN = 60;
  152. var SCROLL_JUMP = 10;
  153. var ITEM_REORDER_ACTIVE = 'reorder-active';
  154. });
  155. //# sourceMappingURL=item-reorder-gesture.js.map