action-sheet-component.js 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import { Component, ElementRef, HostListener, Renderer, ViewEncapsulation } from '@angular/core';
  2. import { BLOCK_ALL, GestureController } from '../../gestures/gesture-controller';
  3. import { Config } from '../../config/config';
  4. import { KEY_ESCAPE } from '../../platform/key';
  5. import { NavParams } from '../../navigation/nav-params';
  6. import { ViewController } from '../../navigation/view-controller';
  7. /**
  8. * @hidden
  9. */
  10. var ActionSheetCmp = (function () {
  11. function ActionSheetCmp(_viewCtrl, config, _elementRef, gestureCtrl, params, renderer) {
  12. this._viewCtrl = _viewCtrl;
  13. this._elementRef = _elementRef;
  14. this.gestureBlocker = gestureCtrl.createBlocker(BLOCK_ALL);
  15. this.d = params.data;
  16. this.mode = config.get('mode');
  17. renderer.setElementClass(_elementRef.nativeElement, "action-sheet-" + this.mode, true);
  18. if (this.d.cssClass) {
  19. this.d.cssClass.split(' ').forEach(function (cssClass) {
  20. // Make sure the class isn't whitespace, otherwise it throws exceptions
  21. if (cssClass.trim() !== '')
  22. renderer.setElementClass(_elementRef.nativeElement, cssClass, true);
  23. });
  24. }
  25. this.id = (++actionSheetIds);
  26. if (this.d.title) {
  27. this.hdrId = 'acst-hdr-' + this.id;
  28. }
  29. if (this.d.subTitle) {
  30. this.descId = 'acst-subhdr-' + this.id;
  31. }
  32. }
  33. ActionSheetCmp.prototype.ionViewDidLoad = function () {
  34. var _this = this;
  35. // normalize the data
  36. this.d.buttons = this.d.buttons.map(function (button) {
  37. if (typeof button === 'string') {
  38. button = { text: button };
  39. }
  40. if (!button.cssClass) {
  41. button.cssClass = '';
  42. }
  43. switch (button.role) {
  44. case 'cancel':
  45. _this.cancelButton = button;
  46. return null;
  47. case 'destructive':
  48. button.cssClass = (button.cssClass + ' ' || '') + 'action-sheet-destructive';
  49. break;
  50. case 'selected':
  51. button.cssClass = (button.cssClass + ' ' || '') + 'action-sheet-selected';
  52. break;
  53. }
  54. return button;
  55. }).filter(function (button) { return button !== null; });
  56. };
  57. ActionSheetCmp.prototype.ionViewWillEnter = function () {
  58. this.gestureBlocker.block();
  59. };
  60. ActionSheetCmp.prototype.ionViewDidLeave = function () {
  61. this.gestureBlocker.unblock();
  62. };
  63. ActionSheetCmp.prototype.ionViewDidEnter = function () {
  64. var focusableEle = this._elementRef.nativeElement.querySelector('button');
  65. if (focusableEle) {
  66. focusableEle.focus();
  67. }
  68. this.enabled = true;
  69. };
  70. ActionSheetCmp.prototype.keyUp = function (ev) {
  71. if (this.enabled && ev.keyCode === KEY_ESCAPE && this._viewCtrl.isLast()) {
  72. (void 0) /* console.debug */;
  73. this.bdClick();
  74. }
  75. };
  76. ActionSheetCmp.prototype.click = function (button) {
  77. if (!this.enabled) {
  78. return;
  79. }
  80. var shouldDismiss = true;
  81. if (button.handler) {
  82. // a handler has been provided, execute it
  83. if (button.handler() === false) {
  84. // if the return value of the handler is false then do not dismiss
  85. shouldDismiss = false;
  86. }
  87. }
  88. if (shouldDismiss) {
  89. this.dismiss(button.role);
  90. }
  91. };
  92. ActionSheetCmp.prototype.bdClick = function () {
  93. if (this.enabled && this.d.enableBackdropDismiss) {
  94. if (this.cancelButton) {
  95. this.click(this.cancelButton);
  96. }
  97. else {
  98. this.dismiss('backdrop');
  99. }
  100. }
  101. };
  102. ActionSheetCmp.prototype.dismiss = function (role) {
  103. var opts = {
  104. minClickBlockDuration: 400
  105. };
  106. return this._viewCtrl.dismiss(null, role, opts);
  107. };
  108. ActionSheetCmp.prototype.ngOnDestroy = function () {
  109. (void 0) /* assert */;
  110. this.d = this.cancelButton = null;
  111. this.gestureBlocker.destroy();
  112. };
  113. ActionSheetCmp.decorators = [
  114. { type: Component, args: [{
  115. selector: 'ion-action-sheet',
  116. template: '<ion-backdrop (click)="bdClick()" [class.backdrop-no-tappable]="!d.enableBackdropDismiss"></ion-backdrop>' +
  117. '<div class="action-sheet-wrapper">' +
  118. '<div class="action-sheet-container">' +
  119. '<div class="action-sheet-group">' +
  120. '<div class="action-sheet-title" id="{{hdrId}}" *ngIf="d.title">{{d.title}}</div>' +
  121. '<div class="action-sheet-sub-title" id="{{descId}}" *ngIf="d.subTitle">{{d.subTitle}}</div>' +
  122. '<button ion-button="action-sheet-button" (click)="click(b)" *ngFor="let b of d.buttons" class="disable-hover" [attr.icon-start]="b.icon ? \'\' : null" [ngClass]="b.cssClass">' +
  123. '<ion-icon [name]="b.icon" *ngIf="b.icon" class="action-sheet-icon"></ion-icon>' +
  124. '{{b.text}}' +
  125. '</button>' +
  126. '</div>' +
  127. '<div class="action-sheet-group action-sheet-group-cancel" *ngIf="cancelButton">' +
  128. '<button ion-button="action-sheet-button" (click)="click(cancelButton)" class="action-sheet-cancel disable-hover" [attr.icon-start]="cancelButton.icon ? \'\' : null" [ngClass]="cancelButton.cssClass">' +
  129. '<ion-icon [name]="cancelButton.icon" *ngIf="cancelButton.icon" class="action-sheet-icon"></ion-icon>' +
  130. '{{cancelButton.text}}' +
  131. '</button>' +
  132. '</div>' +
  133. '</div>' +
  134. '</div>',
  135. host: {
  136. 'role': 'dialog',
  137. '[attr.aria-labelledby]': 'hdrId',
  138. '[attr.aria-describedby]': 'descId'
  139. },
  140. encapsulation: ViewEncapsulation.None,
  141. },] },
  142. ];
  143. /** @nocollapse */
  144. ActionSheetCmp.ctorParameters = function () { return [
  145. { type: ViewController, },
  146. { type: Config, },
  147. { type: ElementRef, },
  148. { type: GestureController, },
  149. { type: NavParams, },
  150. { type: Renderer, },
  151. ]; };
  152. ActionSheetCmp.propDecorators = {
  153. 'keyUp': [{ type: HostListener, args: ['body:keyup', ['$event'],] },],
  154. };
  155. return ActionSheetCmp;
  156. }());
  157. export { ActionSheetCmp };
  158. var actionSheetIds = -1;
  159. //# sourceMappingURL=action-sheet-component.js.map