diff options
author | Andrew Dolgov <[email protected]> | 2020-05-17 08:25:51 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2020-05-17 08:25:51 +0300 |
commit | 9ae9302b6b3526b15652715f9741dad8c51f9fee (patch) | |
tree | 9b3efedd928a5b074e4b60c6f4184c804877111e /js/AppBase.js | |
parent | 3dc506a19ac483c60cf2800066e4403df4db0ef1 (diff) |
implement keyboard-related changes discussed in https://community.tt-rss.org/t/changing-the-amount-of-scroll-by-arrow-key/3452/7
Diffstat (limited to 'js/AppBase.js')
-rw-r--r-- | js/AppBase.js | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/js/AppBase.js b/js/AppBase.js index 86cc44e8a..49d276341 100644 --- a/js/AppBase.js +++ b/js/AppBase.js @@ -7,6 +7,33 @@ define(["dojo/_base/declare"], function (declare) { hotkey_prefix: 0, hotkey_prefix_pressed: false, hotkey_prefix_timeout: 0, + Scrollable: { + scrollByPages: function (elem, page_offset, event) { + if (!elem) return; + + /* keep a line or so from the previous page */ + const offset = (elem.offsetHeight - (page_offset > 0 ? 50 : -50)) * page_offset; + + this.scroll(elem, offset, event); + }, + scroll: function(elem, offset, event) { + if (!elem) return; + + if (event && event.repeat) { + elem.addClassName("forbid-smooth-scroll"); + window.clearTimeout(this._scroll_reset_timeout); + + this._scroll_reset_timeout = window.setTimeout(() => { + if (elem) elem.removeClassName("forbid-smooth-scroll"); + }, 250) + + } else { + elem.removeClassName("forbid-smooth-scroll"); + } + + elem.scrollTop += offset; + }, + }, constructor: function() { window.onerror = this.Error.onWindowError; }, |