BUGFIX: do not allow loop over topics list using keyboard shortcuts

This commit is contained in:
Régis Hanol 2014-01-23 00:38:34 +01:00
parent ae3b53bb76
commit 202d1064ea
1 changed files with 9 additions and 5 deletions

View File

@ -103,7 +103,7 @@ Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({
} }
}, },
_moveSelection: function(num) { _moveSelection: function(direction) {
var $articles = this._findArticles(); var $articles = this._findArticles();
if (typeof $articles === 'undefined') { if (typeof $articles === 'undefined') {
@ -111,8 +111,12 @@ Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({
} }
var $selected = $articles.filter('.selected'), var $selected = $articles.filter('.selected'),
index = $articles.index($selected), index = $articles.index($selected);
$article = $articles.eq(index + num);
// loop is not allowed
if (direction === -1 && index === 0) { return; }
var $article = $articles.eq(index + direction);
if ($article.size() > 0) { if ($article.size() > 0) {
$articles.removeClass('selected'); $articles.removeClass('selected');
@ -140,10 +144,10 @@ Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({
} }
}, },
_changeSection: function(num) { _changeSection: function(direction) {
var $sections = $('#navigation-bar').find('li'), var $sections = $('#navigation-bar').find('li'),
index = $sections.index('.active'); index = $sections.index('.active');
$sections.eq(index + num).find('a').click(); $sections.eq(index + direction).find('a').click();
} }
}); });