Files
zulip/static/js/rows.js
Steve Howell 03b58e1528 Make narrowing click handlers work more generally.
Previously, narrowing would only work from recipient rows, not
other message table rows (e.g. summary rows).  This led to the trap
that you could add a narrows_by_recipient class to an element,
expect that narrowing would work, but the actual handler would
break or silently fail if it weren't part of a recipient row.

Now the click handler looks for the closest table row (tr).  It's
encapsulated in rows.get_closest_row(), so if we go to a
non-table-based design, it should be easy to address in one
place.

(imported from commit e116b7573c4bb06599ced84a0adcf8dc23d63593)
2013-08-27 15:46:33 -04:00

65 lines
1.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;
}
return message_row.nextUntil('.selectable_row').next('.selectable_row');
};
exports.prev_visible = function (message_row) {
if (message_row === undefined) {
return $();
}
var row = message_row.prev('.selectable_row');
if (row.length !== 0) {
return row;
}
return message_row.prevUntil('.selectable_row').prev('.selectable_row');
};
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 parseInt(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_row = function (element) {
// This gets the closest message row to an element, whether it's
// a summary bar, recipient bar, or message. With our current markup,
// this is the most reliable way to do it.
return $(element).closest("tr");
};
return exports;
}());