mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 00:46:03 +00:00
overlays: Create modal helper methods to manage display status.
This commit is contained in:
@@ -16,6 +16,10 @@ exports.is_active = function () {
|
|||||||
return !!open_overlay_name;
|
return !!open_overlay_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.is_modal_open = function () {
|
||||||
|
return $(".modal").hasClass("in");
|
||||||
|
};
|
||||||
|
|
||||||
exports.info_overlay_open = function () {
|
exports.info_overlay_open = function () {
|
||||||
return open_overlay_name === 'informationalOverlays';
|
return open_overlay_name === 'informationalOverlays';
|
||||||
};
|
};
|
||||||
@@ -32,6 +36,14 @@ exports.lightbox_open = function () {
|
|||||||
return open_overlay_name === 'lightbox';
|
return open_overlay_name === 'lightbox';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.active_modal = function () {
|
||||||
|
if (!exports.is_modal_open()) {
|
||||||
|
blueslip.error("Programming error — Called open_modal when there is no modal open");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return $(".modal.in").attr("id");
|
||||||
|
};
|
||||||
|
|
||||||
exports.open_overlay = function (opts) {
|
exports.open_overlay = function (opts) {
|
||||||
if (!opts.name || !opts.overlay || !opts.on_close) {
|
if (!opts.name || !opts.overlay || !opts.on_close) {
|
||||||
blueslip.error('Programming error in open_overlay');
|
blueslip.error('Programming error in open_overlay');
|
||||||
@@ -69,6 +81,23 @@ exports.open_overlay = function (opts) {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.open_modal = function (name) {
|
||||||
|
if (name === undefined) {
|
||||||
|
blueslip.error('Undefined name was passed into open_modal');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (exports.is_modal_open()) {
|
||||||
|
blueslip.error('open_modal() was called while ' + exports.active_modal() +
|
||||||
|
' modal was open.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
blueslip.debug('open modal: ' + name);
|
||||||
|
|
||||||
|
$("#" + name).modal("show").attr("aria-hidden", false);
|
||||||
|
};
|
||||||
|
|
||||||
exports.close_overlay = function (name) {
|
exports.close_overlay = function (name) {
|
||||||
if (name !== open_overlay_name) {
|
if (name !== open_overlay_name) {
|
||||||
blueslip.error("Trying to close " + name + " when " + open_overlay_name + " is open." );
|
blueslip.error("Trying to close " + name + " when " + open_overlay_name + " is open." );
|
||||||
@@ -106,6 +135,37 @@ exports.close_active = function () {
|
|||||||
exports.close_overlay(open_overlay_name);
|
exports.close_overlay(open_overlay_name);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.close_modal = function (name) {
|
||||||
|
if (name === undefined) {
|
||||||
|
blueslip.error('Undefined name was passed into close_modal');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!exports.is_modal_open()) {
|
||||||
|
blueslip.warn('close_active_modal() called without checking is_modal_open()');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (exports.active_modal() !== name) {
|
||||||
|
blueslip.error("Trying to close " + name +
|
||||||
|
" modal when " + exports.active_modal() + " is open." );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
blueslip.debug('close modal: ' + name);
|
||||||
|
|
||||||
|
$("#" + name).modal("hide").attr("aria-hidden", true);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.close_active_modal = function () {
|
||||||
|
if (!exports.is_modal_open()) {
|
||||||
|
blueslip.warn('close_active_modal() called without checking is_modal_open()');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$(".modal.in").modal("hide").attr("aria-hidden", true);
|
||||||
|
};
|
||||||
|
|
||||||
exports.close_for_hash_change = function () {
|
exports.close_for_hash_change = function () {
|
||||||
$(".overlay.show").removeClass("show");
|
$(".overlay.show").removeClass("show");
|
||||||
reset_state();
|
reset_state();
|
||||||
|
|||||||
Reference in New Issue
Block a user