modal.js 937 B

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