a zip code crypto-currency system good for red ONLY

item-sliding.js 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  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", "../../util/util", "./item", "../list/list", "../../platform/platform", "./item-options"], 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 util_1 = require("../../util/util");
  14. var item_1 = require("./item");
  15. var list_1 = require("../list/list");
  16. var platform_1 = require("../../platform/platform");
  17. var item_options_1 = require("./item-options");
  18. var SWIPE_MARGIN = 30;
  19. var ELASTIC_FACTOR = 0.55;
  20. var ITEM_SIDE_FLAG_NONE = 0;
  21. var ITEM_SIDE_FLAG_LEFT = 1 << 0;
  22. var ITEM_SIDE_FLAG_RIGHT = 1 << 1;
  23. var ITEM_SIDE_FLAG_BOTH = ITEM_SIDE_FLAG_LEFT | ITEM_SIDE_FLAG_RIGHT;
  24. /**
  25. * @name ItemSliding
  26. * @description
  27. * A sliding item is a list item that can be swiped to reveal buttons. It requires
  28. * an [Item](../Item) component as a child and a [List](../../list/List) component as
  29. * a parent. All buttons to reveal can be placed in the `<ion-item-options>` element.
  30. *
  31. * @usage
  32. * ```html
  33. * <ion-list>
  34. * <ion-item-sliding #item>
  35. * <ion-item>
  36. * Item
  37. * </ion-item>
  38. * <ion-item-options side="left">
  39. * <button ion-button (click)="favorite(item)">Favorite</button>
  40. * <button ion-button color="danger" (click)="share(item)">Share</button>
  41. * </ion-item-options>
  42. *
  43. * <ion-item-options side="right">
  44. * <button ion-button (click)="unread(item)">Unread</button>
  45. * </ion-item-options>
  46. * </ion-item-sliding>
  47. * </ion-list>
  48. * ```
  49. *
  50. * ### Swipe Direction
  51. * By default, the buttons are revealed when the sliding item is swiped from right to left,
  52. * so the buttons are placed in the right side. But it's also possible to reveal them
  53. * in the right side (sliding from left to right) by setting the `side` attribute
  54. * on the `ion-item-options` element. Up to 2 `ion-item-options` can used at the same time
  55. * in order to reveal two different sets of buttons depending the swipping direction.
  56. *
  57. * ```html
  58. * <ion-item-options side="right">
  59. * <button ion-button (click)="archive(item)">
  60. * <ion-icon name="archive"></ion-icon>
  61. * Archive
  62. * </button>
  63. * </ion-item-options>
  64. *
  65. * <ion-item-options side="left">
  66. * <button ion-button (click)="archive(item)">
  67. * <ion-icon name="archive"></ion-icon>
  68. * Archive
  69. * </button>
  70. * </ion-item-options>
  71. * ```
  72. *
  73. * ### Listening for events (ionDrag) and (ionSwipe)
  74. * It's possible to know the current relative position of the sliding item by subscribing
  75. * to the (ionDrag)` event.
  76. *
  77. * ```html
  78. * <ion-item-sliding (ionDrag)="logDrag($event)">
  79. * <ion-item>Item</ion-item>
  80. * <ion-item-options>
  81. * <button ion-button>Favorite</button>
  82. * </ion-item-options>
  83. * </ion-item-sliding>
  84. * ```
  85. *
  86. * ### Button Layout
  87. * If an icon is placed with text in the option button, by default it will
  88. * display the icon on top of the text. This can be changed to display the icon
  89. * to the left of the text by setting `icon-start` as an attribute on the
  90. * `<ion-item-options>` element.
  91. *
  92. * ```html
  93. * <ion-item-options icon-start>
  94. * <button ion-button (click)="archive(item)">
  95. * <ion-icon name="archive"></ion-icon>
  96. * Archive
  97. * </button>
  98. * </ion-item-options>
  99. *
  100. * ```
  101. *
  102. * ### Expandable Options
  103. *
  104. * Options can be expanded to take up the full width of the item if you swipe past
  105. * a certain point. This can be combined with the `ionSwipe` event to call methods
  106. * on the class.
  107. *
  108. * ```html
  109. *
  110. * <ion-item-sliding (ionSwipe)="delete(item)">
  111. * <ion-item>Item</ion-item>
  112. * <ion-item-options>
  113. * <button ion-button expandable (click)="delete(item)">Delete</button>
  114. * </ion-item-options>
  115. * </ion-item-sliding>
  116. * ```
  117. *
  118. * We can call `delete` by either clicking the button, or by doing a full swipe on the item.
  119. *
  120. * @demo /docs/demos/src/item-sliding/
  121. * @see {@link /docs/components#lists List Component Docs}
  122. * @see {@link ../Item Item API Docs}
  123. * @see {@link ../../list/List List API Docs}
  124. */
  125. var ItemSliding = (function () {
  126. function ItemSliding(list, _plt, _renderer, _elementRef, _zone) {
  127. this._plt = _plt;
  128. this._renderer = _renderer;
  129. this._elementRef = _elementRef;
  130. this._zone = _zone;
  131. this._openAmount = 0;
  132. this._startX = 0;
  133. this._optsWidthRightSide = 0;
  134. this._optsWidthLeftSide = 0;
  135. this._tmr = null;
  136. this._optsDirty = true;
  137. this._state = 2 /* Disabled */;
  138. /**
  139. * @output {event} Emitted when the sliding position changes.
  140. * It reports the relative position.
  141. *
  142. * ```ts
  143. * ondrag(item) {
  144. * let percent = item.getSlidingPercent();
  145. * if (percent > 0) {
  146. * // positive
  147. * console.log('right side');
  148. * } else {
  149. * // negative
  150. * console.log('left side');
  151. * }
  152. * if (Math.abs(percent) > 1) {
  153. * console.log('overscroll');
  154. * }
  155. * }
  156. * ```
  157. *
  158. */
  159. this.ionDrag = new core_1.EventEmitter();
  160. list && list.containsSlidingItem(true);
  161. _elementRef.nativeElement.$ionComponent = this;
  162. this.setElementClass('item-wrapper', true);
  163. }
  164. Object.defineProperty(ItemSliding.prototype, "_itemOptions", {
  165. set: function (itemOptions) {
  166. var sides = 0;
  167. // Reset left and right options in case they were removed
  168. this._leftOptions = this._rightOptions = null;
  169. for (var _i = 0, _a = itemOptions.toArray(); _i < _a.length; _i++) {
  170. var item = _a[_i];
  171. if (item.isRightSide()) {
  172. this._rightOptions = item;
  173. sides |= ITEM_SIDE_FLAG_RIGHT;
  174. }
  175. else {
  176. this._leftOptions = item;
  177. sides |= ITEM_SIDE_FLAG_LEFT;
  178. }
  179. }
  180. this._optsDirty = true;
  181. this._sides = sides;
  182. },
  183. enumerable: true,
  184. configurable: true
  185. });
  186. /**
  187. * @hidden
  188. */
  189. ItemSliding.prototype.getOpenAmount = function () {
  190. return this._openAmount;
  191. };
  192. /**
  193. * @hidden
  194. */
  195. ItemSliding.prototype.getSlidingPercent = function () {
  196. var openAmount = this._openAmount;
  197. if (openAmount > 0) {
  198. return openAmount / this._optsWidthRightSide;
  199. }
  200. else if (openAmount < 0) {
  201. return openAmount / this._optsWidthLeftSide;
  202. }
  203. else {
  204. return 0;
  205. }
  206. };
  207. /**
  208. * @hidden
  209. */
  210. ItemSliding.prototype.startSliding = function (startX) {
  211. if (this._tmr) {
  212. this._plt.cancelTimeout(this._tmr);
  213. this._tmr = null;
  214. }
  215. if (this._openAmount === 0) {
  216. this._optsDirty = true;
  217. this._setState(4 /* Enabled */);
  218. }
  219. this._startX = startX + this._openAmount;
  220. this.item.setElementStyle(this._plt.Css.transition, 'none');
  221. };
  222. /**
  223. * @hidden
  224. */
  225. ItemSliding.prototype.moveSliding = function (x) {
  226. if (this._optsDirty) {
  227. this.calculateOptsWidth();
  228. return;
  229. }
  230. var openAmount = (this._startX - x);
  231. switch (this._sides) {
  232. case ITEM_SIDE_FLAG_RIGHT:
  233. openAmount = Math.max(0, openAmount);
  234. break;
  235. case ITEM_SIDE_FLAG_LEFT:
  236. openAmount = Math.min(0, openAmount);
  237. break;
  238. case ITEM_SIDE_FLAG_BOTH: break;
  239. case ITEM_SIDE_FLAG_NONE: return;
  240. default:
  241. (void 0) /* assert */;
  242. break;
  243. }
  244. if (openAmount > this._optsWidthRightSide) {
  245. var optsWidth = this._optsWidthRightSide;
  246. openAmount = optsWidth + (openAmount - optsWidth) * ELASTIC_FACTOR;
  247. }
  248. else if (openAmount < -this._optsWidthLeftSide) {
  249. var optsWidth = -this._optsWidthLeftSide;
  250. openAmount = optsWidth + (openAmount - optsWidth) * ELASTIC_FACTOR;
  251. }
  252. this._setOpenAmount(openAmount, false);
  253. return openAmount;
  254. };
  255. /**
  256. * @hidden
  257. */
  258. ItemSliding.prototype.endSliding = function (velocity) {
  259. var restingPoint = (this._openAmount > 0)
  260. ? this._optsWidthRightSide
  261. : -this._optsWidthLeftSide;
  262. // Check if the drag didn't clear the buttons mid-point
  263. // and we aren't moving fast enough to swipe open
  264. var isResetDirection = (this._openAmount > 0) === !(velocity < 0);
  265. var isMovingFast = Math.abs(velocity) > 0.3;
  266. var isOnCloseZone = Math.abs(this._openAmount) < Math.abs(restingPoint / 2);
  267. if (util_1.swipeShouldReset(isResetDirection, isMovingFast, isOnCloseZone)) {
  268. restingPoint = 0;
  269. }
  270. this.fireSwipeEvent();
  271. this._setOpenAmount(restingPoint, true);
  272. return restingPoint;
  273. };
  274. /**
  275. * @hidden
  276. */
  277. ItemSliding.prototype.fireSwipeEvent = function () {
  278. var _this = this;
  279. if (this._state & 32 /* SwipeRight */) {
  280. this._zone.run(function () { return _this._rightOptions.ionSwipe.emit(_this); });
  281. }
  282. else if (this._state & 64 /* SwipeLeft */) {
  283. this._zone.run(function () { return _this._leftOptions.ionSwipe.emit(_this); });
  284. }
  285. };
  286. /**
  287. * @hidden
  288. */
  289. ItemSliding.prototype.calculateOptsWidth = function () {
  290. if (!this._optsDirty) {
  291. return;
  292. }
  293. this._optsWidthRightSide = 0;
  294. if (this._rightOptions) {
  295. this._optsWidthRightSide = this._rightOptions.width();
  296. (void 0) /* assert */;
  297. }
  298. this._optsWidthLeftSide = 0;
  299. if (this._leftOptions) {
  300. this._optsWidthLeftSide = this._leftOptions.width();
  301. (void 0) /* assert */;
  302. }
  303. this._optsDirty = false;
  304. };
  305. ItemSliding.prototype._setOpenAmount = function (openAmount, isFinal) {
  306. var _this = this;
  307. var platform = this._plt;
  308. if (this._tmr) {
  309. platform.cancelTimeout(this._tmr);
  310. this._tmr = null;
  311. }
  312. this._openAmount = openAmount;
  313. if (isFinal) {
  314. this.item.setElementStyle(platform.Css.transition, '');
  315. }
  316. if (openAmount > 0) {
  317. var state = (openAmount >= (this._optsWidthRightSide + SWIPE_MARGIN))
  318. ? 8 /* Right */ | 32 /* SwipeRight */
  319. : 8 /* Right */;
  320. this._setState(state);
  321. }
  322. else if (openAmount < 0) {
  323. var state_1 = (openAmount <= (-this._optsWidthLeftSide - SWIPE_MARGIN))
  324. ? 16 /* Left */ | 64 /* SwipeLeft */
  325. : 16 /* Left */;
  326. this._setState(state_1);
  327. }
  328. else {
  329. (void 0) /* assert */;
  330. this._tmr = platform.timeout(function () {
  331. _this._setState(2 /* Disabled */);
  332. _this._tmr = null;
  333. }, 600);
  334. this.item.setElementStyle(platform.Css.transform, '');
  335. return;
  336. }
  337. this.item.setElementStyle(platform.Css.transform, "translate3d(" + -openAmount + "px,0,0)");
  338. var ionDrag = this.ionDrag;
  339. if (ionDrag.observers.length > 0) {
  340. ionDrag.emit(this);
  341. }
  342. };
  343. ItemSliding.prototype._setState = function (state) {
  344. if (state === this._state) {
  345. return;
  346. }
  347. this.setElementClass('active-slide', (state !== 2 /* Disabled */));
  348. this.setElementClass('active-options-right', !!(state & 8 /* Right */));
  349. this.setElementClass('active-options-left', !!(state & 16 /* Left */));
  350. this.setElementClass('active-swipe-right', !!(state & 32 /* SwipeRight */));
  351. this.setElementClass('active-swipe-left', !!(state & 64 /* SwipeLeft */));
  352. this._state = state;
  353. };
  354. /**
  355. * Close the sliding item. Items can also be closed from the [List](../../list/List).
  356. *
  357. * The sliding item can be closed by grabbing a reference to `ItemSliding`. In the
  358. * below example, the template reference variable `slidingItem` is placed on the element
  359. * and passed to the `share` method.
  360. *
  361. * ```html
  362. * <ion-list>
  363. * <ion-item-sliding #slidingItem>
  364. * <ion-item>
  365. * Item
  366. * </ion-item>
  367. * <ion-item-options>
  368. * <button ion-button (click)="share(slidingItem)">Share</button>
  369. * </ion-item-options>
  370. * </ion-item-sliding>
  371. * </ion-list>
  372. * ```
  373. *
  374. * ```ts
  375. * import { Component } from '@angular/core';
  376. * import { ItemSliding } from 'ionic-angular';
  377. *
  378. * @Component({...})
  379. * export class MyClass {
  380. * constructor() { }
  381. *
  382. * share(slidingItem: ItemSliding) {
  383. * slidingItem.close();
  384. * }
  385. * }
  386. * ```
  387. */
  388. ItemSliding.prototype.close = function () {
  389. this._setOpenAmount(0, true);
  390. };
  391. /**
  392. * @hidden
  393. */
  394. ItemSliding.prototype.setElementClass = function (cssClass, shouldAdd) {
  395. this._renderer.setElementClass(this._elementRef.nativeElement, cssClass, shouldAdd);
  396. };
  397. ItemSliding.decorators = [
  398. { type: core_1.Component, args: [{
  399. selector: 'ion-item-sliding',
  400. template: "\n <ng-content select=\"ion-item,[ion-item]\"></ng-content>\n <ng-content select=\"ion-item-options\"></ng-content>\n ",
  401. changeDetection: core_1.ChangeDetectionStrategy.OnPush,
  402. encapsulation: core_1.ViewEncapsulation.None
  403. },] },
  404. ];
  405. /** @nocollapse */
  406. ItemSliding.ctorParameters = function () { return [
  407. { type: list_1.List, decorators: [{ type: core_1.Optional },] },
  408. { type: platform_1.Platform, },
  409. { type: core_1.Renderer, },
  410. { type: core_1.ElementRef, },
  411. { type: core_1.NgZone, },
  412. ]; };
  413. ItemSliding.propDecorators = {
  414. 'item': [{ type: core_1.ContentChild, args: [item_1.Item,] },],
  415. 'ionDrag': [{ type: core_1.Output },],
  416. '_itemOptions': [{ type: core_1.ContentChildren, args: [core_1.forwardRef(function () { return item_options_1.ItemOptions; }),] },],
  417. };
  418. return ItemSliding;
  419. }());
  420. exports.ItemSliding = ItemSliding;
  421. });
  422. //# sourceMappingURL=item-sliding.js.map