toast-component.js 3.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { Component, ElementRef, Renderer } from '@angular/core';
  2. import { Config } from '../../config/config';
  3. import { NavParams } from '../../navigation/nav-params';
  4. import { ViewController } from '../../navigation/view-controller';
  5. /**
  6. * @hidden
  7. */
  8. var ToastCmp = (function () {
  9. function ToastCmp(_viewCtrl, _config, _elementRef, params, renderer) {
  10. this._viewCtrl = _viewCtrl;
  11. this._config = _config;
  12. this._elementRef = _elementRef;
  13. this.dismissTimeout = undefined;
  14. renderer.setElementClass(_elementRef.nativeElement, "toast-" + _config.get('mode'), true);
  15. this.d = params.data;
  16. if (this.d.cssClass) {
  17. this.d.cssClass.split(' ').forEach(function (cssClass) {
  18. // Make sure the class isn't whitespace, otherwise it throws exceptions
  19. if (cssClass.trim() !== '')
  20. renderer.setElementClass(_elementRef.nativeElement, cssClass, true);
  21. });
  22. }
  23. this.id = (++toastIds);
  24. if (this.d.message) {
  25. this.hdrId = 'toast-hdr-' + this.id;
  26. }
  27. }
  28. ToastCmp.prototype.ngAfterViewInit = function () {
  29. var _this = this;
  30. // if there's a `duration` set, automatically dismiss.
  31. if (this.d.duration) {
  32. this.dismissTimeout = setTimeout(function () {
  33. _this.dismiss('backdrop');
  34. }, this.d.duration);
  35. }
  36. this.enabled = true;
  37. };
  38. ToastCmp.prototype.ionViewDidEnter = function () {
  39. var activeElement = document.activeElement;
  40. if (activeElement) {
  41. activeElement.blur();
  42. }
  43. var focusableEle = this._elementRef.nativeElement.querySelector('button');
  44. if (focusableEle) {
  45. focusableEle.focus();
  46. }
  47. };
  48. ToastCmp.prototype.cbClick = function () {
  49. if (this.enabled) {
  50. this.dismiss('close');
  51. }
  52. };
  53. ToastCmp.prototype.dismiss = function (role) {
  54. clearTimeout(this.dismissTimeout);
  55. this.dismissTimeout = undefined;
  56. return this._viewCtrl.dismiss(null, role, { disableApp: false });
  57. };
  58. ToastCmp.decorators = [
  59. { type: Component, args: [{
  60. selector: 'ion-toast',
  61. template: '<div class="toast-wrapper" ' +
  62. '[class.toast-bottom]="d.position === \'bottom\'" ' +
  63. '[class.toast-middle]="d.position === \'middle\'" ' +
  64. '[class.toast-top]="d.position === \'top\'"> ' +
  65. '<div class="toast-container"> ' +
  66. '<div class="toast-message" id="{{hdrId}}" *ngIf="d.message">{{d.message}}</div> ' +
  67. '<button ion-button clear class="toast-button" *ngIf="d.showCloseButton" (click)="cbClick()"> ' +
  68. '{{ d.closeButtonText || \'Close\' }} ' +
  69. '</button> ' +
  70. '</div> ' +
  71. '</div>',
  72. host: {
  73. 'role': 'dialog',
  74. '[attr.aria-labelledby]': 'hdrId',
  75. '[attr.aria-describedby]': 'descId',
  76. },
  77. },] },
  78. ];
  79. /** @nocollapse */
  80. ToastCmp.ctorParameters = function () { return [
  81. { type: ViewController, },
  82. { type: Config, },
  83. { type: ElementRef, },
  84. { type: NavParams, },
  85. { type: Renderer, },
  86. ]; };
  87. return ToastCmp;
  88. }());
  89. export { ToastCmp };
  90. var toastIds = -1;
  91. //# sourceMappingURL=toast-component.js.map