message_viewport: Move height definition before use.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2021-02-27 16:44:26 -08:00 committed by Tim Abbott
parent b5dbe259a8
commit 07863d1c8a
1 changed files with 18 additions and 18 deletions

View File

@ -7,6 +7,24 @@ let jwindow;
const dimensions = {}; const dimensions = {};
let in_stoppable_autoscroll = false; let in_stoppable_autoscroll = false;
function make_dimen_wrapper(dimen_name, dimen_func) {
dimensions[dimen_name] = new util.CachedValue({
compute_value() {
return dimen_func.call(exports.message_pane);
},
});
return function viewport_dimension_wrapper(...args) {
if (args.length !== 0) {
dimensions[dimen_name].reset();
return dimen_func.apply(exports.message_pane, args);
}
return dimensions[dimen_name].get();
};
}
exports.height = make_dimen_wrapper("height", $(exports.message_pane).height);
exports.width = make_dimen_wrapper("width", $(exports.message_pane).width);
// Includes both scroll and arrow events. Negative means scroll up, // Includes both scroll and arrow events. Negative means scroll up,
// positive means scroll down. // positive means scroll down.
exports.last_movement_direction = 1; exports.last_movement_direction = 1;
@ -279,24 +297,6 @@ exports.scrollTop = function viewport_scrollTop(target_scrollTop) {
return ret; return ret;
}; };
function make_dimen_wrapper(dimen_name, dimen_func) {
dimensions[dimen_name] = new util.CachedValue({
compute_value() {
return dimen_func.call(exports.message_pane);
},
});
return function viewport_dimension_wrapper(...args) {
if (args.length !== 0) {
dimensions[dimen_name].reset();
return dimen_func.apply(exports.message_pane, args);
}
return dimensions[dimen_name].get();
};
}
exports.height = make_dimen_wrapper("height", $(exports.message_pane).height);
exports.width = make_dimen_wrapper("width", $(exports.message_pane).width);
exports.stop_auto_scrolling = function () { exports.stop_auto_scrolling = function () {
if (in_stoppable_autoscroll) { if (in_stoppable_autoscroll) {
exports.message_pane.stop(); exports.message_pane.stop();