loading.js 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { isPresent } from '../../util/util';
  2. import { PORTAL_LOADING } from '../app/app-constants';
  3. import { LoadingCmp } from './loading-component';
  4. import { LoadingMdPopIn, LoadingMdPopOut, LoadingPopIn, LoadingPopOut, LoadingWpPopIn, LoadingWpPopOut } from './loading-transitions';
  5. import { ViewController } from '../../navigation/view-controller';
  6. /**
  7. * @hidden
  8. */
  9. export class Loading extends ViewController {
  10. constructor(app, opts = {}, config) {
  11. opts.showBackdrop = isPresent(opts.showBackdrop) ? !!opts.showBackdrop : true;
  12. opts.enableBackdropDismiss = isPresent(opts.enableBackdropDismiss) ? !!opts.enableBackdropDismiss : false;
  13. opts.dismissOnPageChange = isPresent(opts.dismissOnPageChange) ? !!opts.dismissOnPageChange : false;
  14. super(LoadingCmp, opts, null);
  15. this._app = app;
  16. this.isOverlay = true;
  17. config.setTransition('loading-pop-in', LoadingPopIn);
  18. config.setTransition('loading-pop-out', LoadingPopOut);
  19. config.setTransition('loading-md-pop-in', LoadingMdPopIn);
  20. config.setTransition('loading-md-pop-out', LoadingMdPopOut);
  21. config.setTransition('loading-wp-pop-in', LoadingWpPopIn);
  22. config.setTransition('loading-wp-pop-out', LoadingWpPopOut);
  23. }
  24. /**
  25. * @hidden
  26. */
  27. getTransitionName(direction) {
  28. let key = (direction === 'back' ? 'loadingLeave' : 'loadingEnter');
  29. return this._nav && this._nav.config.get(key);
  30. }
  31. /**
  32. * @param {string} content sets the html content for the loading indicator.
  33. */
  34. setContent(content) {
  35. this.data.content = content;
  36. return this;
  37. }
  38. /**
  39. * @param {string} spinner sets the name of the SVG spinner for the loading indicator.
  40. */
  41. setSpinner(spinner) {
  42. this.data.spinner = spinner;
  43. return this;
  44. }
  45. /**
  46. * @param {string} cssClass sets additional classes for custom styles, separated by spaces.
  47. */
  48. setCssClass(cssClass) {
  49. this.data.cssClass = cssClass;
  50. return this;
  51. }
  52. /**
  53. * @param {boolean} showBackdrop sets whether to show the backdrop.
  54. */
  55. setShowBackdrop(showBackdrop) {
  56. this.data.showBackdrop = showBackdrop;
  57. return this;
  58. }
  59. /**
  60. * @param {number} dur how many milliseconds to wait before hiding the indicator.
  61. */
  62. setDuration(dur) {
  63. this.data.duration = dur;
  64. return this;
  65. }
  66. /**
  67. * Present the loading instance.
  68. *
  69. * @param {NavOptions} [navOptions={}] Nav options to go with this transition.
  70. * @returns {Promise} Returns a promise which is resolved when the transition has completed.
  71. */
  72. present(navOptions = {}) {
  73. return this._app.present(this, navOptions, PORTAL_LOADING);
  74. }
  75. /**
  76. * Dismiss all loading components which have been presented.
  77. */
  78. dismissAll() {
  79. this._nav && this._nav.popAll();
  80. }
  81. }
  82. //# sourceMappingURL=loading.js.map