From e7dd634183154949fab7aa0b00844eb645cb87e5 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 9 Dec 2019 22:42:43 +0300 Subject: exp: auto-disable smooth scrolling for repeat hotkey events --- js/Article.js | 48 +++++++++++++++++++++++++++++------------------- js/Headlines.js | 19 +++++++++++++++---- js/tt-rss.js | 26 +++++++++++++------------- 3 files changed, 57 insertions(+), 36 deletions(-) (limited to 'js') diff --git a/js/Article.js b/js/Article.js index 468388789..9c7ccf074 100644 --- a/js/Article.js +++ b/js/Article.js @@ -2,6 +2,7 @@ /* global __, ngettext */ define(["dojo/_base/declare"], function (declare) { Article = { + _scroll_reset_timeout: false, getScoreClass: function (score) { if (score > 500) { return "score-high"; @@ -314,33 +315,42 @@ define(["dojo/_base/declare"], function (declare) { else return 0; }, - scrollByPages: function (offset) { + scrollByPages: function (page_offset, event) { + let elem; + if (!App.isCombinedMode()) { - const ci = $("content-insert"); - if (ci) { - ci.scrollTop += ci.offsetHeight * offset * 0.99; - } + elem = $("content-insert"); } else { - const hi = $("headlines-frame"); - if (hi) { - hi.scrollTop += hi.offsetHeight * offset * 0.99; - } - + elem = $("headlines-frame"); } + + const offset = elem.offsetHeight * page_offset * 0.99; + + this.scroll(offset, event); }, - scroll: function (offset) { + scroll: function (offset, event) { + + let elem; + if (!App.isCombinedMode()) { - const ci = $("content-insert"); - if (ci) { - ci.scrollTop += offset; - } + elem = $("content-insert"); } else { - const hi = $("headlines-frame"); - if (hi) { - hi.scrollTop += offset; - } + elem = $("headlines-frame"); + } + + if (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; }, mouseIn: function (id) { this.post_under_pointer = id; diff --git a/js/Headlines.js b/js/Headlines.js index 52c1c5842..058376266 100755 --- a/js/Headlines.js +++ b/js/Headlines.js @@ -7,6 +7,7 @@ define(["dojo/_base/declare"], function (declare) { _observer_counters_timeout: 0, headlines: [], current_first_id: 0, + _scroll_reset_timeout: false, row_observer: new MutationObserver((mutations) => { const modified = []; @@ -1383,11 +1384,21 @@ define(["dojo/_base/declare"], function (declare) { } }, - scrollByPages: function (offset) { - const hi = $("headlines-frame"); - if (hi) { - hi.scrollTop += hi.offsetHeight * offset * 0.99; + scrollByPages: function (offset, event) { + const elem = $("headlines-frame"); + + if (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 += elem.offsetHeight * offset * 0.99; }, initHeadlinesMenu: function () { if (!dijit.byId("headlinesMenu")) { diff --git a/js/tt-rss.js b/js/tt-rss.js index f5444207d..8972543c9 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -213,7 +213,7 @@ require(["dojo/_base/kernel", const action_func = this.hotkey_actions[action_name]; if (action_func != null) { - action_func(); + action_func(event); event.stopPropagation(); return false; } @@ -324,23 +324,23 @@ require(["dojo/_base/kernel", this.hotkey_actions["catchup_above"] = function () { Headlines.catchupRelativeTo(0); }; - this.hotkey_actions["article_scroll_down"] = function () { - Article.scroll(40); + this.hotkey_actions["article_scroll_down"] = function (event) { + Article.scroll(80, event); }; - this.hotkey_actions["article_scroll_up"] = function () { - Article.scroll(-40); + this.hotkey_actions["article_scroll_up"] = function (event) { + Article.scroll(-80, event); }; - this.hotkey_actions["next_article_page"] = function () { - Headlines.scrollByPages(1); + this.hotkey_actions["next_article_page"] = function (event) { + Headlines.scrollByPages(1, event); }; - this.hotkey_actions["prev_article_page"] = function () { - Headlines.scrollByPages(-1); + this.hotkey_actions["prev_article_page"] = function (event) { + Headlines.scrollByPages(-1, event); }; - this.hotkey_actions["article_page_down"] = function () { - Article.scrollByPages(1); + this.hotkey_actions["article_page_down"] = function (event) { + Article.scrollByPages(1, event); }; - this.hotkey_actions["article_page_up"] = function () { - Article.scrollByPages(-1); + this.hotkey_actions["article_page_up"] = function (event) { + Article.scrollByPages(-1, event); }; this.hotkey_actions["close_article"] = function () { if (App.isCombinedMode()) { -- cgit v1.2.3