2012-10-27 02:01:18 +02:00
|
|
|
var rows = (function () {
|
|
|
|
|
2013-08-14 20:57:29 +02:00
|
|
|
var exports = {};
|
2012-10-03 20:49:58 +02:00
|
|
|
|
2013-08-14 20:57:29 +02:00
|
|
|
// 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) {
|
2014-02-21 21:52:51 +01:00
|
|
|
if (message_row === undefined || message_row.length === 0) {
|
2013-08-14 20:57:29 +02:00
|
|
|
return $();
|
|
|
|
}
|
|
|
|
var row = message_row.next('.selectable_row');
|
|
|
|
if (row.length !== 0) {
|
|
|
|
return row;
|
|
|
|
}
|
2014-02-05 16:55:24 +01:00
|
|
|
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]);
|
2013-08-14 20:57:29 +02:00
|
|
|
};
|
2012-10-03 20:49:58 +02:00
|
|
|
|
2013-08-14 20:57:29 +02:00
|
|
|
exports.prev_visible = function (message_row) {
|
2014-02-21 21:52:51 +01:00
|
|
|
if (message_row === undefined || message_row.length === 0) {
|
2013-08-14 20:57:29 +02:00
|
|
|
return $();
|
|
|
|
}
|
|
|
|
var row = message_row.prev('.selectable_row');
|
|
|
|
if (row.length !== 0) {
|
|
|
|
return row;
|
|
|
|
}
|
2014-02-05 16:55:24 +01:00
|
|
|
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]);
|
2013-08-14 20:57:29 +02:00
|
|
|
};
|
2012-10-03 20:49:58 +02:00
|
|
|
|
2013-08-14 20:57:29 +02:00
|
|
|
exports.first_visible = function () {
|
|
|
|
return $('.focused_table .selectable_row:first');
|
|
|
|
};
|
2012-10-03 20:49:58 +02:00
|
|
|
|
2013-08-14 20:57:29 +02:00
|
|
|
exports.last_visible = function () {
|
|
|
|
return $('.focused_table .selectable_row:last');
|
|
|
|
};
|
2012-10-03 20:49:58 +02:00
|
|
|
|
2013-08-14 20:57:29 +02:00
|
|
|
exports.id = function (message_row) {
|
2017-08-22 16:33:20 +02:00
|
|
|
return parseFloat(message_row.attr('zid'));
|
2013-08-14 20:57:29 +02:00
|
|
|
};
|
2012-10-18 20:55:41 +02:00
|
|
|
|
2013-08-14 20:57:29 +02:00
|
|
|
var valid_table_names = {
|
|
|
|
zhome: true,
|
2017-01-12 00:17:43 +01:00
|
|
|
zfilt: true,
|
2013-08-14 20:57:29 +02:00
|
|
|
};
|
2012-10-27 02:05:54 +02:00
|
|
|
|
2013-08-14 20:57:29 +02:00
|
|
|
exports.get_table = function (table_name) {
|
|
|
|
if (! valid_table_names.hasOwnProperty(table_name)) {
|
|
|
|
return $();
|
|
|
|
}
|
2012-10-27 03:03:06 +02:00
|
|
|
|
2013-08-14 20:57:29 +02:00
|
|
|
return $('#' + table_name);
|
|
|
|
};
|
2012-10-27 03:03:06 +02:00
|
|
|
|
2017-07-19 13:53:30 +02:00
|
|
|
exports.get_message_id = function (elem) {
|
|
|
|
// Gets the message_id for elem, where elem is a DOM
|
|
|
|
// element inside a message. This is typically used
|
|
|
|
// in click handlers for things like the reaction button.
|
|
|
|
var row = $(elem).closest(".message_row");
|
|
|
|
var message_id = exports.id(row);
|
|
|
|
return message_id;
|
|
|
|
};
|
|
|
|
|
2014-02-05 16:55:24 +01:00
|
|
|
exports.get_closest_group = function (element) {
|
2013-08-27 17:09:27 +02:00
|
|
|
// This gets the closest message row to an element, whether it's
|
2014-02-03 22:48:25 +01:00
|
|
|
// a recipient bar or message. With our current markup,
|
2013-08-27 17:09:27 +02:00
|
|
|
// this is the most reliable way to do it.
|
2014-02-05 16:55:24 +01:00
|
|
|
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()));
|
2013-08-27 17:09:27 +02:00
|
|
|
};
|
|
|
|
|
2014-03-13 04:25:34 +01:00
|
|
|
exports.id_for_recipient_row = function (recipient_row) {
|
|
|
|
// A recipient row can be either a normal recipient row, or
|
|
|
|
// the FRB, which is a fake recipient row. If it's a FRB, it has
|
|
|
|
// a 'zid' property that stores the message id it is directly over
|
|
|
|
var msg_row = exports.first_message_in_group(recipient_row);
|
|
|
|
if (msg_row.length === 0) {
|
|
|
|
// If we're narrowing from the FRB, take the msg id
|
|
|
|
// directly from it
|
|
|
|
return exports.id(recipient_row);
|
|
|
|
}
|
2016-12-02 21:34:35 +01:00
|
|
|
return exports.id(msg_row);
|
2014-03-13 04:25:34 +01:00
|
|
|
};
|
|
|
|
|
2013-08-14 20:57:29 +02:00
|
|
|
return exports;
|
2012-10-27 02:01:18 +02:00
|
|
|
|
|
|
|
}());
|
2016-12-04 08:59:56 +01:00
|
|
|
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = rows;
|
|
|
|
}
|