Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
modal: Add support for event handler on closing a modal.
Ganesh Pawar73533e578a36
diff --git a/static/js/dialog_widget.js b/static/js/dialog_widget.jsindex 6b5968457a7..0379bd76380 100644--- a/static/js/dialog_widget.js+++ b/static/js/dialog_widget.js@@ -1,5 +1,4 @@import $ from "jquery";-import Micromodal from "micromodal";import render_dialog_widget from "../templates/dialog_widget.hbs";@@ -59,8 +58,9 @@ export function show_dialog_spinner() {loading.make_indicator(spinner);}-export function close_modal() {- Micromodal.close("dialog_widget_modal");+// Supports a callback to be called once the modal finishes closing.+export function close_modal(on_hidden_callback) {+ overlays.close_modal("dialog_widget_modal", {micromodal: true, on_hidden: on_hidden_callback});}export function launch(conf) {diff --git a/static/js/overlays.js b/static/js/overlays.jsindex 3d0674d067e..1ef913e0747 100644--- a/static/js/overlays.js+++ b/static/js/overlays.js@@ -179,7 +179,9 @@ export function open_modal(selector, conf) {conf.on_shown();}} else if (animation_name === "mmfadeOut") {- // Equivalent to bootstrap's "hidden.bs.modal" event+ // Equivalent to bootstrap's "hidden.bs.modal" event.+ //+ // Call the on_hidden callback after the modal finishes hiding.micromodal.removeClass("modal--open");if (conf.autoremove) {@@ -254,7 +256,9 @@ export function close_active() {close_overlay(open_overlay_name);}-// If conf.micromodal is true, close a micromodal modal else close a bootstrap modal+// `conf` is an object with the following optional properties:+// * micromodal: true if the modal to close is expected to be micromodal.+// * on_hidden: Callback to run when the modal finishes hiding.export function close_modal(selector, conf) {if (selector === undefined) {blueslip.error("Undefined selector was passed into close_modal");@@ -279,6 +283,20 @@ export function close_modal(selector, conf) {blueslip.debug("close modal: " + selector);if (conf && conf.micromodal) {+ const id_selector = `#${selector}`;+ const micromodal = $(id_selector);++ // On-hidden hooks should typically be registered in+ // overlays.open_modal. However, we offer this alternative+ // mechanism as a convenience for hooks only known when+ // closing the modal.+ micromodal.find(".modal__container").on("animationend", (event) => {+ const animation_name = event.originalEvent.animationName;+ if (animation_name === "mmfadeOut" && conf.on_hidden) {+ conf.on_hidden();+ }+ });+Micromodal.close(selector);return;}