2014-03-13 21:14:33 +01:00
|
|
|
var floating_recipient_bar = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
|
|
|
|
|
|
|
var is_floating_recipient_bar_showing = false;
|
|
|
|
|
2018-12-25 21:48:06 +01:00
|
|
|
exports.frb_bottom = function () {
|
|
|
|
var bar = $("#floating_recipient_bar");
|
|
|
|
var bar_top = bar.offset().top;
|
|
|
|
var bar_bottom = bar_top + bar.safeOuterHeight();
|
|
|
|
|
|
|
|
return bar_bottom;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.obscured_recipient_bar = function () {
|
|
|
|
// Find the recipient bar that is closed to being onscreen
|
|
|
|
// but above the "top".
|
|
|
|
|
|
|
|
// Start with the pointer's current location.
|
|
|
|
var selected_row = current_msg_list.selected_row();
|
|
|
|
|
|
|
|
if (selected_row === undefined || selected_row.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var candidate = rows.get_message_recipient_row(selected_row);
|
|
|
|
if (candidate === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var floating_recipient_bar_bottom = exports.frb_bottom();
|
|
|
|
|
|
|
|
while (candidate.length) {
|
|
|
|
if (candidate.is(".recipient_row")) {
|
|
|
|
if (candidate.offset().top < floating_recipient_bar_bottom) {
|
|
|
|
return candidate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
candidate = candidate.prev();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-03-13 21:14:33 +01:00
|
|
|
function show_floating_recipient_bar() {
|
|
|
|
if (!is_floating_recipient_bar_showing) {
|
|
|
|
$("#floating_recipient_bar").css('visibility', 'visible');
|
|
|
|
is_floating_recipient_bar_showing = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-26 15:42:17 +01:00
|
|
|
var old_source;
|
|
|
|
function replace_floating_recipient_bar(source_recipient_bar) {
|
2016-12-02 17:09:31 +01:00
|
|
|
var new_label;
|
|
|
|
var other_label;
|
|
|
|
var header;
|
2018-12-26 15:42:17 +01:00
|
|
|
if (source_recipient_bar !== old_source) {
|
|
|
|
if (source_recipient_bar.children(".message_header_stream").length !== 0) {
|
2014-03-13 21:14:33 +01:00
|
|
|
new_label = $("#current_label_stream");
|
|
|
|
other_label = $("#current_label_private_message");
|
2018-12-26 15:42:17 +01:00
|
|
|
header = source_recipient_bar.children(".message_header_stream");
|
2014-03-13 21:14:33 +01:00
|
|
|
} else {
|
|
|
|
new_label = $("#current_label_private_message");
|
|
|
|
other_label = $("#current_label_stream");
|
2018-12-26 15:42:17 +01:00
|
|
|
header = source_recipient_bar.children(".message_header_private_message");
|
2014-03-13 21:14:33 +01:00
|
|
|
}
|
|
|
|
new_label.find(".message_header").replaceWith(header.clone());
|
|
|
|
other_label.css('display', 'none');
|
|
|
|
new_label.css('display', 'block');
|
2018-12-26 15:42:17 +01:00
|
|
|
new_label.attr("zid", rows.id(rows.first_message_in_group(source_recipient_bar)));
|
2014-03-13 21:14:33 +01:00
|
|
|
|
2018-12-26 15:42:17 +01:00
|
|
|
new_label.toggleClass('message-fade', source_recipient_bar.hasClass('message-fade'));
|
|
|
|
old_source = source_recipient_bar;
|
2014-03-13 21:14:33 +01:00
|
|
|
}
|
|
|
|
show_floating_recipient_bar();
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.hide = function () {
|
|
|
|
if (is_floating_recipient_bar_showing) {
|
|
|
|
$("#floating_recipient_bar").css('visibility', 'hidden');
|
|
|
|
is_floating_recipient_bar_showing = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.update = function () {
|
2017-06-03 03:09:40 +02:00
|
|
|
// .temp-show-date might be forcing the display of a recipient_row_date if
|
|
|
|
// the floating_recipient_bar is just beginning to overlap the
|
|
|
|
// top-most recipient_bar. remove all instances of .temp-show-date and
|
|
|
|
// re-apply it if we continue to detect overlap
|
|
|
|
$('.temp-show-date').removeClass('temp-show-date');
|
|
|
|
|
2018-12-25 21:48:06 +01:00
|
|
|
var floating_recipient_bar_bottom = exports.frb_bottom();
|
2014-03-13 21:14:33 +01:00
|
|
|
|
2018-12-26 15:42:17 +01:00
|
|
|
var source_recipient_bar = exports.obscured_recipient_bar();
|
2014-03-13 21:14:33 +01:00
|
|
|
|
2018-12-26 15:42:17 +01:00
|
|
|
if (!source_recipient_bar) {
|
2018-12-25 21:48:06 +01:00
|
|
|
exports.hide();
|
2014-03-13 21:14:33 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-13 16:27:16 +01:00
|
|
|
// We now know what the floating stream/topic bar should say.
|
2014-03-13 21:14:33 +01:00
|
|
|
// Do we show it?
|
|
|
|
|
2018-11-13 16:27:16 +01:00
|
|
|
// Hide if the bottom of our floating stream/topic label is not
|
2018-12-26 15:42:17 +01:00
|
|
|
// lower than the bottom of source_recipient_bar (since that means we're
|
2014-03-13 21:14:33 +01:00
|
|
|
// covering up a label that already exists).
|
2018-12-26 15:42:17 +01:00
|
|
|
var header_height = $(source_recipient_bar).find('.message_header').safeOuterHeight();
|
2014-03-13 21:14:33 +01:00
|
|
|
if (floating_recipient_bar_bottom <=
|
2018-12-26 15:42:17 +01:00
|
|
|
source_recipient_bar.offset().top + header_height) {
|
2017-06-03 03:09:40 +02:00
|
|
|
// hide floating_recipient_bar and use .temp-show-date to force display
|
|
|
|
// of the recipient_row_date belonging to the current recipient_bar
|
2018-12-26 15:42:17 +01:00
|
|
|
$('.recipient_row_date', source_recipient_bar).addClass('temp-show-date');
|
2014-03-13 21:14:33 +01:00
|
|
|
exports.hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-26 15:42:17 +01:00
|
|
|
replace_floating_recipient_bar(source_recipient_bar);
|
2014-03-13 21:14:33 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return exports;
|
|
|
|
}());
|
2016-12-04 08:59:56 +01:00
|
|
|
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = floating_recipient_bar;
|
|
|
|
}
|
2018-05-28 08:04:36 +02:00
|
|
|
window.floating_recipient_bar = floating_recipient_bar;
|