-
-
Save lidlanca/6db7784436c2aef88306 to your computer and use it in GitHub Desktop.
Discourse Console test J Keyboard Bind on load more
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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