modal.js 1.3 KB

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