ui.get_scroll_element: Set up SimpleBar if it’s expected but missing.

Although SimpleBar automatically sets itself up on elements with a
`data-simplebar` attribute, sometimes we try to set event listeners
before that happens.  Create the SimpleBar early in that case.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg 2019-07-25 15:22:43 -07:00
parent 48526b1fd6
commit f0e0fe1c15
3 changed files with 9 additions and 1 deletions

View File

@ -16,6 +16,7 @@ function init_simulated_scrolling() {
}); });
var elem = { var elem = {
dataset: {},
scrollTop: 0, scrollTop: 0,
scrollHeight: 0, scrollHeight: 0,
}; };

View File

@ -340,6 +340,9 @@ run_test('zoom_in_and_zoom_out', () => {
f.call(elem(stream_li1)); f.call(elem(stream_li1));
f.call(elem(stream_li2)); f.call(elem(stream_li2));
}; };
$('#stream-filters-container')[0] = {
dataset: {},
};
stream_list.set_event_handlers(); stream_list.set_event_handlers();
stream_list.zoom_in_topics({stream_id: 42}); stream_list.zoom_in_topics({stream_id: 42});

View File

@ -1,6 +1,6 @@
var ui = (function () { var ui = (function () {
require("simplebar"); var SimpleBar = require("simplebar").default;
var exports = {}; var exports = {};
@ -27,6 +27,10 @@ exports.get_scroll_element = function (element_selector) {
var element = element_selector.expectOne()[0]; var element = element_selector.expectOne()[0];
if (element.SimpleBar) { if (element.SimpleBar) {
return $(element.SimpleBar.getScrollElement()); return $(element.SimpleBar.getScrollElement());
} else if ('simplebar' in element.dataset) {
// The SimpleBar mutation observer hasnt processed this element yet.
// Create the SimpleBar early in case we need to add event listeners.
return $(new SimpleBar(element).getScrollElement());
} }
return element_selector; return element_selector;
}; };