list_render: Extract get_list_scrolling_container().

We put this in `scroll_util` to make it more likely
we will eventually unify this with other scrolling
logic.  (A big piece to move is ui.get_scroll_element,
but that's for another PR.)

And then the other tactical advantage is that we get
100% line coverage on it.

I changed the warning to an error, since I don't
think we ever expect scrolling at the `body` level,
and I don't bother with the preview node.
This commit is contained in:
Steve Howell
2020-04-13 11:52:07 +00:00
committed by Tim Abbott
parent 839a817d0e
commit 3aef11dc0e
4 changed files with 50 additions and 15 deletions

View File

@@ -1,3 +1,30 @@
exports.get_list_scrolling_container = function (container) {
/*
This is used for list widgets that don't
have SimpleBar (in contrast to, say,
ui.get_scroll_element().
*/
let nearestScrollingContainer = container;
while (nearestScrollingContainer.length) {
if (nearestScrollingContainer.is("body, html")) {
blueslip.error(
"Please wrap lists in an element with " +
"'max-height' attribute.");
break;
}
if (nearestScrollingContainer.css("max-height") !== "none") {
break;
}
nearestScrollingContainer = nearestScrollingContainer.parent();
}
return nearestScrollingContainer;
};
exports.scroll_delta = function (opts) {
const elem_top = opts.elem_top;
const container_height = opts.container_height;