mirror of https://github.com/zulip/zulip.git
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:
parent
839a817d0e
commit
3aef11dc0e
|
@ -1,3 +1,4 @@
|
|||
zrequire('scroll_util');
|
||||
zrequire('list_render');
|
||||
|
||||
// We need these stubs to get by instanceof checks.
|
||||
|
|
|
@ -93,3 +93,23 @@ run_test('scroll_element_into_container', () => {
|
|||
scroll_util.scroll_element_into_container(elem2, container);
|
||||
assert.equal(container.scrollTop(), 250 - 100 + 3 + 15);
|
||||
});
|
||||
|
||||
run_test('get_list_scrolling_container error', () => {
|
||||
const body = {
|
||||
length: 1,
|
||||
is: (sel) => {
|
||||
assert.equal(sel, 'body, html');
|
||||
return true;
|
||||
},
|
||||
};
|
||||
|
||||
blueslip.expect(
|
||||
'error',
|
||||
"Please wrap lists in an element with " +
|
||||
"'max-height' attribute."
|
||||
);
|
||||
|
||||
scroll_util.get_list_scrolling_container(body);
|
||||
|
||||
blueslip.reset();
|
||||
});
|
||||
|
|
|
@ -260,24 +260,11 @@ exports.create = function ($container, list, opts) {
|
|||
};
|
||||
|
||||
widget.set_up_event_handlers = function () {
|
||||
let $nearestScrollingContainer = $container;
|
||||
|
||||
while ($nearestScrollingContainer.length) {
|
||||
if ($nearestScrollingContainer.is("body, html")) {
|
||||
blueslip.warn("Please wrap progressive scrolling lists in an element with 'max-height' attribute. Error found in:\n" + blueslip.preview_node($container));
|
||||
break;
|
||||
}
|
||||
|
||||
if ($nearestScrollingContainer.css("max-height") !== "none") {
|
||||
break;
|
||||
}
|
||||
|
||||
$nearestScrollingContainer = $nearestScrollingContainer.parent();
|
||||
}
|
||||
meta.scroll_container = scroll_util.get_list_scrolling_container($container);
|
||||
|
||||
// on scroll of the nearest scrolling container, if it hits the bottom
|
||||
// of the container then fetch a new block of items and render them.
|
||||
$nearestScrollingContainer.scroll(function () {
|
||||
meta.scroll_container.scroll(function () {
|
||||
if (this.scrollHeight - (this.scrollTop + this.clientHeight) < 10) {
|
||||
widget.render();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue