mirror of
https://github.com/zulip/zulip.git
synced 2025-11-07 23:43:43 +00:00
The functional change here is that our code to stop autoscrolling on certain events, particularly mousemove, now only runs during system initiated autoscroll events. If the user had been replying to a message, then the feature to stop autoscroll was too aggressive. This patch also starts to put more scrolling-related code into viewport.js, which will hopefully prevent some code duplication and give us a single place to control things like stopping animated scrolls. (imported from commit e7d5946b0ac7fcfda2eff1d0e2b58a78b44ecc1a)
86 lines
2.3 KiB
JavaScript
86 lines
2.3 KiB
JavaScript
var viewport = (function () {
|
|
var exports = {};
|
|
|
|
var jwindow;
|
|
var height;
|
|
var width;
|
|
var in_stoppable_autoscroll = false;
|
|
|
|
exports.scrollTop = function viewport_scrollTop () {
|
|
return jwindow.scrollTop.apply(jwindow, arguments);
|
|
};
|
|
|
|
exports.height = function viewport_height() {
|
|
if (arguments.length !== 0) {
|
|
height = undefined;
|
|
return jwindow.height.apply(jwindow, arguments);
|
|
}
|
|
if (height === undefined) {
|
|
height = $(window).height();
|
|
}
|
|
return height;
|
|
};
|
|
|
|
exports.width = function viewport_width() {
|
|
if (arguments.length !== 0) {
|
|
width = undefined;
|
|
return jwindow.width.apply(jwindow, arguments);
|
|
}
|
|
if (width === undefined) {
|
|
width = jwindow.width();
|
|
}
|
|
return width;
|
|
};
|
|
|
|
|
|
exports.stop_auto_scrolling = function() {
|
|
if (in_stoppable_autoscroll) {
|
|
$("html, body").stop();
|
|
}
|
|
};
|
|
|
|
exports.system_initiated_animate_scroll = function (scroll_amount) {
|
|
suppress_scroll_pointer_update = true; // Gets set to false in the scroll handler.
|
|
var viewport_offset = exports.scrollTop();
|
|
in_stoppable_autoscroll = true;
|
|
$("html, body").animate({
|
|
scrollTop: viewport_offset + scroll_amount,
|
|
always: function () {
|
|
in_stoppable_autoscroll = false;
|
|
}
|
|
});
|
|
};
|
|
|
|
exports.user_initiated_animate_scroll = function (scroll_amount) {
|
|
disable_pointer_movement = true;
|
|
in_stoppable_autoscroll = false; // defensive
|
|
|
|
// We use $('html, body') because you can't animate window.scrollTop
|
|
// on Chrome (http://bugs.jquery.com/ticket/10419).
|
|
$('html, body').animate({
|
|
scrollTop: viewport.scrollTop() + scroll_amount
|
|
}, {
|
|
complete: function () {
|
|
// The complete callback is actually called before the
|
|
// scrolling has completed, so we try to let scrolling
|
|
// finish before allowing pointer movements again or the
|
|
// pointer may still move.
|
|
setTimeout(function () {
|
|
disable_pointer_movement = false;
|
|
}, 50);
|
|
}
|
|
});
|
|
};
|
|
|
|
$(function () {
|
|
jwindow = $(window);
|
|
// This handler must be placed before all resize handlers in our application
|
|
jwindow.resize(function () {
|
|
height = undefined;
|
|
width = undefined;
|
|
});
|
|
});
|
|
|
|
return exports;
|
|
}());
|