Change signature of ui.process_condensing().

I renamed ui.process_condensing() to ui.condense_and_collapse(),
and, more importantly, it now takes a list of elements, not a single
element, which allows us to do some computations outside the loop.

(imported from commit d5984088030c2a0d4ec8b258c7fcec3e84caf2b1)
This commit is contained in:
Steve Howell
2013-12-04 16:02:34 -05:00
parent 983f29eac4
commit f923c15ba8
3 changed files with 31 additions and 29 deletions

View File

@@ -401,7 +401,7 @@ MessageListView.prototype = {
// Must happen after the elements are inserted into the document for // Must happen after the elements are inserted into the document for
// getBoundingClientRect to work. // getBoundingClientRect to work.
_.each(rendered_elems, ui.process_condensing); ui.condense_and_collapse(rendered_elems);
// Must happen after anything that changes the height of messages has // Must happen after anything that changes the height of messages has
// taken effect. // taken effect.

View File

@@ -249,7 +249,7 @@ exports.activate = function (operators, opts) {
// above us could change size -- which is problematic, because it // above us could change size -- which is problematic, because it
// could cause us to lose our position. But doing this here, right // could cause us to lose our position. But doing this here, right
// after showing the table, seems to cause us to win the race. // after showing the table, seems to cause us to win the race.
_.each($("tr.message_row"), ui.process_condensing); ui.condense_and_collapse($("tr.message_row"));
reset_load_more_status(); reset_load_more_status();
if (! defer_selecting_closest) { if (! defer_selecting_closest) {

View File

@@ -1705,42 +1705,44 @@ exports.restore_compose_cursor = function () {
.caret(saved_compose_cursor, saved_compose_cursor); .caret(saved_compose_cursor, saved_compose_cursor);
}; };
exports.process_condensing = function (elem) { exports.condense_and_collapse = function (elems) {
var height_cutoff = viewport.height() * 0.65; var height_cutoff = viewport.height() * 0.65;
function could_be_condensed(elem) { function could_be_condensed(elem) {
return elem.getBoundingClientRect().height > height_cutoff; return elem.getBoundingClientRect().height > height_cutoff;
} }
var content = $(elem).find(".message_content"); _.each(elems, function (elem) {
var message = current_msg_list.get(rows.id($(elem))); var content = $(elem).find(".message_content");
if (content !== undefined && message !== undefined) { var message = current_msg_list.get(rows.id($(elem)));
var long_message = could_be_condensed(elem); if (content !== undefined && message !== undefined) {
if (long_message) { var long_message = could_be_condensed(elem);
// All long messages are flagged as such. if (long_message) {
content.addClass("could-be-condensed"); // All long messages are flagged as such.
} content.addClass("could-be-condensed");
}
// If message.condensed is defined, then the user has manually // If message.condensed is defined, then the user has manually
// specified whether this message should be expanded or condensed. // specified whether this message should be expanded or condensed.
if (message.condensed === true) { if (message.condensed === true) {
condense($(elem)); condense($(elem));
return; return;
} else if (message.condensed === false) { } else if (message.condensed === false) {
uncondense($(elem)); uncondense($(elem));
return; return;
} else if (long_message) { } else if (long_message) {
// By default, condense a long message. // By default, condense a long message.
condense($(elem)); condense($(elem));
} }
// Completely hide the message and replace it with a [More] // Completely hide the message and replace it with a [More]
// link if the user has collapsed it. // link if the user has collapsed it.
if (message.collapsed) { if (message.collapsed) {
content.addClass("collapsed"); content.addClass("collapsed");
$(elem).find(".message_expander").show(); $(elem).find(".message_expander").show();
}
} }
} });
}; };
$(function () { $(function () {