mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-24 08:09:13 -05:00
FIX: Keep topic list items on screen when using keyboard.
This commit is contained in:
parent
47d821cd31
commit
2681717a87
1 changed files with 6 additions and 14 deletions
|
@ -261,26 +261,18 @@ Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({
|
||||||
|
|
||||||
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') {
|
||||||
this._scrollList($article, direction);
|
this._scrollList($article, direction);
|
||||||
} else {
|
} else {
|
||||||
Discourse.URL.jumpToPost(rgx[1]);
|
Discourse.URL.jumpToPost(rgx[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_scrollList: function($article, direction) {
|
_scrollList: function($article, direction) {
|
||||||
var $document = $(document),
|
// Try to keep the article on screen
|
||||||
distToElement = $article.position().top + $article.height() - $(window).height() - $document.scrollTop();
|
var scrollPos = $article.position().top - ($(window).height() * 0.5);
|
||||||
|
if (scrollPos < 0) { scrollPos = 0; }
|
||||||
// cut some bottom slack
|
$('html, body').scrollTop(scrollPos);
|
||||||
distToElement += 40;
|
|
||||||
|
|
||||||
// don't scroll backwards, its silly
|
|
||||||
if((direction > 0 && distToElement < 0) || (direction < 0 && distToElement > 0)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$('html, body').scrollTop($document.scrollTop() + distToElement);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_findArticles: function() {
|
_findArticles: function() {
|
||||||
|
|
Loading…
Reference in a new issue