mirror of https://github.com/zulip/zulip.git
91 lines
2.6 KiB
JavaScript
91 lines
2.6 KiB
JavaScript
var rows = (function () {
|
|
|
|
var exports = {};
|
|
|
|
// We don't need an andSelf() here because we already know
|
|
// that our next element is *not* a message_row, so this
|
|
// isn't going to end up empty unless we're at the bottom or top.
|
|
exports.next_visible = function (message_row) {
|
|
if (message_row === undefined) {
|
|
return $();
|
|
}
|
|
var row = message_row.next('.selectable_row');
|
|
if (row.length !== 0) {
|
|
return row;
|
|
}
|
|
var recipient_row = exports.get_message_recipient_row(message_row);
|
|
var next_recipient_rows = $(recipient_row).nextAll('.recipient_row');
|
|
if (next_recipient_rows.length === 0) {
|
|
return $();
|
|
}
|
|
return $('.selectable_row:first', next_recipient_rows[0]);
|
|
};
|
|
|
|
exports.prev_visible = function (message_row) {
|
|
if (message_row === undefined) {
|
|
return $();
|
|
}
|
|
var row = message_row.prev('.selectable_row');
|
|
if (row.length !== 0) {
|
|
return row;
|
|
}
|
|
var recipient_row = exports.get_message_recipient_row(message_row);
|
|
var prev_recipient_rows = $(recipient_row).prevAll('.recipient_row');
|
|
if (prev_recipient_rows.length === 0) {
|
|
return $();
|
|
}
|
|
return $('.selectable_row:last', prev_recipient_rows[0]);
|
|
};
|
|
|
|
exports.first_visible = function () {
|
|
return $('.focused_table .selectable_row:first');
|
|
};
|
|
|
|
exports.last_visible = function () {
|
|
return $('.focused_table .selectable_row:last');
|
|
};
|
|
|
|
exports.id = function (message_row) {
|
|
return parseFloat(message_row.attr('zid'), 10);
|
|
};
|
|
|
|
var valid_table_names = {
|
|
zhome: true,
|
|
zfilt: true
|
|
};
|
|
|
|
exports.get_table = function (table_name) {
|
|
if (! valid_table_names.hasOwnProperty(table_name)) {
|
|
return $();
|
|
}
|
|
|
|
return $('#' + table_name);
|
|
};
|
|
|
|
exports.get_closest_group = function (element) {
|
|
// This gets the closest message row to an element, whether it's
|
|
// a recipient bar or message. With our current markup,
|
|
// this is the most reliable way to do it.
|
|
return $(element).closest("div.recipient_row");
|
|
};
|
|
|
|
exports.first_message_in_group = function (message_group) {
|
|
return $('div.message_row:first', message_group);
|
|
};
|
|
|
|
exports.get_message_recipient_row = function (message_row) {
|
|
return $(message_row).parent('.recipient_row').expectOne();
|
|
};
|
|
|
|
exports.get_message_recipient_header = function (message_row) {
|
|
return $(message_row).parent('.recipient_row').find('.message_header').expectOne();
|
|
};
|
|
|
|
exports.recipient_from_group = function (message_group) {
|
|
return message_store.get(exports.id($(message_group).children('.message_row').first().expectOne()));
|
|
};
|
|
|
|
return exports;
|
|
|
|
}());
|