DEV: Minor code improvements.
This commit is contained in:
parent
3d0008165f
commit
fd9671f7fe
|
@ -76,6 +76,8 @@ const bindings = {
|
|||
"x t": { click: "#dismiss-topics,#dismiss-topics-top" } // dismiss topics
|
||||
};
|
||||
|
||||
const animationDuration = 100;
|
||||
|
||||
export default {
|
||||
bindEvents(keyTrapper, container) {
|
||||
this.keyTrapper = keyTrapper;
|
||||
|
@ -420,7 +422,8 @@ export default {
|
|||
// Pressing a move key (J/K) very quick (i.e. keeping J or K pressed) will
|
||||
// move fast by disabling smooth page scrolling.
|
||||
const now = +new Date();
|
||||
const fast = this._lastMoveTime && now - this._lastMoveTime < 150;
|
||||
const fast =
|
||||
this._lastMoveTime && now - this._lastMoveTime < 1.5 * animationDuration;
|
||||
this._lastMoveTime = now;
|
||||
|
||||
const $articles = this._findArticles();
|
||||
|
@ -446,14 +449,9 @@ export default {
|
|||
const index = $articles.index($selected);
|
||||
let $article = $articles.eq(index);
|
||||
|
||||
/*
|
||||
* Try doing a page scroll in the context of current post.
|
||||
*/
|
||||
|
||||
// Try doing a page scroll in the context of current post.
|
||||
if (!fast && direction !== 0 && $article.length > 0) {
|
||||
/** @var Begin and end offsets for current article
|
||||
* The beginning of first article is the beginning of the page.
|
||||
*/
|
||||
// The beginning of first article is the beginning of the page.
|
||||
const beginArticle =
|
||||
$article.is(".topic-post") && $article.find("#post_1").length
|
||||
? 0
|
||||
|
@ -461,7 +459,6 @@ export default {
|
|||
const endArticle =
|
||||
$article.offset().top + $article[0].getBoundingClientRect().height;
|
||||
|
||||
/** @var Begin and end offsets for screen */
|
||||
const beginScreen = $(window).scrollTop();
|
||||
const endScreen = beginScreen + window.innerHeight;
|
||||
|
||||
|
@ -482,10 +479,7 @@ export default {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Try scrolling to post above or below.
|
||||
*/
|
||||
|
||||
// Try scrolling to post above or below.
|
||||
if ($selected.length !== 0) {
|
||||
if (direction === -1 && index === 0) return;
|
||||
if (direction === 1 && index === $articles.length - 1) return;
|
||||
|
@ -512,9 +506,7 @@ export default {
|
|||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* Otherwise scroll through the suggested topic list.
|
||||
*/
|
||||
// Otherwise scroll through the suggested topic list.
|
||||
this._scrollList($article, direction);
|
||||
}
|
||||
},
|
||||
|
@ -522,7 +514,7 @@ export default {
|
|||
_scrollTo(scrollTop, complete) {
|
||||
$("html, body")
|
||||
.stop(true, true)
|
||||
.animate({ scrollTop }, { duration: 100, complete });
|
||||
.animate({ scrollTop }, { duration: animationDuration, complete });
|
||||
},
|
||||
|
||||
_scrollList($article) {
|
||||
|
@ -554,7 +546,7 @@ export default {
|
|||
}
|
||||
this._scrollAnimation = $("html, body").animate(
|
||||
{ scrollTop: scrollPos + "px" },
|
||||
100
|
||||
animationDuration
|
||||
);
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in New Issue