a zip code crypto-currency system good for red ONLY

item-reorder.js 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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", "@angular/core", "../content/content", "../../platform/dom-controller", "../../util/util", "./item-reorder-gesture", "../../platform/platform"], factory);
  8. }
  9. })(function (require, exports) {
  10. "use strict";
  11. Object.defineProperty(exports, "__esModule", { value: true });
  12. var core_1 = require("@angular/core");
  13. var content_1 = require("../content/content");
  14. var dom_controller_1 = require("../../platform/dom-controller");
  15. var util_1 = require("../../util/util");
  16. var item_reorder_gesture_1 = require("./item-reorder-gesture");
  17. var platform_1 = require("../../platform/platform");
  18. var ReorderIndexes = (function () {
  19. function ReorderIndexes(from, to) {
  20. this.from = from;
  21. this.to = to;
  22. }
  23. ReorderIndexes.prototype.applyTo = function (array) {
  24. util_1.reorderArray(array, this);
  25. };
  26. return ReorderIndexes;
  27. }());
  28. exports.ReorderIndexes = ReorderIndexes;
  29. /**
  30. * @name ItemReorder
  31. * @description
  32. * Item reorder adds the ability to change an item's order in a group.
  33. * It can be used within an `ion-list` or `ion-item-group` to provide a
  34. * visual drag and drop interface.
  35. *
  36. * ## Grouping Items
  37. *
  38. * All reorderable items must be grouped in the same element. If an item
  39. * should not be reordered, it shouldn't be included in this group. For
  40. * example, the following code works because the items are grouped in the
  41. * `<ion-list>`:
  42. *
  43. * ```html
  44. * <ion-list reorder="true">
  45. * <ion-item *ngFor="let item of items">{% raw %}{{ item }}{% endraw %}</ion-item>
  46. * </ion-list>
  47. * ```
  48. *
  49. * However, the below list includes a header that shouldn't be reordered:
  50. *
  51. * ```html
  52. * <ion-list reorder="true">
  53. * <ion-list-header>Header</ion-list-header>
  54. * <ion-item *ngFor="let item of items">{% raw %}{{ item }}{% endraw %}</ion-item>
  55. * </ion-list>
  56. * ```
  57. *
  58. * In order to mix different sets of items, `ion-item-group` should be used to
  59. * group the reorderable items:
  60. *
  61. * ```html
  62. * <ion-list>
  63. * <ion-list-header>Header</ion-list-header>
  64. * <ion-item-group reorder="true">
  65. * <ion-item *ngFor="let item of items">{% raw %}{{ item }}{% endraw %}</ion-item>
  66. * </ion-item-group>
  67. * </ion-list>
  68. * ```
  69. *
  70. * It's important to note that in this example, the `[reorder]` directive is applied to
  71. * the `<ion-item-group>` instead of the `<ion-list>`. This way makes it possible to
  72. * mix items that should and shouldn't be reordered.
  73. *
  74. *
  75. * ## Implementing the Reorder Function
  76. *
  77. * When the item is dragged and dropped into the new position, the `(ionItemReorder)` event is
  78. * emitted. This event provides the initial index (from) and the new index (to) of the reordered
  79. * item. For example, if the first item is dragged to the fifth position, the event will emit
  80. * `{from: 0, to: 4}`. Note that the index starts at zero.
  81. *
  82. * A function should be called when the event is emitted that handles the reordering of the items.
  83. * See [usage](#usage) below for some examples.
  84. *
  85. *
  86. * @usage
  87. *
  88. * ```html
  89. * <ion-list>
  90. * <ion-list-header>Header</ion-list-header>
  91. * <ion-item-group reorder="true" (ionItemReorder)="reorderItems($event)">
  92. * <ion-item *ngFor="let item of items">{% raw %}{{ item }}{% endraw %}</ion-item>
  93. * </ion-item-group>
  94. * </ion-list>
  95. * ```
  96. *
  97. * ```ts
  98. * class MyComponent {
  99. * items = [];
  100. *
  101. * constructor() {
  102. * for (let x = 0; x < 5; x++) {
  103. * this.items.push(x);
  104. * }
  105. * }
  106. *
  107. * reorderItems(indexes) {
  108. * let element = this.items[indexes.from];
  109. * this.items.splice(indexes.from, 1);
  110. * this.items.splice(indexes.to, 0, element);
  111. * }
  112. * }
  113. * ```
  114. *
  115. * Ionic also provides a helper function called `reorderArray` to
  116. * reorder the array of items. This can be used instead:
  117. *
  118. * ```ts
  119. * import { reorderArray } from 'ionic-angular';
  120. *
  121. * class MyComponent {
  122. * items = [];
  123. *
  124. * constructor() {
  125. * for (let x = 0; x < 5; x++) {
  126. * this.items.push(x);
  127. * }
  128. * }
  129. *
  130. * reorderItems(indexes) {
  131. * this.items = reorderArray(this.items, indexes);
  132. * }
  133. * }
  134. * ```
  135. * Alternatevely you can execute helper function inside template:
  136. *
  137. * ```html
  138. * <ion-list>
  139. * <ion-list-header>Header</ion-list-header>
  140. * <ion-item-group reorder="true" (ionItemReorder)="$event.applyTo(items)">
  141. * <ion-item *ngFor="let item of items">{% raw %}{{ item }}{% endraw %}</ion-item>
  142. * </ion-item-group>
  143. * </ion-list>
  144. * ```
  145. *
  146. * @demo /docs/demos/src/item-reorder/
  147. * @see {@link /docs/components#lists List Component Docs}
  148. * @see {@link ../../list/List List API Docs}
  149. * @see {@link ../Item Item API Docs}
  150. */
  151. var ItemReorder = (function () {
  152. function ItemReorder(_plt, _dom, elementRef, _rendered, _zone, _content) {
  153. this._plt = _plt;
  154. this._dom = _dom;
  155. this._rendered = _rendered;
  156. this._zone = _zone;
  157. this._content = _content;
  158. this._enableReorder = false;
  159. this._visibleReorder = false;
  160. this._isStart = false;
  161. this._lastToIndex = -1;
  162. /**
  163. * @output {object} Emitted when the item is reordered. Emits an object
  164. * with `from` and `to` properties.
  165. */
  166. this.ionItemReorder = new core_1.EventEmitter();
  167. this._element = elementRef.nativeElement;
  168. }
  169. Object.defineProperty(ItemReorder.prototype, "side", {
  170. /**
  171. * @input {string} Which side of the view the ion-reorder should be placed. Default `"end"`.
  172. */
  173. set: function (side) {
  174. this._isStart = side === 'start';
  175. },
  176. enumerable: true,
  177. configurable: true
  178. });
  179. /**
  180. * @hidden
  181. */
  182. ItemReorder.prototype.ngOnDestroy = function () {
  183. this._element = null;
  184. this._reorderGesture && this._reorderGesture.destroy();
  185. };
  186. Object.defineProperty(ItemReorder.prototype, "reorder", {
  187. /**
  188. * @hidden
  189. */
  190. get: function () {
  191. return this._enableReorder;
  192. },
  193. set: function (val) {
  194. var _this = this;
  195. var enabled = util_1.isTrueProperty(val);
  196. if (!enabled && this._reorderGesture) {
  197. this._reorderGesture.destroy();
  198. this._reorderGesture = null;
  199. this._visibleReorder = false;
  200. setTimeout(function () { return _this._enableReorder = false; }, 400);
  201. }
  202. else if (enabled && !this._reorderGesture) {
  203. (void 0) /* console.debug */;
  204. this._reorderGesture = new item_reorder_gesture_1.ItemReorderGesture(this._plt, this);
  205. this._enableReorder = true;
  206. this._dom.write(function () {
  207. _this._zone.run(function () {
  208. _this._visibleReorder = true;
  209. });
  210. }, 16);
  211. }
  212. },
  213. enumerable: true,
  214. configurable: true
  215. });
  216. ItemReorder.prototype._reorderPrepare = function () {
  217. var ele = this._element;
  218. var children = ele.children;
  219. for (var i = 0, ilen = children.length; i < ilen; i++) {
  220. var child = children[i];
  221. child.$ionIndex = i;
  222. child.$ionReorderList = ele;
  223. }
  224. };
  225. ItemReorder.prototype._reorderStart = function () {
  226. this.setElementClass('reorder-list-active', true);
  227. };
  228. ItemReorder.prototype._reorderEmit = function (fromIndex, toIndex) {
  229. var _this = this;
  230. this._reorderReset();
  231. if (fromIndex !== toIndex) {
  232. this._zone.run(function () {
  233. var indexes = new ReorderIndexes(fromIndex, toIndex);
  234. _this.ionItemReorder.emit(indexes);
  235. });
  236. }
  237. };
  238. ItemReorder.prototype._scrollContent = function (scroll) {
  239. var scrollTop = this._content.scrollTop + scroll;
  240. if (scroll !== 0) {
  241. this._content.scrollTo(0, scrollTop, 0);
  242. }
  243. return scrollTop;
  244. };
  245. ItemReorder.prototype._reorderReset = function () {
  246. var children = this._element.children;
  247. var len = children.length;
  248. this.setElementClass('reorder-list-active', false);
  249. var transform = this._plt.Css.transform;
  250. for (var i = 0; i < len; i++) {
  251. children[i].style[transform] = '';
  252. }
  253. this._lastToIndex = -1;
  254. };
  255. ItemReorder.prototype._reorderMove = function (fromIndex, toIndex, itemHeight) {
  256. if (this._lastToIndex === -1) {
  257. this._lastToIndex = fromIndex;
  258. }
  259. var lastToIndex = this._lastToIndex;
  260. this._lastToIndex = toIndex;
  261. // TODO: I think both loops can be merged into a single one
  262. // but I had no luck last time I tried
  263. /********* DOM READ ********** */
  264. var children = this._element.children;
  265. /********* DOM WRITE ********* */
  266. var transform = this._plt.Css.transform;
  267. if (toIndex >= lastToIndex) {
  268. for (var i = lastToIndex; i <= toIndex; i++) {
  269. if (i !== fromIndex) {
  270. children[i].style[transform] = (i > fromIndex)
  271. ? "translateY(" + -itemHeight + "px)" : '';
  272. }
  273. }
  274. }
  275. if (toIndex <= lastToIndex) {
  276. for (var i = toIndex; i <= lastToIndex; i++) {
  277. if (i !== fromIndex) {
  278. children[i].style[transform] = (i < fromIndex)
  279. ? "translateY(" + itemHeight + "px)" : '';
  280. }
  281. }
  282. }
  283. };
  284. /**
  285. * @hidden
  286. */
  287. ItemReorder.prototype.setElementClass = function (classname, add) {
  288. this._rendered.setElementClass(this._element, classname, add);
  289. };
  290. /**
  291. * @hidden
  292. */
  293. ItemReorder.prototype.getNativeElement = function () {
  294. return this._element;
  295. };
  296. ItemReorder.decorators = [
  297. { type: core_1.Directive, args: [{
  298. selector: 'ion-list[reorder],ion-item-group[reorder]',
  299. host: {
  300. '[class.reorder-enabled]': '_enableReorder',
  301. '[class.reorder-visible]': '_visibleReorder',
  302. '[class.reorder-side-start]': '_isStart'
  303. }
  304. },] },
  305. ];
  306. /** @nocollapse */
  307. ItemReorder.ctorParameters = function () { return [
  308. { type: platform_1.Platform, },
  309. { type: dom_controller_1.DomController, },
  310. { type: core_1.ElementRef, },
  311. { type: core_1.Renderer, },
  312. { type: core_1.NgZone, },
  313. { type: content_1.Content, decorators: [{ type: core_1.Optional },] },
  314. ]; };
  315. ItemReorder.propDecorators = {
  316. 'ionItemReorder': [{ type: core_1.Output },],
  317. 'side': [{ type: core_1.Input, args: ['side',] },],
  318. 'reorder': [{ type: core_1.Input },],
  319. };
  320. return ItemReorder;
  321. }());
  322. exports.ItemReorder = ItemReorder;
  323. });
  324. //# sourceMappingURL=item-reorder.js.map