a zip code crypto-currency system good for red ONLY

select.js 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  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", "@angular/core", "@angular/forms", "../action-sheet/action-sheet", "../alert/alert", "../popover/popover", "../app/app", "../../config/config", "../../navigation/deep-linker", "../../util/form", "../../util/base-input", "../../util/util", "../item/item", "../option/option", "./select-popover-component"], factory);
  18. }
  19. })(function (require, exports) {
  20. "use strict";
  21. Object.defineProperty(exports, "__esModule", { value: true });
  22. var core_1 = require("@angular/core");
  23. var forms_1 = require("@angular/forms");
  24. var action_sheet_1 = require("../action-sheet/action-sheet");
  25. var alert_1 = require("../alert/alert");
  26. var popover_1 = require("../popover/popover");
  27. var app_1 = require("../app/app");
  28. var config_1 = require("../../config/config");
  29. var deep_linker_1 = require("../../navigation/deep-linker");
  30. var form_1 = require("../../util/form");
  31. var base_input_1 = require("../../util/base-input");
  32. var util_1 = require("../../util/util");
  33. var item_1 = require("../item/item");
  34. var option_1 = require("../option/option");
  35. var select_popover_component_1 = require("./select-popover-component");
  36. /**
  37. * @name Select
  38. * @description
  39. * The `ion-select` component is similar to an HTML `<select>` element, however,
  40. * Ionic's select component makes it easier for users to sort through and select
  41. * the preferred option or options. When users tap the select component, a
  42. * dialog will appear with all of the options in a large, easy to select list
  43. * for users.
  44. *
  45. * The select component takes child `ion-option` components. If `ion-option` is not
  46. * given a `value` attribute then it will use its text as the value.
  47. *
  48. * If `ngModel` is bound to `ion-select`, the selected value will be based on the
  49. * bound value of the model. Otherwise, the `selected` attribute can be used on
  50. * `ion-option` components.
  51. *
  52. * ### Interfaces
  53. *
  54. * By default, the `ion-select` uses the {@link ../../alert/AlertController AlertController API}
  55. * to open up the overlay of options in an alert. The interface can be changed to use the
  56. * {@link ../../action-sheet/ActionSheetController ActionSheetController API} or
  57. * {@link ../../popover/PopoverController PopoverController API} by passing `action-sheet` or `popover`,
  58. * respectively, to the `interface` property. Read on to the other sections for the limitations
  59. * of the different interfaces.
  60. *
  61. * ### Single Value: Radio Buttons
  62. *
  63. * The standard `ion-select` component allows the user to select only one
  64. * option. When selecting only one option the alert interface presents users with
  65. * a radio button styled list of options. The action sheet interface can only be
  66. * used with a single value select. If the number of options exceed 6, it will
  67. * use the `alert` interface even if `action-sheet` is passed. The `ion-select`
  68. * component's value receives the value of the selected option's value.
  69. *
  70. * ```html
  71. * <ion-item>
  72. * <ion-label>Gender</ion-label>
  73. * <ion-select [(ngModel)]="gender">
  74. * <ion-option value="f">Female</ion-option>
  75. * <ion-option value="m">Male</ion-option>
  76. * </ion-select>
  77. * </ion-item>
  78. * ```
  79. *
  80. * ### Multiple Value: Checkboxes
  81. *
  82. * By adding the `multiple="true"` attribute to `ion-select`, users are able
  83. * to select multiple options. When multiple options can be selected, the alert
  84. * overlay presents users with a checkbox styled list of options. The
  85. * `ion-select multiple="true"` component's value receives an array of all the
  86. * selected option values. In the example below, because each option is not given
  87. * a `value`, then it'll use its text as the value instead.
  88. *
  89. * Note: the `action-sheet` and `popover` interfaces will not work with a multi-value select.
  90. *
  91. * ```html
  92. * <ion-item>
  93. * <ion-label>Toppings</ion-label>
  94. * <ion-select [(ngModel)]="toppings" multiple="true">
  95. * <ion-option>Bacon</ion-option>
  96. * <ion-option>Black Olives</ion-option>
  97. * <ion-option>Extra Cheese</ion-option>
  98. * <ion-option>Mushrooms</ion-option>
  99. * <ion-option>Pepperoni</ion-option>
  100. * <ion-option>Sausage</ion-option>
  101. * </ion-select>
  102. * </ion-item>
  103. * ```
  104. *
  105. * ### Select Buttons
  106. * By default, the two buttons read `Cancel` and `OK`. Each button's text
  107. * can be customized using the `cancelText` and `okText` attributes:
  108. *
  109. * ```html
  110. * <ion-select okText="Okay" cancelText="Dismiss">
  111. * ...
  112. * </ion-select>
  113. * ```
  114. *
  115. * The `action-sheet` and `popover` interfaces do not have an `OK` button, clicking
  116. * on any of the options will automatically close the overlay and select
  117. * that value.
  118. *
  119. * ### Select Options
  120. *
  121. * Since `ion-select` uses the `Alert`, `Action Sheet` and `Popover` interfaces, options can be
  122. * passed to these components through the `selectOptions` property. This can be used
  123. * to pass a custom title, subtitle, css class, and more. See the
  124. * {@link ../../alert/AlertController/#create AlertController API docs},
  125. * {@link ../../action-sheet/ActionSheetController/#create ActionSheetController API docs}, and
  126. * {@link ../../popover/PopoverController/#create PopoverController API docs}
  127. * for the properties that each interface accepts.
  128. *
  129. * For example, to change the `mode` of the overlay, pass it into `selectOptions`.
  130. *
  131. * ```html
  132. * <ion-select [selectOptions]="selectOptions">
  133. * ...
  134. * </ion-select>
  135. * ```
  136. *
  137. * ```ts
  138. * this.selectOptions = {
  139. * title: 'Pizza Toppings',
  140. * subTitle: 'Select your toppings',
  141. * mode: 'md'
  142. * };
  143. * ```
  144. *
  145. * ### Object Value References
  146. *
  147. * When using objects for select values, it is possible for the identities of these objects to
  148. * change if they are coming from a server or database, while the selected value's identity
  149. * remains the same. For example, this can occur when an existing record with the desired object value
  150. * is loaded into the select, but the newly retrieved select options now have different identities. This will
  151. * result in the select appearing to have no value at all, even though the original selection in still intact.
  152. *
  153. * Using the `compareWith` `Input` is the solution to this problem
  154. *
  155. * ```html
  156. * <ion-item>
  157. * <ion-label>Employee</ion-label>
  158. * <ion-select [(ngModel)]="employee" [compareWith]="compareFn">
  159. * <ion-option *ngFor="let employee of employees" [value]="employee">{{employee.name}}</ion-option>
  160. * </ion-select>
  161. * </ion-item>
  162. * ```
  163. *
  164. * ```ts
  165. * compareFn(e1: Employee, e2: Employee): boolean {
  166. * return e1 && e2 ? e1.id === e2.id : e1 === e2;
  167. * }
  168. * ```
  169. *
  170. * @demo /docs/demos/src/select/
  171. */
  172. var Select = (function (_super) {
  173. __extends(Select, _super);
  174. function Select(_app, form, config, elementRef, renderer, item, deepLinker) {
  175. var _this = _super.call(this, config, elementRef, renderer, 'select', [], form, item, null) || this;
  176. _this._app = _app;
  177. _this.config = config;
  178. _this.deepLinker = deepLinker;
  179. _this._multi = false;
  180. _this._texts = [];
  181. _this._text = '';
  182. _this._compareWith = util_1.isCheckedProperty;
  183. /**
  184. * @input {string} The text to display on the cancel button. Default: `Cancel`.
  185. */
  186. _this.cancelText = 'Cancel';
  187. /**
  188. * @input {string} The text to display on the ok button. Default: `OK`.
  189. */
  190. _this.okText = 'OK';
  191. /**
  192. * @input {any} Any additional options that the `alert` or `action-sheet` interface can take.
  193. * See the [AlertController API docs](../../alert/AlertController/#create) and the
  194. * [ActionSheetController API docs](../../action-sheet/ActionSheetController/#create) for the
  195. * create options for each interface.
  196. */
  197. _this.selectOptions = {};
  198. /**
  199. * @input {string} The interface the select should use: `action-sheet`, `popover` or `alert`. Default: `alert`.
  200. */
  201. _this.interface = '';
  202. /**
  203. * @input {string} The text to display instead of the selected option's value.
  204. */
  205. _this.selectedText = '';
  206. /**
  207. * @output {any} Emitted when the selection was cancelled.
  208. */
  209. _this.ionCancel = new core_1.EventEmitter();
  210. return _this;
  211. }
  212. Object.defineProperty(Select.prototype, "compareWith", {
  213. /**
  214. * @input {Function} The function that will be called to compare object values
  215. */
  216. set: function (fn) {
  217. if (typeof fn !== 'function') {
  218. throw new Error("compareWith must be a function, but received " + JSON.stringify(fn));
  219. }
  220. this._compareWith = fn;
  221. },
  222. enumerable: true,
  223. configurable: true
  224. });
  225. Select.prototype._click = function (ev) {
  226. ev.preventDefault();
  227. ev.stopPropagation();
  228. this.open(ev);
  229. };
  230. Select.prototype._keyup = function () {
  231. this.open();
  232. };
  233. /**
  234. * @hidden
  235. */
  236. Select.prototype.getValues = function () {
  237. var values = Array.isArray(this._value) ? this._value : [this._value];
  238. (void 0) /* assert */;
  239. return values;
  240. };
  241. /**
  242. * Open the select interface.
  243. */
  244. Select.prototype.open = function (ev) {
  245. var _this = this;
  246. if (this.isFocus() || this._disabled) {
  247. return;
  248. }
  249. (void 0) /* console.debug */;
  250. // the user may have assigned some options specifically for the alert
  251. var selectOptions = util_1.deepCopy(this.selectOptions);
  252. // make sure their buttons array is removed from the options
  253. // and we create a new array for the alert's two buttons
  254. selectOptions.buttons = [{
  255. text: this.cancelText,
  256. role: 'cancel',
  257. handler: function () {
  258. _this.ionCancel.emit(_this);
  259. }
  260. }];
  261. // if the selectOptions didn't provide a title then use the label's text
  262. if (!selectOptions.title && this._item) {
  263. selectOptions.title = this._item.getLabelText();
  264. }
  265. var options = this._options.toArray();
  266. if ((this.interface === 'action-sheet' || this.interface === 'popover') && this._multi) {
  267. console.warn('Interface cannot be "' + this.interface + '" with a multi-value select. Using the "alert" interface.');
  268. this.interface = 'alert';
  269. }
  270. if (this.interface === 'popover' && !ev) {
  271. console.warn('Interface cannot be "popover" without UIEvent.');
  272. this.interface = 'alert';
  273. }
  274. var overlay;
  275. if (this.interface === 'action-sheet') {
  276. selectOptions.buttons = selectOptions.buttons.concat(options.map(function (input) {
  277. return {
  278. role: (input.selected ? 'selected' : ''),
  279. text: input.text,
  280. handler: function () {
  281. _this.value = input.value;
  282. input.ionSelect.emit(input.value);
  283. }
  284. };
  285. }));
  286. var selectCssClass = 'select-action-sheet';
  287. // If the user passed a cssClass for the select, add it
  288. selectCssClass += selectOptions.cssClass ? ' ' + selectOptions.cssClass : '';
  289. selectOptions.cssClass = selectCssClass;
  290. overlay = new action_sheet_1.ActionSheet(this._app, selectOptions, this.config);
  291. }
  292. else if (this.interface === 'popover') {
  293. var popoverOptions = options.map(function (input) { return ({
  294. text: input.text,
  295. checked: input.selected,
  296. disabled: input.disabled,
  297. value: input.value,
  298. handler: function () {
  299. _this.value = input.value;
  300. input.ionSelect.emit(input.value);
  301. }
  302. }); });
  303. var popoverCssClass = 'select-popover';
  304. // If the user passed a cssClass for the select, add it
  305. popoverCssClass += selectOptions.cssClass ? ' ' + selectOptions.cssClass : '';
  306. overlay = new popover_1.Popover(this._app, select_popover_component_1.SelectPopover, {
  307. options: popoverOptions
  308. }, {
  309. cssClass: popoverCssClass
  310. }, this.config, this.deepLinker);
  311. // ev.target is readonly.
  312. // place popover regarding to ion-select instead of .button-inner
  313. Object.defineProperty(ev, 'target', { value: ev.currentTarget });
  314. selectOptions.ev = ev;
  315. }
  316. else {
  317. // default to use the alert interface
  318. this.interface = 'alert';
  319. // user cannot provide inputs from selectOptions
  320. // alert inputs must be created by ionic from ion-options
  321. selectOptions.inputs = this._options.map(function (input) {
  322. return {
  323. type: (_this._multi ? 'checkbox' : 'radio'),
  324. label: input.text,
  325. value: input.value,
  326. checked: input.selected,
  327. disabled: input.disabled,
  328. handler: function (selectedOption) {
  329. // Only emit the select event if it is being checked
  330. // For multi selects this won't emit when unchecking
  331. if (selectedOption.checked) {
  332. input.ionSelect.emit(input.value);
  333. }
  334. }
  335. };
  336. });
  337. var selectCssClass_1 = 'select-alert';
  338. // create the alert instance from our built up selectOptions
  339. overlay = new alert_1.Alert(this._app, selectOptions, this.config);
  340. if (this._multi) {
  341. // use checkboxes
  342. selectCssClass_1 += ' multiple-select-alert';
  343. }
  344. else {
  345. // use radio buttons
  346. selectCssClass_1 += ' single-select-alert';
  347. }
  348. // If the user passed a cssClass for the select, add it
  349. selectCssClass_1 += selectOptions.cssClass ? ' ' + selectOptions.cssClass : '';
  350. overlay.setCssClass(selectCssClass_1);
  351. overlay.addButton({
  352. text: this.okText,
  353. handler: function (selectedValues) { return _this.value = selectedValues; }
  354. });
  355. }
  356. overlay.present(selectOptions);
  357. this._fireFocus();
  358. overlay.onDidDismiss(function () {
  359. _this._fireBlur();
  360. _this._overlay = undefined;
  361. });
  362. this._overlay = overlay;
  363. };
  364. /**
  365. * Close the select interface.
  366. */
  367. Select.prototype.close = function () {
  368. if (!this._overlay || !this.isFocus()) {
  369. return;
  370. }
  371. return this._overlay.dismiss();
  372. };
  373. Object.defineProperty(Select.prototype, "multiple", {
  374. /**
  375. * @input {boolean} If true, the element can accept multiple values.
  376. */
  377. get: function () {
  378. return this._multi;
  379. },
  380. set: function (val) {
  381. this._multi = util_1.isTrueProperty(val);
  382. },
  383. enumerable: true,
  384. configurable: true
  385. });
  386. Object.defineProperty(Select.prototype, "text", {
  387. /**
  388. * @hidden
  389. */
  390. get: function () {
  391. return (this._multi ? this._texts : this._texts.join());
  392. },
  393. enumerable: true,
  394. configurable: true
  395. });
  396. Object.defineProperty(Select.prototype, "options", {
  397. /**
  398. * @private
  399. */
  400. set: function (val) {
  401. this._options = val;
  402. var values = this.getValues();
  403. if (values.length === 0) {
  404. // there are no values set at this point
  405. // so check to see who should be selected
  406. // we use writeValue() because we don't want to update ngModel
  407. this.writeValue(val.filter(function (o) { return o.selected; }).map(function (o) { return o.value; }));
  408. }
  409. else {
  410. this._updateText();
  411. }
  412. },
  413. enumerable: true,
  414. configurable: true
  415. });
  416. Select.prototype._inputShouldChange = function (val) {
  417. return !util_1.deepEqual(this._value, val);
  418. };
  419. /**
  420. * TODO: REMOVE THIS
  421. * @hidden
  422. */
  423. Select.prototype._inputChangeEvent = function () {
  424. return this.value;
  425. };
  426. /**
  427. * @hidden
  428. */
  429. Select.prototype._updateText = function () {
  430. var _this = this;
  431. this._texts.length = 0;
  432. if (this._options) {
  433. this._options.forEach(function (option) {
  434. // check this option if the option's value is in the values array
  435. option.selected = _this.getValues().some(function (selectValue) {
  436. return _this._compareWith(selectValue, option.value);
  437. });
  438. if (option.selected) {
  439. _this._texts.push(option.text);
  440. }
  441. });
  442. }
  443. this._text = this._texts.join(', ');
  444. };
  445. /**
  446. * @hidden
  447. */
  448. Select.prototype._inputUpdated = function () {
  449. this._updateText();
  450. _super.prototype._inputUpdated.call(this);
  451. };
  452. Select.decorators = [
  453. { type: core_1.Component, args: [{
  454. selector: 'ion-select',
  455. template: '<div *ngIf="!_text" class="select-placeholder select-text">{{placeholder}}</div>' +
  456. '<div *ngIf="_text" class="select-text">{{selectedText || _text}}</div>' +
  457. '<div class="select-icon">' +
  458. '<div class="select-icon-inner"></div>' +
  459. '</div>' +
  460. '<button aria-haspopup="true" ' +
  461. 'type="button" ' +
  462. '[id]="id" ' +
  463. 'ion-button="item-cover" ' +
  464. '[attr.aria-labelledby]="_labelId" ' +
  465. '[attr.aria-disabled]="_disabled" ' +
  466. 'class="item-cover">' +
  467. '</button>',
  468. host: {
  469. '[class.select-disabled]': '_disabled'
  470. },
  471. providers: [{ provide: forms_1.NG_VALUE_ACCESSOR, useExisting: Select, multi: true }],
  472. encapsulation: core_1.ViewEncapsulation.None,
  473. },] },
  474. ];
  475. /** @nocollapse */
  476. Select.ctorParameters = function () { return [
  477. { type: app_1.App, },
  478. { type: form_1.Form, },
  479. { type: config_1.Config, },
  480. { type: core_1.ElementRef, },
  481. { type: core_1.Renderer, },
  482. { type: item_1.Item, decorators: [{ type: core_1.Optional },] },
  483. { type: deep_linker_1.DeepLinker, },
  484. ]; };
  485. Select.propDecorators = {
  486. 'cancelText': [{ type: core_1.Input },],
  487. 'okText': [{ type: core_1.Input },],
  488. 'placeholder': [{ type: core_1.Input },],
  489. 'selectOptions': [{ type: core_1.Input },],
  490. 'interface': [{ type: core_1.Input },],
  491. 'selectedText': [{ type: core_1.Input },],
  492. 'compareWith': [{ type: core_1.Input },],
  493. 'ionCancel': [{ type: core_1.Output },],
  494. '_click': [{ type: core_1.HostListener, args: ['click', ['$event'],] },],
  495. '_keyup': [{ type: core_1.HostListener, args: ['keyup.space',] },],
  496. 'multiple': [{ type: core_1.Input },],
  497. 'options': [{ type: core_1.ContentChildren, args: [option_1.Option,] },],
  498. };
  499. return Select;
  500. }(base_input_1.BaseInput));
  501. exports.Select = Select;
  502. });
  503. //# sourceMappingURL=select.js.map