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
// 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
// taken effect.

View File

@@ -249,7 +249,7 @@ exports.activate = function (operators, opts) {
// above us could change size -- which is problematic, because it
// could cause us to lose our position. But doing this here, right
// 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();
if (! defer_selecting_closest) {

View File

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