Skip to content

Instantly share code, notes, and snippets.

@lidlanca
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lidlanca/6db7784436c2aef88306 to your computer and use it in GitHub Desktop.
Save lidlanca/6db7784436c2aef88306 to your computer and use it in GitHub Desktop.
Discourse Console test J Keyboard Bind on load more
Discourse.KeyboardShortcuts._moveSelection = function(direction) {
var $articles = this._findArticles();
if (typeof $articles === 'undefined') {
return;
}
var $selected = $articles.filter('.selected'),
index = $articles.index($selected);
if($selected.length !== 0){ //boundries check
// loop is not allowed
if (direction === -1 && index === 0) { return; }
if (direction === 1 && index === ($articles.size()-1) ) { return;}
}
// if nothing is selected go to the first post on screen
if ($selected.length === 0) {
var scrollTop = $(document).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;
}
direction = 0;
}
var $article = $articles.eq(index + direction);
if ($article.size() > 0) {
$articles.removeClass('selected');
$article.addClass('selected');
var rgx = new RegExp("post-cloak-(\\d+)").exec($article.parent()[0].id);
if (rgx === null || typeof rgx[1] === 'undefined') {
this._scrollList($article, direction);
} else {
Discourse.URL.jumpToPost(rgx[1]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment