modal.js 731 B

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