mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 06:23:38 +00:00
This commit forces the files that create modals to create their own modal closing function instead of creating all of them in the modals file. These functions are then passed to the modals.close object. This is intended to remove modals.js's dependencies on these other files.
58 lines
1.6 KiB
JavaScript
58 lines
1.6 KiB
JavaScript
var modals = (function () {
|
|
"use strict";
|
|
|
|
var exports = {
|
|
close : {},
|
|
|
|
set_close_handler : function (name, handler) {
|
|
exports.close[name] = handler;
|
|
},
|
|
|
|
close_modal: function (name) {
|
|
$("[data-overlay='" + name + "']").removeClass("show");
|
|
|
|
if (exports.close[name]) {
|
|
exports.close[name]();
|
|
} else {
|
|
blueslip.error("Modal close handler for " + name + " not properly setup." );
|
|
}
|
|
},
|
|
};
|
|
|
|
$(function () {
|
|
$("body").on("click", ".overlay, .overlay .exit", function (e) {
|
|
var $target = $(e.target);
|
|
|
|
// if the target is not the .overlay element, search up the node tree
|
|
// until it is found.
|
|
if ($target.is(".exit, .exit-sign, .overlay-content")) {
|
|
$target = $target.closest("[data-overlay]");
|
|
} else if (!$target.is(".overlay")) {
|
|
// not a valid click target then.
|
|
return;
|
|
}
|
|
|
|
var target_name = $target.attr("data-overlay");
|
|
|
|
$target.removeClass("show");
|
|
|
|
// if an appropriate clearing/closing function for a modal exists,
|
|
// execute it.
|
|
if (exports.close[target_name]) {
|
|
exports.close[target_name]();
|
|
} else {
|
|
blueslip.error("Tried to close unknown modal " + target_name);
|
|
}
|
|
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
});
|
|
});
|
|
|
|
return exports;
|
|
}());
|
|
|
|
if (typeof module !== 'undefined') {
|
|
module.exports = modals;
|
|
}
|