mirror of
https://github.com/discourse/discourse.git
synced 2025-04-29 10:54:34 +08:00
BUGFIX: j/k navigation was scrolling stuff in insane ways on first press
This commit is contained in:
parent
bb887964b1
commit
2d9db9ebc9
@ -133,11 +133,31 @@ Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({
|
|||||||
// loop is not allowed
|
// loop is not allowed
|
||||||
if (direction === -1 && index === 0) { return; }
|
if (direction === -1 && index === 0) { return; }
|
||||||
|
|
||||||
|
// if nothing is selected go to the first post on screen
|
||||||
|
if ($selected.length === 0) {
|
||||||
|
var scrollTop = $('body').scrollTop();
|
||||||
|
|
||||||
|
index = 0;
|
||||||
|
$articles.each(function(){
|
||||||
|
var top = $(this).position().top;
|
||||||
|
if(top > scrollTop) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
index += 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
if(index >= $articles.length){
|
||||||
|
index = $articles.length - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var $article = $articles.eq(index + direction);
|
var $article = $articles.eq(index + direction);
|
||||||
|
|
||||||
if ($article.size() > 0) {
|
if ($article.size() > 0) {
|
||||||
$articles.removeClass('selected');
|
$articles.removeClass('selected');
|
||||||
$article.addClass('selected');
|
Em.run.next(function(){
|
||||||
|
$article.addClass('selected');
|
||||||
|
});
|
||||||
|
|
||||||
var rgx = new RegExp("post-cloak-(\\d+)").exec($article.parent()[0].id);
|
var rgx = new RegExp("post-cloak-(\\d+)").exec($article.parent()[0].id);
|
||||||
if (rgx === null || typeof rgx[1] === 'undefined') {
|
if (rgx === null || typeof rgx[1] === 'undefined') {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user