2017-05-27 15:40:54 +02:00
|
|
|
var overlays = (function () {
|
2017-05-05 23:43:05 +02:00
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
2017-05-06 02:27:40 +02:00
|
|
|
var active_overlay;
|
|
|
|
var close_handler;
|
2017-05-27 15:40:54 +02:00
|
|
|
var open_overlay_name;
|
2017-05-06 02:27:40 +02:00
|
|
|
|
|
|
|
function reset_state() {
|
|
|
|
active_overlay = undefined;
|
|
|
|
close_handler = undefined;
|
2017-05-27 15:40:54 +02:00
|
|
|
open_overlay_name = undefined;
|
2017-05-06 02:27:40 +02:00
|
|
|
}
|
2017-05-05 23:43:05 +02:00
|
|
|
|
2017-05-06 02:40:32 +02:00
|
|
|
exports.is_active = function () {
|
2017-05-27 15:40:54 +02:00
|
|
|
return !!open_overlay_name;
|
2017-05-06 02:40:32 +02:00
|
|
|
};
|
|
|
|
|
2017-08-29 19:05:05 +02:00
|
|
|
exports.is_modal_open = function () {
|
|
|
|
return $(".modal").hasClass("in");
|
|
|
|
};
|
|
|
|
|
2017-05-09 16:45:02 +02:00
|
|
|
exports.info_overlay_open = function () {
|
2017-05-27 15:40:54 +02:00
|
|
|
return open_overlay_name === 'informationalOverlays';
|
2017-05-09 16:45:02 +02:00
|
|
|
};
|
|
|
|
|
2017-05-10 00:37:08 +02:00
|
|
|
exports.settings_open = function () {
|
2017-05-27 15:40:54 +02:00
|
|
|
return open_overlay_name === 'settings';
|
2017-05-10 00:37:08 +02:00
|
|
|
};
|
|
|
|
|
2017-05-16 05:28:14 +02:00
|
|
|
exports.streams_open = function () {
|
2017-05-27 15:40:54 +02:00
|
|
|
return open_overlay_name === 'subscriptions';
|
2017-05-16 05:28:14 +02:00
|
|
|
};
|
|
|
|
|
2017-05-10 15:43:36 +02:00
|
|
|
exports.lightbox_open = function () {
|
2017-05-27 15:40:54 +02:00
|
|
|
return open_overlay_name === 'lightbox';
|
2017-05-10 15:43:36 +02:00
|
|
|
};
|
|
|
|
|
2017-10-03 00:41:43 +02:00
|
|
|
exports.drafts_open = function () {
|
|
|
|
return open_overlay_name === 'drafts';
|
|
|
|
};
|
|
|
|
|
2017-08-29 19:05:05 +02:00
|
|
|
exports.active_modal = function () {
|
|
|
|
if (!exports.is_modal_open()) {
|
2017-10-03 00:41:43 +02:00
|
|
|
blueslip.error("Programming error — Called active_modal when there is no modal open");
|
2017-08-29 19:05:05 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
return $(".modal.in").attr("id");
|
|
|
|
};
|
|
|
|
|
2017-05-06 00:37:33 +02:00
|
|
|
exports.open_overlay = function (opts) {
|
2017-10-31 14:36:54 +01:00
|
|
|
popovers.hide_all();
|
|
|
|
|
2017-05-06 00:37:33 +02:00
|
|
|
if (!opts.name || !opts.overlay || !opts.on_close) {
|
2017-05-27 15:40:54 +02:00
|
|
|
blueslip.error('Programming error in open_overlay');
|
2017-05-06 00:37:33 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-27 15:40:54 +02:00
|
|
|
if (active_overlay || open_overlay_name || close_handler) {
|
2017-10-20 19:21:08 +02:00
|
|
|
blueslip.error('Programming error — trying to open ' + opts.name +
|
2017-05-27 15:40:54 +02:00
|
|
|
' before closing ' + open_overlay_name);
|
2017-05-06 02:27:40 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-15 17:03:29 +02:00
|
|
|
blueslip.debug('open overlay: ' + opts.name);
|
|
|
|
|
2017-05-06 00:37:33 +02:00
|
|
|
// Our overlays are kind of crufty...we have an HTML id
|
|
|
|
// attribute for them and then a data-overlay attribute for
|
|
|
|
// them. Make sure they match.
|
|
|
|
if (opts.overlay.attr('data-overlay') !== opts.name) {
|
|
|
|
blueslip.error('Bad overlay setup for ' + opts.name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-27 15:40:54 +02:00
|
|
|
open_overlay_name = opts.name;
|
2017-05-06 02:27:40 +02:00
|
|
|
active_overlay = opts.overlay;
|
2017-05-06 00:37:33 +02:00
|
|
|
opts.overlay.addClass('show');
|
2017-06-22 17:27:53 +02:00
|
|
|
|
|
|
|
opts.overlay.attr("aria-hidden", "false");
|
|
|
|
$('.app').attr("aria-hidden", "true");
|
|
|
|
$('.fixed-app').attr("aria-hidden", "true");
|
|
|
|
$('.header').attr("aria-hidden", "true");
|
2017-05-06 00:37:33 +02:00
|
|
|
|
2017-05-06 02:27:40 +02:00
|
|
|
close_handler = function () {
|
2017-05-06 00:37:33 +02:00
|
|
|
opts.on_close();
|
2017-05-06 02:27:40 +02:00
|
|
|
reset_state();
|
2017-05-06 00:37:33 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-08-29 19:05:05 +02:00
|
|
|
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);
|
2017-12-25 16:29:48 +01:00
|
|
|
// Remove previous alert messsages from modal, if exists.
|
|
|
|
$("#" + name).find(".alert").hide();
|
2017-08-29 19:05:05 +02:00
|
|
|
};
|
|
|
|
|
2017-05-27 15:40:54 +02:00
|
|
|
exports.close_overlay = function (name) {
|
|
|
|
if (name !== open_overlay_name) {
|
2017-10-06 21:36:39 +02:00
|
|
|
blueslip.error("Trying to close " + name + " when " + open_overlay_name + " is open.");
|
2017-05-06 02:27:40 +02:00
|
|
|
return;
|
2017-05-05 23:43:05 +02:00
|
|
|
}
|
2017-05-06 02:27:40 +02:00
|
|
|
|
2017-06-15 17:03:29 +02:00
|
|
|
if (name === undefined) {
|
|
|
|
blueslip.error('Undefined name was passed into close_overlay');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
blueslip.debug('close overlay: ' + name);
|
|
|
|
|
2017-05-06 02:27:40 +02:00
|
|
|
active_overlay.removeClass("show");
|
2017-06-22 17:27:53 +02:00
|
|
|
|
|
|
|
active_overlay.attr("aria-hidden", "true");
|
|
|
|
$('.app').attr("aria-hidden", "false");
|
|
|
|
$('.fixed-app').attr("aria-hidden", "false");
|
|
|
|
$('.header').attr("aria-hidden", "false");
|
2017-05-06 02:27:40 +02:00
|
|
|
|
2017-05-12 17:24:16 +02:00
|
|
|
if (!close_handler) {
|
2017-10-06 21:36:39 +02:00
|
|
|
blueslip.error("Overlay close handler for " + name + " not properly setup.");
|
2017-05-12 17:24:16 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-06 02:27:40 +02:00
|
|
|
close_handler();
|
|
|
|
};
|
|
|
|
|
2017-05-10 00:37:28 +02:00
|
|
|
exports.close_active = function () {
|
2017-05-27 15:40:54 +02:00
|
|
|
if (!open_overlay_name) {
|
2017-05-10 00:37:28 +02:00
|
|
|
blueslip.warn('close_active() called without checking is_active()');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-27 15:40:54 +02:00
|
|
|
exports.close_overlay(open_overlay_name);
|
2017-05-10 00:37:28 +02:00
|
|
|
};
|
|
|
|
|
2017-08-29 19:05:05 +02:00
|
|
|
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 +
|
2017-10-06 21:36:39 +02:00
|
|
|
" modal when " + exports.active_modal() + " is open.");
|
2017-08-29 19:05:05 +02:00
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
2017-05-06 02:27:40 +02:00
|
|
|
exports.close_for_hash_change = function () {
|
|
|
|
$(".overlay.show").removeClass("show");
|
|
|
|
reset_state();
|
2017-05-05 23:43:05 +02:00
|
|
|
};
|
|
|
|
|
2017-05-06 01:04:45 +02:00
|
|
|
exports.open_settings = function () {
|
2017-05-27 15:40:54 +02:00
|
|
|
overlays.open_overlay({
|
2017-05-06 01:04:45 +02:00
|
|
|
name: 'settings',
|
|
|
|
overlay: $("#settings_overlay_container"),
|
|
|
|
on_close: function () {
|
2017-05-27 18:55:41 +02:00
|
|
|
hashchange.exit_overlay();
|
2017-05-06 01:04:45 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-05-15 22:03:14 +02:00
|
|
|
exports.initialize = function () {
|
2017-05-05 23:43:05 +02:00
|
|
|
$("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.
|
2017-07-07 17:30:22 +02:00
|
|
|
if ($target.is(".exit, .exit-sign, .overlay-content, .exit span")) {
|
2017-05-05 23:43:05 +02:00
|
|
|
$target = $target.closest("[data-overlay]");
|
|
|
|
} else if (!$target.is(".overlay")) {
|
|
|
|
// not a valid click target then.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var target_name = $target.attr("data-overlay");
|
|
|
|
|
2017-05-27 15:40:54 +02:00
|
|
|
exports.close_overlay(target_name);
|
2017-05-05 23:43:05 +02:00
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2017-03-13 22:02:31 +01:00
|
|
|
});
|
2018-05-15 22:03:14 +02:00
|
|
|
};
|
2017-05-05 23:43:05 +02:00
|
|
|
|
|
|
|
return exports;
|
2017-03-13 22:02:31 +01:00
|
|
|
|
|
|
|
}());
|
|
|
|
|
|
|
|
if (typeof module !== 'undefined') {
|
2017-05-27 15:40:54 +02:00
|
|
|
module.exports = overlays;
|
2017-03-13 22:02:31 +01:00
|
|
|
}
|
2018-05-28 08:04:36 +02:00
|
|
|
window.overlays = overlays;
|