a zip code crypto-currency system good for red ONLY

popover-transitions.js 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. (function (factory) {
  12. if (typeof module === "object" && typeof module.exports === "object") {
  13. var v = factory(require, exports);
  14. if (v !== undefined) module.exports = v;
  15. }
  16. else if (typeof define === "function" && define.amd) {
  17. define(["require", "exports", "../../animations/animation", "../../transitions/page-transition"], factory);
  18. }
  19. })(function (require, exports) {
  20. "use strict";
  21. Object.defineProperty(exports, "__esModule", { value: true });
  22. var animation_1 = require("../../animations/animation");
  23. var page_transition_1 = require("../../transitions/page-transition");
  24. /**
  25. * Animations for popover
  26. */
  27. var PopoverTransition = (function (_super) {
  28. __extends(PopoverTransition, _super);
  29. function PopoverTransition() {
  30. return _super !== null && _super.apply(this, arguments) || this;
  31. }
  32. PopoverTransition.prototype.mdPositionView = function (nativeEle, ev) {
  33. var originY = 'top';
  34. var originX = 'left';
  35. var popoverWrapperEle = nativeEle.querySelector('.popover-wrapper');
  36. // Popover content width and height
  37. var popoverEle = nativeEle.querySelector('.popover-content');
  38. var popoverDim = popoverEle.getBoundingClientRect();
  39. var popoverWidth = popoverDim.width;
  40. var popoverHeight = popoverDim.height;
  41. // Window body width and height
  42. var bodyWidth = this.plt.width();
  43. var bodyHeight = this.plt.height();
  44. // If ev was passed, use that for target element
  45. var targetDim = ev && ev.target && ev.target.getBoundingClientRect();
  46. var targetTop = (targetDim && 'top' in targetDim) ? targetDim.top : (bodyHeight / 2) - (popoverHeight / 2);
  47. var targetLeft = (targetDim && 'left' in targetDim) ? targetDim.left : (bodyWidth / 2) - (popoverWidth / 2);
  48. var targetHeight = targetDim && targetDim.height || 0;
  49. var popoverCSS = {
  50. top: targetTop,
  51. left: targetLeft
  52. };
  53. // If the popover left is less than the padding it is off screen
  54. // to the left so adjust it, else if the width of the popover
  55. // exceeds the body width it is off screen to the right so adjust
  56. if (popoverCSS.left < POPOVER_MD_BODY_PADDING) {
  57. popoverCSS.left = POPOVER_MD_BODY_PADDING;
  58. }
  59. else if (popoverWidth + POPOVER_MD_BODY_PADDING + popoverCSS.left > bodyWidth) {
  60. popoverCSS.left = bodyWidth - popoverWidth - POPOVER_MD_BODY_PADDING;
  61. originX = 'right';
  62. }
  63. // If the popover when popped down stretches past bottom of screen,
  64. // make it pop up if there's room above
  65. if (targetTop + targetHeight + popoverHeight > bodyHeight && targetTop - popoverHeight > 0) {
  66. popoverCSS.top = targetTop - popoverHeight;
  67. nativeEle.className = nativeEle.className + ' popover-bottom';
  68. originY = 'bottom';
  69. // If there isn't room for it to pop up above the target cut it off
  70. }
  71. else if (targetTop + targetHeight + popoverHeight > bodyHeight) {
  72. popoverEle.style.bottom = POPOVER_MD_BODY_PADDING + 'px';
  73. }
  74. popoverEle.style.top = popoverCSS.top + 'px';
  75. popoverEle.style.left = popoverCSS.left + 'px';
  76. popoverEle.style[this.plt.Css.transformOrigin] = originY + ' ' + originX;
  77. // Since the transition starts before styling is done we
  78. // want to wait for the styles to apply before showing the wrapper
  79. popoverWrapperEle.style.opacity = '1';
  80. };
  81. PopoverTransition.prototype.iosPositionView = function (nativeEle, ev) {
  82. var originY = 'top';
  83. var originX = 'left';
  84. var popoverWrapperEle = nativeEle.querySelector('.popover-wrapper');
  85. // Popover content width and height
  86. var popoverEle = nativeEle.querySelector('.popover-content');
  87. var popoverDim = popoverEle.getBoundingClientRect();
  88. var popoverWidth = popoverDim.width;
  89. var popoverHeight = popoverDim.height;
  90. // Window body width and height
  91. var bodyWidth = this.plt.width();
  92. var bodyHeight = this.plt.height();
  93. // If ev was passed, use that for target element
  94. var targetDim = ev && ev.target && ev.target.getBoundingClientRect();
  95. var targetTop = (targetDim && 'top' in targetDim) ? targetDim.top : (bodyHeight / 2) - (popoverHeight / 2);
  96. var targetLeft = (targetDim && 'left' in targetDim) ? targetDim.left : (bodyWidth / 2);
  97. var targetWidth = targetDim && targetDim.width || 0;
  98. var targetHeight = targetDim && targetDim.height || 0;
  99. // The arrow that shows above the popover on iOS
  100. var arrowEle = nativeEle.querySelector('.popover-arrow');
  101. var arrowDim = arrowEle.getBoundingClientRect();
  102. var arrowWidth = arrowDim.width;
  103. var arrowHeight = arrowDim.height;
  104. // If no ev was passed, hide the arrow
  105. if (!targetDim) {
  106. arrowEle.style.display = 'none';
  107. }
  108. var arrowCSS = {
  109. top: targetTop + targetHeight,
  110. left: targetLeft + (targetWidth / 2) - (arrowWidth / 2)
  111. };
  112. var popoverCSS = {
  113. top: targetTop + targetHeight + (arrowHeight - 1),
  114. left: targetLeft + (targetWidth / 2) - (popoverWidth / 2)
  115. };
  116. // If the popover left is less than the padding it is off screen
  117. // to the left so adjust it, else if the width of the popover
  118. // exceeds the body width it is off screen to the right so adjust
  119. //
  120. var checkSafeAreaLeft = false;
  121. var checkSafeAreaRight = false;
  122. // If the popover left is less than the padding it is off screen
  123. // to the left so adjust it, else if the width of the popover
  124. // exceeds the body width it is off screen to the right so adjust
  125. // 25 is a random/arbitrary number. It seems to work fine for ios11
  126. // and iPhoneX. Is it perfect? No. Does it work? Yes.
  127. if (popoverCSS.left < (POPOVER_IOS_BODY_PADDING + 25)) {
  128. checkSafeAreaLeft = true;
  129. popoverCSS.left = POPOVER_IOS_BODY_PADDING;
  130. }
  131. else if ((popoverWidth + POPOVER_IOS_BODY_PADDING + popoverCSS.left + 25) > bodyWidth) {
  132. // Ok, so we're on the right side of the screen,
  133. // but now we need to make sure we're still a bit further right
  134. // cus....notchurally... Again, 25 is random. It works tho
  135. checkSafeAreaRight = true;
  136. popoverCSS.left = bodyWidth - popoverWidth - POPOVER_IOS_BODY_PADDING;
  137. originX = 'right';
  138. }
  139. // make it pop up if there's room above
  140. if (targetTop + targetHeight + popoverHeight > bodyHeight && targetTop - popoverHeight > 0) {
  141. arrowCSS.top = targetTop - (arrowHeight + 1);
  142. popoverCSS.top = targetTop - popoverHeight - (arrowHeight - 1);
  143. nativeEle.className = nativeEle.className + ' popover-bottom';
  144. originY = 'bottom';
  145. // If there isn't room for it to pop up above the target cut it off
  146. }
  147. else if (targetTop + targetHeight + popoverHeight > bodyHeight) {
  148. popoverEle.style.bottom = POPOVER_IOS_BODY_PADDING + '%';
  149. }
  150. arrowEle.style.top = arrowCSS.top + 'px';
  151. arrowEle.style.left = arrowCSS.left + 'px';
  152. popoverEle.style.top = popoverCSS.top + 'px';
  153. popoverEle.style.left = popoverCSS.left + 'px';
  154. if (checkSafeAreaLeft) {
  155. if (CSS.supports('left', 'constant(safe-area-inset-left)')) {
  156. popoverEle.style.left = "calc(" + popoverCSS.left + "px + constant(safe-area-inset-left)";
  157. }
  158. else if (CSS.supports('left', 'env(safe-area-inset-left)')) {
  159. popoverEle.style.left = "calc(" + popoverCSS.left + "px + env(safe-area-inset-left)";
  160. }
  161. }
  162. if (checkSafeAreaRight) {
  163. if (CSS.supports('right', 'constant(safe-area-inset-right)')) {
  164. popoverEle.style.left = "calc(" + popoverCSS.left + "px - constant(safe-area-inset-right)";
  165. }
  166. else if (CSS.supports('right', 'env(safe-area-inset-right)')) {
  167. popoverEle.style.left = "calc(" + popoverCSS.left + "px - env(safe-area-inset-right)";
  168. }
  169. }
  170. popoverEle.style[this.plt.Css.transformOrigin] = originY + ' ' + originX;
  171. // Since the transition starts before styling is done we
  172. // want to wait for the styles to apply before showing the wrapper
  173. popoverWrapperEle.style.opacity = '1';
  174. };
  175. return PopoverTransition;
  176. }(page_transition_1.PageTransition));
  177. exports.PopoverTransition = PopoverTransition;
  178. var PopoverPopIn = (function (_super) {
  179. __extends(PopoverPopIn, _super);
  180. function PopoverPopIn() {
  181. return _super !== null && _super.apply(this, arguments) || this;
  182. }
  183. PopoverPopIn.prototype.init = function () {
  184. var ele = this.enteringView.pageRef().nativeElement;
  185. var backdrop = new animation_1.Animation(this.plt, ele.querySelector('ion-backdrop'));
  186. var wrapper = new animation_1.Animation(this.plt, ele.querySelector('.popover-wrapper'));
  187. wrapper.fromTo('opacity', 0.01, 1);
  188. backdrop.fromTo('opacity', 0.01, 0.08);
  189. this
  190. .easing('ease')
  191. .duration(100)
  192. .add(backdrop)
  193. .add(wrapper);
  194. };
  195. PopoverPopIn.prototype.play = function () {
  196. var _this = this;
  197. this.plt.raf(function () {
  198. _this.iosPositionView(_this.enteringView.pageRef().nativeElement, _this.opts.ev);
  199. _super.prototype.play.call(_this);
  200. });
  201. };
  202. return PopoverPopIn;
  203. }(PopoverTransition));
  204. exports.PopoverPopIn = PopoverPopIn;
  205. var PopoverPopOut = (function (_super) {
  206. __extends(PopoverPopOut, _super);
  207. function PopoverPopOut() {
  208. return _super !== null && _super.apply(this, arguments) || this;
  209. }
  210. PopoverPopOut.prototype.init = function () {
  211. var ele = this.leavingView.pageRef().nativeElement;
  212. var backdrop = new animation_1.Animation(this.plt, ele.querySelector('ion-backdrop'));
  213. var wrapper = new animation_1.Animation(this.plt, ele.querySelector('.popover-wrapper'));
  214. wrapper.fromTo('opacity', 0.99, 0);
  215. backdrop.fromTo('opacity', 0.08, 0);
  216. this
  217. .easing('ease')
  218. .duration(500)
  219. .add(backdrop)
  220. .add(wrapper);
  221. };
  222. return PopoverPopOut;
  223. }(PopoverTransition));
  224. exports.PopoverPopOut = PopoverPopOut;
  225. var PopoverMdPopIn = (function (_super) {
  226. __extends(PopoverMdPopIn, _super);
  227. function PopoverMdPopIn() {
  228. return _super !== null && _super.apply(this, arguments) || this;
  229. }
  230. PopoverMdPopIn.prototype.init = function () {
  231. var ele = this.enteringView.pageRef().nativeElement;
  232. var content = new animation_1.Animation(this.plt, ele.querySelector('.popover-content'));
  233. var viewport = new animation_1.Animation(this.plt, ele.querySelector('.popover-viewport'));
  234. content.fromTo('scale', 0.001, 1);
  235. viewport.fromTo('opacity', 0.01, 1);
  236. this
  237. .easing('cubic-bezier(0.36,0.66,0.04,1)')
  238. .duration(300)
  239. .add(content)
  240. .add(viewport);
  241. };
  242. PopoverMdPopIn.prototype.play = function () {
  243. var _this = this;
  244. this.plt.raf(function () {
  245. _this.mdPositionView(_this.enteringView.pageRef().nativeElement, _this.opts.ev);
  246. _super.prototype.play.call(_this);
  247. });
  248. };
  249. return PopoverMdPopIn;
  250. }(PopoverTransition));
  251. exports.PopoverMdPopIn = PopoverMdPopIn;
  252. var PopoverMdPopOut = (function (_super) {
  253. __extends(PopoverMdPopOut, _super);
  254. function PopoverMdPopOut() {
  255. return _super !== null && _super.apply(this, arguments) || this;
  256. }
  257. PopoverMdPopOut.prototype.init = function () {
  258. var ele = this.leavingView.pageRef().nativeElement;
  259. var wrapper = new animation_1.Animation(this.plt, ele.querySelector('.popover-wrapper'));
  260. wrapper.fromTo('opacity', 0.99, 0);
  261. this
  262. .easing('ease')
  263. .duration(500)
  264. .fromTo('opacity', 0.01, 1)
  265. .add(wrapper);
  266. };
  267. return PopoverMdPopOut;
  268. }(PopoverTransition));
  269. exports.PopoverMdPopOut = PopoverMdPopOut;
  270. var POPOVER_IOS_BODY_PADDING = 2;
  271. var POPOVER_MD_BODY_PADDING = 12;
  272. });
  273. //# sourceMappingURL=popover-transitions.js.map