a zip code crypto-currency system good for red ONLY

picker-component.js 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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", "../../config/config", "../../gestures/gesture-controller", "../../platform/key", "../../navigation/nav-params", "../../navigation/view-controller", "./picker-column"], 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 config_1 = require("../../config/config");
  15. var gesture_controller_1 = require("../../gestures/gesture-controller");
  16. var key_1 = require("../../platform/key");
  17. var nav_params_1 = require("../../navigation/nav-params");
  18. var view_controller_1 = require("../../navigation/view-controller");
  19. var picker_column_1 = require("./picker-column");
  20. /**
  21. * @hidden
  22. */
  23. var PickerCmp = (function () {
  24. function PickerCmp(_viewCtrl, _elementRef, config, gestureCtrl, params, renderer) {
  25. this._viewCtrl = _viewCtrl;
  26. this._elementRef = _elementRef;
  27. this._gestureBlocker = gestureCtrl.createBlocker(gesture_controller_1.BLOCK_ALL);
  28. this.d = params.data;
  29. this.mode = config.get('mode');
  30. renderer.setElementClass(_elementRef.nativeElement, "picker-" + this.mode, true);
  31. if (this.d.cssClass) {
  32. this.d.cssClass.split(' ').forEach(function (cssClass) {
  33. renderer.setElementClass(_elementRef.nativeElement, cssClass, true);
  34. });
  35. }
  36. this.id = (++pickerIds);
  37. this.lastClick = 0;
  38. }
  39. PickerCmp.prototype.ionViewWillLoad = function () {
  40. // normalize the data
  41. var data = this.d;
  42. data.buttons = data.buttons.map(function (button) {
  43. if (util_1.isString(button)) {
  44. return { text: button };
  45. }
  46. if (button.role) {
  47. button.cssRole = "picker-toolbar-" + button.role;
  48. }
  49. return button;
  50. });
  51. // clean up dat data
  52. data.columns = data.columns.map(function (column) {
  53. if (!util_1.isPresent(column.options)) {
  54. column.options = [];
  55. }
  56. column.selectedIndex = column.selectedIndex || 0;
  57. column.options = column.options.map(function (inputOpt) {
  58. var opt = {
  59. text: '',
  60. value: '',
  61. disabled: inputOpt.disabled,
  62. };
  63. if (util_1.isPresent(inputOpt)) {
  64. if (util_1.isString(inputOpt) || util_1.isNumber(inputOpt)) {
  65. opt.text = inputOpt.toString();
  66. opt.value = inputOpt;
  67. }
  68. else {
  69. opt.text = util_1.isPresent(inputOpt.text) ? inputOpt.text : inputOpt.value;
  70. opt.value = util_1.isPresent(inputOpt.value) ? inputOpt.value : inputOpt.text;
  71. }
  72. }
  73. return opt;
  74. });
  75. return column;
  76. });
  77. };
  78. PickerCmp.prototype.ionViewDidLoad = function () {
  79. this.refresh();
  80. };
  81. PickerCmp.prototype.ionViewWillEnter = function () {
  82. this._gestureBlocker.block();
  83. };
  84. PickerCmp.prototype.ionViewDidLeave = function () {
  85. this._gestureBlocker.unblock();
  86. };
  87. PickerCmp.prototype.refresh = function () {
  88. this._cols.forEach(function (column) { return column.refresh(); });
  89. };
  90. PickerCmp.prototype._colChange = function () {
  91. // one of the columns has changed its selected index
  92. var picker = this._viewCtrl;
  93. picker.ionChange.emit(this.getSelected());
  94. };
  95. PickerCmp.prototype._keyUp = function (ev) {
  96. if (this.enabled && this._viewCtrl.isLast()) {
  97. if (ev.keyCode === key_1.KEY_ENTER) {
  98. if (this.lastClick + 1000 < Date.now()) {
  99. // do not fire this click if there recently was already a click
  100. // this can happen when the button has focus and used the enter
  101. // key to click the button. However, both the click handler and
  102. // this keyup event will fire, so only allow one of them to go.
  103. (void 0) /* console.debug */;
  104. var button = this.d.buttons[this.d.buttons.length - 1];
  105. this.btnClick(button);
  106. }
  107. }
  108. else if (ev.keyCode === key_1.KEY_ESCAPE) {
  109. (void 0) /* console.debug */;
  110. this.bdClick();
  111. }
  112. }
  113. };
  114. PickerCmp.prototype.ionViewDidEnter = function () {
  115. var focusableEle = this._elementRef.nativeElement.querySelector('button');
  116. if (focusableEle) {
  117. focusableEle.focus();
  118. }
  119. this.enabled = true;
  120. };
  121. PickerCmp.prototype.btnClick = function (button) {
  122. if (!this.enabled) {
  123. return;
  124. }
  125. // keep the time of the most recent button click
  126. this.lastClick = Date.now();
  127. var shouldDismiss = true;
  128. if (button.handler) {
  129. // a handler has been provided, execute it
  130. // pass the handler the values from the inputs
  131. if (button.handler(this.getSelected()) === false) {
  132. // if the return value of the handler is false then do not dismiss
  133. shouldDismiss = false;
  134. }
  135. }
  136. if (shouldDismiss) {
  137. this.dismiss(button.role);
  138. }
  139. };
  140. PickerCmp.prototype.bdClick = function () {
  141. if (this.enabled && this.d.enableBackdropDismiss) {
  142. var cancelBtn = this.d.buttons.find(function (b) { return b.role === 'cancel'; });
  143. if (cancelBtn) {
  144. this.btnClick(cancelBtn);
  145. }
  146. else {
  147. this.dismiss('backdrop');
  148. }
  149. }
  150. };
  151. PickerCmp.prototype.dismiss = function (role) {
  152. return this._viewCtrl.dismiss(this.getSelected(), role);
  153. };
  154. PickerCmp.prototype.getSelected = function () {
  155. var selected = {};
  156. this.d.columns.forEach(function (col, index) {
  157. var selectedColumn = col.options[col.selectedIndex];
  158. selected[col.name] = {
  159. text: selectedColumn ? selectedColumn.text : null,
  160. value: selectedColumn ? selectedColumn.value : null,
  161. columnIndex: index,
  162. };
  163. });
  164. return selected;
  165. };
  166. PickerCmp.prototype.ngOnDestroy = function () {
  167. (void 0) /* assert */;
  168. this._gestureBlocker.destroy();
  169. };
  170. PickerCmp.decorators = [
  171. { type: core_1.Component, args: [{
  172. selector: 'ion-picker-cmp',
  173. template: "\n <ion-backdrop (click)=\"bdClick()\"></ion-backdrop>\n <div class=\"picker-wrapper\">\n <div class=\"picker-toolbar\">\n <div *ngFor=\"let b of d.buttons\" class=\"picker-toolbar-button\" [ngClass]=\"b.cssRole\">\n <button ion-button (click)=\"btnClick(b)\" [ngClass]=\"b.cssClass\" class=\"picker-button\" clear>\n {{b.text}}\n </button>\n </div>\n </div>\n <div class=\"picker-columns\">\n <div class=\"picker-above-highlight\"></div>\n <div *ngFor=\"let c of d.columns\" [col]=\"c\" class=\"picker-col\" (ionChange)=\"_colChange($event)\"></div>\n <div class=\"picker-below-highlight\"></div>\n </div>\n </div>\n ",
  174. host: {
  175. 'role': 'dialog'
  176. },
  177. encapsulation: core_1.ViewEncapsulation.None,
  178. },] },
  179. ];
  180. /** @nocollapse */
  181. PickerCmp.ctorParameters = function () { return [
  182. { type: view_controller_1.ViewController, },
  183. { type: core_1.ElementRef, },
  184. { type: config_1.Config, },
  185. { type: gesture_controller_1.GestureController, },
  186. { type: nav_params_1.NavParams, },
  187. { type: core_1.Renderer, },
  188. ]; };
  189. PickerCmp.propDecorators = {
  190. '_cols': [{ type: core_1.ViewChildren, args: [picker_column_1.PickerColumnCmp,] },],
  191. '_keyUp': [{ type: core_1.HostListener, args: ['body:keyup', ['$event'],] },],
  192. };
  193. return PickerCmp;
  194. }());
  195. exports.PickerCmp = PickerCmp;
  196. var pickerIds = -1;
  197. });
  198. //# sourceMappingURL=picker-component.js.map