2012-10-27 02:01:18 +02:00
|
|
|
var rows = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
2012-10-03 20:49:58 +02:00
|
|
|
|
2012-10-18 20:55:41 +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.
|
2012-10-27 02:01:18 +02:00
|
|
|
exports.next_visible = function (message_row) {
|
2012-10-18 20:55:41 +02:00
|
|
|
if (message_row === undefined)
|
2012-11-28 23:07:33 +01:00
|
|
|
return $();
|
2012-10-18 20:55:41 +02:00
|
|
|
var row = message_row.next('.message_row');
|
|
|
|
if (row.length !== 0) {
|
|
|
|
return row;
|
|
|
|
}
|
|
|
|
return message_row.nextUntil('.message_row').next('.message_row');
|
2012-10-27 02:01:18 +02:00
|
|
|
};
|
2012-10-03 20:49:58 +02:00
|
|
|
|
2012-10-27 02:01:18 +02:00
|
|
|
exports.prev_visible = function (message_row) {
|
2012-10-18 20:55:41 +02:00
|
|
|
if (message_row === undefined)
|
2012-11-28 23:07:33 +01:00
|
|
|
return $();
|
2012-10-18 20:55:41 +02:00
|
|
|
var row = message_row.prev('.message_row');
|
|
|
|
if (row.length !== 0) {
|
|
|
|
return row;
|
|
|
|
}
|
|
|
|
return message_row.prevUntil('.message_row').prev('.message_row');
|
2012-10-27 02:01:18 +02:00
|
|
|
};
|
2012-10-03 20:49:58 +02:00
|
|
|
|
2012-10-27 02:01:18 +02:00
|
|
|
exports.first_visible = function () {
|
2012-10-18 20:55:41 +02:00
|
|
|
return $('.focused_table .message_row:first');
|
2012-10-27 02:01:18 +02:00
|
|
|
};
|
2012-10-03 20:49:58 +02:00
|
|
|
|
2012-10-27 02:01:18 +02:00
|
|
|
exports.last_visible = function () {
|
2012-10-18 20:55:41 +02:00
|
|
|
return $('.focused_table .message_row:last');
|
2012-10-27 02:01:18 +02:00
|
|
|
};
|
2012-10-03 20:49:58 +02:00
|
|
|
|
2012-10-27 02:01:18 +02:00
|
|
|
exports.id = function (message_row) {
|
2012-11-01 19:16:42 +01:00
|
|
|
return parseInt(message_row.attr('zid'), 10);
|
2012-10-27 02:01:18 +02:00
|
|
|
};
|
2012-10-18 20:55:41 +02:00
|
|
|
|
2012-10-27 02:05:54 +02:00
|
|
|
var valid_table_names = {
|
|
|
|
zhome: true,
|
|
|
|
zfilt: true
|
|
|
|
};
|
|
|
|
|
2012-10-27 02:01:18 +02:00
|
|
|
exports.get = function (message_id, table_name) {
|
2012-10-27 02:05:54 +02:00
|
|
|
// Make sure message_id is just an int, because we build
|
|
|
|
// a jQuery selector using it.
|
|
|
|
message_id = parseInt(message_id, 10);
|
|
|
|
if (isNaN(message_id))
|
2012-11-28 23:07:33 +01:00
|
|
|
return $();
|
2012-10-27 02:05:54 +02:00
|
|
|
|
|
|
|
// To avoid attacks and bizarre errors, we have a whitelist
|
|
|
|
// of valid table names.
|
|
|
|
if (! valid_table_names.hasOwnProperty(table_name))
|
2012-11-28 23:07:33 +01:00
|
|
|
return $();
|
2012-10-27 02:05:54 +02:00
|
|
|
|
2012-10-18 20:55:41 +02:00
|
|
|
return $('#' + table_name + message_id);
|
2012-10-27 02:01:18 +02:00
|
|
|
};
|
|
|
|
|
2012-10-27 03:03:06 +02:00
|
|
|
exports.get_table = function (table_name) {
|
|
|
|
if (! valid_table_names.hasOwnProperty(table_name))
|
2012-11-28 23:07:33 +01:00
|
|
|
return $();
|
2012-10-27 03:03:06 +02:00
|
|
|
|
|
|
|
return $('#' + table_name);
|
|
|
|
};
|
|
|
|
|
2012-10-27 02:01:18 +02:00
|
|
|
return exports;
|
|
|
|
|
|
|
|
}());
|