modal.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const closedValue = null;
  2. window.Modal = new (class {
  3. constructor() {
  4. this._currentModal = new ReactiveVar(closedValue);
  5. this._onCloseGoTo = '';
  6. this._isWideModal = false;
  7. }
  8. getHeaderName() {
  9. const currentModal = this._currentModal.get();
  10. return currentModal && currentModal.header;
  11. }
  12. getTemplateName() {
  13. const currentModal = this._currentModal.get();
  14. return currentModal && currentModal.modalName;
  15. }
  16. isOpen() {
  17. return this.getTemplateName() !== closedValue;
  18. }
  19. isWide() {
  20. return this._isWideModal;
  21. }
  22. close() {
  23. this._currentModal.set(closedValue);
  24. if (this._onCloseGoTo) {
  25. FlowRouter.go(this._onCloseGoTo);
  26. }
  27. }
  28. openWide(modalName, { header = '', onCloseGoTo = '' } = {}) {
  29. this._currentModal.set({ header, modalName });
  30. this._onCloseGoTo = onCloseGoTo;
  31. this._isWideModal = true;
  32. }
  33. open(modalName, { header = '', onCloseGoTo = '' } = {}) {
  34. this._currentModal.set({ header, modalName });
  35. this._onCloseGoTo = onCloseGoTo;
  36. }
  37. })();
  38. Blaze.registerHelper('Modal', Modal);
  39. EscapeActions.register(
  40. 'modalWindow',
  41. () => Modal.close(),
  42. () => Modal.isOpen(),
  43. { noClickEscapeOn: '.modal-container,.model-content' },
  44. );