a zip code crypto-currency system good for red ONLY

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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", "../../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 platform_1 = require("../../platform/platform");
  17. /**
  18. * @name Img
  19. * @description
  20. * Two of the biggest cuprits of scroll jank is starting up a new HTTP
  21. * request, and rendering images. These two reasons is largely why
  22. * `ion-img` was created. The standard HTML `img` element is often a large
  23. * source of these problems, and what makes matters worse is that the app
  24. * does not have fine-grained control of requests and rendering for each
  25. * `img` element.
  26. *
  27. * The `ion-img` component is similar to the standard `img` element,
  28. * but it also adds features in order to provide improved performance.
  29. * Features include only loading images which are visible, using web workers
  30. * for HTTP requests, preventing jank while scrolling and in-memory caching.
  31. *
  32. * Note that `ion-img` also comes with a few more restrictions in comparison
  33. * to the standard `img` element. A good rule is, if there are only a few
  34. * images to be rendered on a page, then the standard `img` is probably
  35. * best. However, if a page has the potential for hundreds or even thousands
  36. * of images within a scrollable area, then `ion-img` would be better suited
  37. * for the job.
  38. *
  39. * > Note: `ion-img` is only meant to be used inside of [virtual-scroll](/docs/api/components/virtual-scroll/VirtualScroll/)
  40. *
  41. *
  42. * ### Lazy Loading
  43. *
  44. * Lazy loading images refers to only loading images which are actually
  45. * visible within the user's viewport. This also means that images which are
  46. * not viewable on the initial load would not be downloaded or rendered. Next,
  47. * as the user scrolls, each image which becomes visible is then requested
  48. * then rendered on-demand.
  49. *
  50. * The benefits of this approach is that unnecessary and resource intensive
  51. * HTTP requests are not started, valuable bandwidth isn't wasted, and this
  52. * allows the browser to free up resources which would be wasted on images
  53. * which are not even viewable. For example, animated GIFs are enourmous
  54. * performance drains, however, with `ion-img` the app is able to dedicate
  55. * resources to just the viewable images. But again, if the problems listed
  56. * above are not problems within your app, then the standard `img` element
  57. * may be best.
  58. *
  59. *
  60. * ### Image Dimensions
  61. *
  62. * By providing image dimensions up front, Ionic is able to accurately size
  63. * up the image's location within the viewport, which helps lazy load only
  64. * images which are viewable. Image dimensions can either by set as
  65. * properties, inline styles, or external stylesheets. It doesn't matter
  66. * which method of setting dimensions is used, but it's important that somehow
  67. * each `ion-img` has been given an exact size.
  68. *
  69. * For example, by default `<ion-avatar>` and `<ion-thumbnail>` already come
  70. * with exact sizes when placed within an `<ion-item>`. By giving each image
  71. * an exact size, this then further locks in the size of each `ion-item`,
  72. * which again helps improve scroll performance.
  73. *
  74. * ```html
  75. * <!-- dimensions set using attributes -->
  76. * <ion-img width="80" height="80" src="..."></ion-img>
  77. *
  78. * <!-- dimensions set using input properties -->
  79. * <ion-img [width]="imgWidth" [height]="imgHeight" src="..."></ion-img>
  80. *
  81. * <!-- dimensions set using inline styles -->
  82. * <ion-img style="width: 80px; height: 80px;" src="..."></ion-img>
  83. * ```
  84. *
  85. * Additionally, each `ion-img` uses the `object-fit: cover` CSS property.
  86. * What this means is that the actual rendered image will center itself within
  87. * it's container. Or to really get detailed: The image is sized to maintain
  88. * its aspect ratio while filling the containing element’s entire content box.
  89. * Its concrete object size is resolved as a cover constraint against the
  90. * element’s used width and height.
  91. *
  92. * ### Future Optimizations
  93. *
  94. * Future goals are to place image requests within web workers, and cache
  95. * images in-memory as datauris. This method has proven to be effective,
  96. * however there are some current limitations with Cordova which we are
  97. * currently working on.
  98. *
  99. */
  100. var Img = (function () {
  101. function Img(_elementRef, _renderer, _plt, _content, _dom) {
  102. this._elementRef = _elementRef;
  103. this._renderer = _renderer;
  104. this._plt = _plt;
  105. this._content = _content;
  106. this._dom = _dom;
  107. /** @internal */
  108. this._cache = true;
  109. /** @internal */
  110. this._w = '';
  111. /** @internal */
  112. this._h = '';
  113. /** @internal */
  114. this._wQ = '';
  115. /** @internal */
  116. this._hQ = '';
  117. /**
  118. * @input {string} Set the `alt` attribute which gets assigned to
  119. * the inner `img` element.
  120. */
  121. this.alt = '';
  122. if (!this._content) {
  123. console.warn("ion-img can only be used within an ion-content");
  124. }
  125. else {
  126. this._content.addImg(this);
  127. }
  128. this._isLoaded(false);
  129. }
  130. Object.defineProperty(Img.prototype, "src", {
  131. /**
  132. * @input {string} The source of the image.
  133. */
  134. get: function () {
  135. return this._src;
  136. },
  137. set: function (newSrc) {
  138. // if the source hasn't changed, then um, let's not change it
  139. if (newSrc !== this._src) {
  140. // we're changing the source
  141. // so abort any active http requests
  142. // and render the image empty
  143. this.reset();
  144. // update to the new src
  145. this._src = newSrc;
  146. // Are they using an actual datauri already,
  147. // or reset any existing datauri we might be holding onto
  148. this._hasLoaded = newSrc.indexOf('data:') === 0;
  149. // run update to kick off requests or render if everything is good
  150. this.update();
  151. }
  152. },
  153. enumerable: true,
  154. configurable: true
  155. });
  156. /**
  157. * @hidden
  158. */
  159. Img.prototype.reset = function () {
  160. if (this._requestingSrc) {
  161. // abort any active requests
  162. (void 0) /* console.debug */;
  163. this._srcAttr('');
  164. this._requestingSrc = null;
  165. }
  166. if (this._renderedSrc) {
  167. // clear out the currently rendered img
  168. (void 0) /* console.debug */;
  169. this._renderedSrc = null;
  170. this._isLoaded(false);
  171. }
  172. };
  173. /**
  174. * @hidden
  175. */
  176. Img.prototype.update = function () {
  177. var _this = this;
  178. // only attempt an update if there is an active src
  179. // and the content containing the image considers it updatable
  180. if (this._src && this._content.isImgsUpdatable()) {
  181. if (this.canRequest && (this._src !== this._renderedSrc && this._src !== this._requestingSrc) && !this._hasLoaded) {
  182. // only begin the request if we "can" request
  183. // begin the image request if the src is different from the rendered src
  184. // and if we don't already has a tmpDataUri
  185. (void 0) /* console.debug */;
  186. this._requestingSrc = this._src;
  187. this._isLoaded(false);
  188. this._srcAttr(this._src);
  189. // set the dimensions of the image if we do have different data
  190. this._setDims();
  191. }
  192. if (this.canRender && this._hasLoaded && this._src !== this._renderedSrc) {
  193. // we can render and we have a datauri to render
  194. this._renderedSrc = this._src;
  195. this._setDims();
  196. this._dom.write(function () {
  197. if (_this._hasLoaded) {
  198. (void 0) /* console.debug */;
  199. _this._isLoaded(true);
  200. _this._srcAttr(_this._src);
  201. }
  202. });
  203. }
  204. }
  205. };
  206. /**
  207. * @internal
  208. */
  209. Img.prototype._isLoaded = function (isLoaded) {
  210. var renderer = this._renderer;
  211. var ele = this._elementRef.nativeElement;
  212. renderer.setElementClass(ele, 'img-loaded', isLoaded);
  213. renderer.setElementClass(ele, 'img-unloaded', !isLoaded);
  214. };
  215. /**
  216. * @internal
  217. */
  218. Img.prototype._srcAttr = function (srcAttr) {
  219. var imgEle = this._img;
  220. var renderer = this._renderer;
  221. if (imgEle && imgEle.src !== srcAttr) {
  222. renderer.setElementAttribute(this._img, 'src', srcAttr);
  223. renderer.setElementAttribute(this._img, 'alt', this.alt);
  224. }
  225. };
  226. Object.defineProperty(Img.prototype, "top", {
  227. /**
  228. * @hidden
  229. */
  230. get: function () {
  231. var bounds = this._getBounds();
  232. return bounds && bounds.top || 0;
  233. },
  234. enumerable: true,
  235. configurable: true
  236. });
  237. Object.defineProperty(Img.prototype, "bottom", {
  238. /**
  239. * @hidden
  240. */
  241. get: function () {
  242. var bounds = this._getBounds();
  243. return bounds && bounds.bottom || 0;
  244. },
  245. enumerable: true,
  246. configurable: true
  247. });
  248. Img.prototype._getBounds = function () {
  249. if (this._bounds) {
  250. // we've been manually passed bounds data
  251. // this is probably from Virtual Scroll items
  252. return this._bounds;
  253. }
  254. if (!this._rect) {
  255. // we don't have bounds from virtual scroll
  256. // so let's do the raw DOM lookup w/ getBoundingClientRect
  257. this._rect = this._elementRef.nativeElement.getBoundingClientRect();
  258. (void 0) /* console.debug */;
  259. }
  260. return this._rect;
  261. };
  262. Object.defineProperty(Img.prototype, "bounds", {
  263. /**
  264. * @input {any} Sets the bounding rectangle of the element relative to the viewport.
  265. * When using `VirtualScroll`, each virtual item should pass its bounds to each
  266. * `ion-img`. The passed in data object should include `top` and `bottom` properties.
  267. */
  268. set: function (b) {
  269. if (util_1.isPresent(b)) {
  270. this._bounds = b;
  271. }
  272. },
  273. enumerable: true,
  274. configurable: true
  275. });
  276. Object.defineProperty(Img.prototype, "cache", {
  277. /**
  278. * @input {boolean} After an image has been successfully downloaded, it can be cached
  279. * in-memory. This is useful for `VirtualScroll` by allowing image responses to be
  280. * cached, and not rendered, until after scrolling has completed, which allows for
  281. * smoother scrolling.
  282. */
  283. get: function () {
  284. return this._cache;
  285. },
  286. set: function (val) {
  287. this._cache = util_1.isTrueProperty(val);
  288. },
  289. enumerable: true,
  290. configurable: true
  291. });
  292. Object.defineProperty(Img.prototype, "width", {
  293. /**
  294. * @input {string} Image width. If this property is not set it's important that
  295. * the dimensions are still set using CSS. If the dimension is just a number it
  296. * will assume the `px` unit.
  297. */
  298. set: function (val) {
  299. this._wQ = getUnitValue(val);
  300. this._setDims();
  301. },
  302. enumerable: true,
  303. configurable: true
  304. });
  305. Object.defineProperty(Img.prototype, "height", {
  306. /**
  307. * @input {string} Image height. If this property is not set it's important that
  308. * the dimensions are still set using CSS. If the dimension is just a number it
  309. * will assume the `px` unit.
  310. */
  311. set: function (val) {
  312. this._hQ = getUnitValue(val);
  313. this._setDims();
  314. },
  315. enumerable: true,
  316. configurable: true
  317. });
  318. Img.prototype._setDims = function () {
  319. var _this = this;
  320. // only set the dimensions if we can render
  321. // and only if the dimensions have changed from when we last set it
  322. if (this.canRender && (this._w !== this._wQ || this._h !== this._hQ)) {
  323. var wrapperEle = this._elementRef.nativeElement;
  324. var renderer = this._renderer;
  325. this._dom.write(function () {
  326. if (_this._w !== _this._wQ) {
  327. _this._w = _this._wQ;
  328. renderer.setElementStyle(wrapperEle, 'width', _this._w);
  329. }
  330. if (_this._h !== _this._hQ) {
  331. _this._h = _this._hQ;
  332. renderer.setElementStyle(wrapperEle, 'height', _this._h);
  333. }
  334. });
  335. }
  336. };
  337. /**
  338. * @hidden
  339. */
  340. Img.prototype.ngAfterContentInit = function () {
  341. var _this = this;
  342. this._img = this._elementRef.nativeElement.firstChild;
  343. this._unreg = this._plt.registerListener(this._img, 'load', function () {
  344. _this._hasLoaded = true;
  345. _this.update();
  346. }, { passive: true });
  347. };
  348. /**
  349. * @hidden
  350. */
  351. Img.prototype.ngOnDestroy = function () {
  352. this._unreg && this._unreg();
  353. this._content && this._content.removeImg(this);
  354. };
  355. Img.decorators = [
  356. { type: core_1.Component, args: [{
  357. selector: 'ion-img',
  358. template: '<img>',
  359. changeDetection: core_1.ChangeDetectionStrategy.OnPush,
  360. encapsulation: core_1.ViewEncapsulation.None,
  361. },] },
  362. ];
  363. /** @nocollapse */
  364. Img.ctorParameters = function () { return [
  365. { type: core_1.ElementRef, },
  366. { type: core_1.Renderer, },
  367. { type: platform_1.Platform, },
  368. { type: content_1.Content, decorators: [{ type: core_1.Optional },] },
  369. { type: dom_controller_1.DomController, },
  370. ]; };
  371. Img.propDecorators = {
  372. 'src': [{ type: core_1.Input },],
  373. 'bounds': [{ type: core_1.Input },],
  374. 'cache': [{ type: core_1.Input },],
  375. 'width': [{ type: core_1.Input },],
  376. 'height': [{ type: core_1.Input },],
  377. 'alt': [{ type: core_1.Input },],
  378. };
  379. return Img;
  380. }());
  381. exports.Img = Img;
  382. function getUnitValue(val) {
  383. if (util_1.isPresent(val)) {
  384. if (typeof val === 'string') {
  385. if (val.indexOf('%') > -1 || val.indexOf('px') > -1) {
  386. return val;
  387. }
  388. if (val.length) {
  389. return val + 'px';
  390. }
  391. }
  392. else if (typeof val === 'number') {
  393. return val + 'px';
  394. }
  395. }
  396. return '';
  397. }
  398. });
  399. //# sourceMappingURL=img.js.map