Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
overlays: Remove unused support for Bootstrap modals.
Anders Kaseorg35778fa1009c
diff --git a/static/js/click_handlers.js b/static/js/click_handlers.jsindex f95f1a6d7f1..e3c06b14be0 100644--- a/static/js/click_handlers.js+++ b/static/js/click_handlers.js@@ -668,10 +668,6 @@ export function initialize() {settings_toggle.toggle_org_setting_collapse();});- $(".organization-box").on("show.bs.modal", () => {- popovers.hide_all();- });-$("body").on("click", ".reload_link", () => {window.location.reload();});@@ -857,15 +853,6 @@ export function initialize() {e.stopPropagation();});- $("body").on("hidden.bs.modal", () => {- // Enable mouse events for the background as the modal closes.- overlays.enable_background_mouse_events();-- // TODO: Remove this once Bootstrap is upgraded.- // See: https://github.com/zulip/zulip/pull/18720- $(".modal.in").removeClass("in");- });-// GEAR MENU$("body").on("click", ".change-language-spectator, .language_selection_widget button", (e) => {@@ -940,10 +927,8 @@ export function initialize() {// state.!$(e.target).closest(".overlay").length &&!$(e.target).closest(".popover").length &&- !$(e.target).closest(".modal").length &&!$(e.target).closest(".micromodal").length &&!$(e.target).closest("[data-tippy-root]").length &&- !$(e.target).closest(".modal-backdrop").length &&!$(e.target).closest(".enter_sends").length &&$(e.target).closest("body").length) {diff --git a/static/js/dialog_widget.js b/static/js/dialog_widget.jsindex 17b903a6222..750e3fae6ac 100644--- a/static/js/dialog_widget.js+++ b/static/js/dialog_widget.js@@ -61,7 +61,7 @@ export function show_dialog_spinner() {// 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});+ overlays.close_modal("dialog_widget_modal", {on_hidden: on_hidden_callback});}export function launch(conf) {@@ -142,7 +142,6 @@ export function launch(conf) {overlays.open_modal("dialog_widget_modal", {autoremove: true,- micromodal: true,on_show: () => {if (conf.focus_submit_on_open) {$submit_button.trigger("focus");diff --git a/static/js/overlays.js b/static/js/overlays.jsindex 8a56d6069d9..d8b832644f7 100644--- a/static/js/overlays.js+++ b/static/js/overlays.js@@ -20,8 +20,7 @@ export function is_active() {}export function is_modal_open() {- // Check for both Bootstrap and Micromodal modals.- return $(".modal").hasClass("in") || $(".micromodal").hasClass("modal--open");+ return $(".micromodal").hasClass("modal--open");}export function is_overlay_or_modal_open() {@@ -48,36 +47,14 @@ export function drafts_open() {return open_overlay_name === "drafts";}-// To address bugs where mouse might apply to the streams/settings-// overlays underneath an open modal within those settings UI, we add-// this inline style to 'div.overlay.show', overriding the-// "pointer-events: all" style in app_components.css.-//-// This is kinda hacky; it only works for modals within overlays, and-// we need to make sure it gets re-enabled when the modal closes.-export function disable_background_mouse_events() {- $("div.overlay.show").attr("style", "pointer-events: none");-}--// This removes only the inline-style of the element that-// was added in disable_background_mouse_events and-// enables the background mouse events.-export function enable_background_mouse_events() {- $("div.overlay.show").attr("style", null);-}-export function active_modal() {if (!is_modal_open()) {blueslip.error("Programming error — Called active_modal when there is no modal open");return undefined;}- // Check for Micromodal modals.const $micromodal = $(".micromodal.modal--open");- if ($micromodal.length) {- return `#${CSS.escape($micromodal.attr("id"))}`;- }- return `#${CSS.escape($(".modal.in").attr("id"))}`;+ return `#${CSS.escape($micromodal.attr("id"))}`;}export function open_overlay(opts) {@@ -125,27 +102,21 @@ export function open_overlay(opts) {// If conf.autoremove is true, the modal element will be removed from the DOM// once the modal is hidden.-// If conf.micromodal is true, open a micromodal modal else open a bootstrap modal// conf also accepts the following optional properties:// on_show: Callback to run when the modal is triggered to show.// on_shown: Callback to run when the modal is shown.// on_hide: Callback to run when the modal is triggered to hide.// on_hidden: Callback to run when the modal is hidden.-export function open_modal(selector, conf) {+export function open_modal(selector, conf = {}) {if (selector === undefined) {blueslip.error("Undefined selector was passed into open_modal");return;}- if ((!conf || (conf && !conf.micromodal)) && selector[0] !== "#") {- blueslip.error("Non-id-based selector passed in to open_modal: " + selector);- return;- }-// Don't accept hash-based selector to enforce modals to have unique ids and// since micromodal doesn't accept hash based selectors.- if (conf && conf.micromodal && selector[0] === "#") {- blueslip.error("hash-based selector passed in to micromodal-based open_modal: " + selector);+ if (selector[0] === "#") {+ blueslip.error("hash-based selector passed in to open_modal: " + selector);return;}@@ -156,69 +127,43 @@ export function open_modal(selector, conf) {blueslip.debug("open modal: " + selector);- // Show a modal using micromodal.- if (conf && conf.micromodal) {- // Micromodal gets elements using the getElementById DOM function- // which doesn't require the hash. We add it manually here.- const id_selector = `#${selector}`;- const $micromodal = $(id_selector);-- $micromodal.find(".modal__container").on("animationend", (event) => {- // Micromodal doesn't support Bootstrap-style `shown.bs.modal` and- // `hidden.bs.modal` events. We workaround this by using the animationName- // from the native event and running the required functions after the- // animation ends.- const animation_name = event.originalEvent.animationName;- if (animation_name === "mmfadeIn") {- // Equivalent to bootstrap's "shown.bs.modal" event-- // Micromodal adds the is-open class before the modal animation- // is complete, which isn't really helpful since a modal is open after the- // animation is complete. So, we manually add a class after the- // animation is complete.- $micromodal.addClass("modal--open");- $micromodal.removeClass("modal--opening");-- if (conf.on_shown) {- conf.on_shown();- }- } else if (animation_name === "mmfadeOut") {- // 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) {- $micromodal.remove();- }- if (conf.on_hidden) {- conf.on_hidden();- }+ // Micromodal gets elements using the getElementById DOM function+ // which doesn't require the hash. We add it manually here.+ const id_selector = `#${selector}`;+ const $micromodal = $(id_selector);++ $micromodal.find(".modal__container").on("animationend", (event) => {+ const animation_name = event.originalEvent.animationName;+ if (animation_name === "mmfadeIn") {+ // Micromodal adds the is-open class before the modal animation+ // is complete, which isn't really helpful since a modal is open after the+ // animation is complete. So, we manually add a class after the+ // animation is complete.+ $micromodal.addClass("modal--open");+ $micromodal.removeClass("modal--opening");++ if (conf.on_shown) {+ conf.on_shown();}- });-- Micromodal.show(selector, {- disableFocus: true,- openClass: "modal--opening",- onShow: conf?.on_show,- onClose: conf?.on_hide,- });- return;- }+ } else if (animation_name === "mmfadeOut") {+ // Call the on_hidden callback after the modal finishes hiding.- const $elem = $(selector).expectOne();- $elem.modal("show").attr("aria-hidden", false);- // Disable background mouse events when modal is active- disable_background_mouse_events();- // Remove previous alert messages from modal, if exists.- $elem.find(".alert").hide();- $elem.find(".alert-notification").html("");-- if (conf && conf.autoremove) {- $elem.on("hidden.bs.modal", () => {- $elem.remove();- });- }+ $micromodal.removeClass("modal--open");+ if (conf.autoremove) {+ $micromodal.remove();+ }+ if (conf.on_hidden) {+ conf.on_hidden();+ }+ }+ });++ Micromodal.show(selector, {+ disableFocus: true,+ openClass: "modal--opening",+ onShow: conf?.on_show,+ onClose: conf?.on_hide,+ });}export function close_overlay(name) {@@ -261,9 +206,8 @@ export function close_active() {}// `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) {+export function close_modal(selector, conf = {}) {if (selector === undefined) {blueslip.error("Undefined selector was passed into close_modal");return;@@ -274,10 +218,7 @@ export function close_modal(selector, conf) {return;}- if (- (!conf && active_modal() !== selector) ||- (conf && conf.micromodal && active_modal() !== `#${selector}`)- ) {+ if (active_modal() !== `#${selector}`) {blueslip.error("Trying to close " + selector + " modal when " + active_modal() + " is open.",);@@ -286,27 +227,21 @@ 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;- }+ 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();+ }+ });- const $elem = $(selector).expectOne();- $elem.modal("hide").attr("aria-hidden", true);+ Micromodal.close(selector);}export function close_active_modal() {@@ -315,14 +250,8 @@ export function close_active_modal() {return;}- // Check for Micromodal modals.const $micromodal = $(".micromodal.modal--open");- if ($micromodal.length) {- Micromodal.close(`${CSS.escape($micromodal.attr("id"))}`);- return;- }-- $(".modal.in").modal("hide").attr("aria-hidden", true);+ Micromodal.close(`${CSS.escape($micromodal.attr("id"))}`);}export function close_for_hash_change() {diff --git a/static/js/settings.js b/static/js/settings.jsindex 0e607830ebf..e8929e1485a 100644--- a/static/js/settings.js+++ b/static/js/settings.js@@ -27,7 +27,7 @@ $(() => {if (!overlays.is_modal_open()) {return;}- if ($(e.target).closest(".modal, .micromodal").length > 0) {+ if ($(e.target).closest(".micromodal").length > 0) {return;}e.preventDefault();diff --git a/static/js/settings_account.js b/static/js/settings_account.jsindex 92d85e1477e..5f43df232b0 100644--- a/static/js/settings_account.js+++ b/static/js/settings_account.js@@ -404,7 +404,6 @@ export function set_up() {$("#api_key_status").hide();overlays.open_modal("api_key_modal", {autoremove: true,- micromodal: true,on_show: () => {$("#get_api_key_password").trigger("focus");},@@ -717,20 +716,6 @@ export function set_up() {setTimeout(() => {user_profile.show_user_profile(user);}, 100);-- // If user opened the "preview profile" modal from user- // settings, then closing preview profile modal should- // send them back to the settings modal.- $("body").one("hidden.bs.modal", "#user-profile-modal", (e) => {- e.preventDefault();- e.stopPropagation();-- setTimeout(() => {- if (!overlays.settings_open()) {- overlays.open_settings();- }- }, 100);- });});function upload_avatar($file_input) {diff --git a/static/js/spectators.js b/static/js/spectators.jsindex 270ce6f5364..dd191a999d6 100644--- a/static/js/spectators.js+++ b/static/js/spectators.js@@ -31,7 +31,6 @@ export function login_to_access(empty_narrow) {overlays.open_modal("login_to_access_modal", {autoremove: true,- micromodal: true,on_hide: () => {browser_history.return_to_web_public_hash();},diff --git a/static/js/user_profile.js b/static/js/user_profile.jsindex 7c1d2f31d44..d3f86f84e52 100644--- a/static/js/user_profile.js+++ b/static/js/user_profile.js@@ -134,9 +134,7 @@ function get_custom_profile_field_data(user, field, field_types, dateFormat) {}export function hide_user_profile() {- overlays.close_modal("user-profile-modal", {- micromodal: true,- });+ overlays.close_modal("user-profile-modal");}export function show_user_profile(user) {@@ -166,7 +164,7 @@ export function show_user_profile(user) {};$("#user-profile-modal-holder").html(render_user_profile_modal(args));- overlays.open_modal("user-profile-modal", {autoremove: true, micromodal: true});+ overlays.open_modal("user-profile-modal", {autoremove: true});$(".tabcontent").hide();$("#profile-tab").show(); // Show general profile details by default.const opts = {diff --git a/static/styles/modal.css b/static/styles/modal.cssindex 86ff8619a8a..ed1f821deb0 100644--- a/static/styles/modal.css+++ b/static/styles/modal.css@@ -1,37 +1,7 @@-.modal {- box-shadow: 0 0 75px hsla(0, 0%, 0%, 0.5);- border: none;- border-radius: 0;- overflow: hidden;- margin-top: 0;- top: 5%;- outline: 10000px solid hsla(0, 0%, 0%, 0.3);-- &.fade {- /* Ensure the modal is entirely off-screen while we fade the background */- top: -50%;- transition: opacity 0.3s linear;- transform: translateY(-50%);-- &.in {- top: 50%;- pointer-events: all;- }- }-- form {- margin-bottom: 0;- }-}-.modal-body {max-height: 60vh;}-.modal-backdrop {- z-index: 102;-}-.modal-bg {background-color: hsl(0, 0%, 98%);}