FIX: We should only intercept enter as a keypress when a selector
matches it.
This commit is contained in:
parent
09bc319fd4
commit
47d821cd31
|
@ -1,12 +1,4 @@
|
|||
/**
|
||||
Keyboard Shortcut related functions.
|
||||
|
||||
@class KeyboardShortcuts
|
||||
@namespace Discourse
|
||||
@module Discourse
|
||||
**/
|
||||
Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({
|
||||
PATH_BINDINGS: {
|
||||
var PATH_BINDINGS = {
|
||||
'g h': '/',
|
||||
'g l': '/latest',
|
||||
'g n': '/new',
|
||||
|
@ -16,7 +8,7 @@ Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({
|
|||
'g t': '/top'
|
||||
},
|
||||
|
||||
SELECTED_POST_BINDINGS: {
|
||||
SELECTED_POST_BINDINGS = {
|
||||
'b': 'toggleBookmark',
|
||||
'd': 'deletePost',
|
||||
'e': 'editPost',
|
||||
|
@ -26,7 +18,7 @@ Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({
|
|||
't': 'replyAsNewTopic'
|
||||
},
|
||||
|
||||
CLICK_BINDINGS: {
|
||||
CLICK_BINDINGS = {
|
||||
// star topic
|
||||
'f': '#topic-footer-buttons button.star, .topic-list tr.topic-list-item.selected a.star',
|
||||
|
||||
|
@ -44,7 +36,7 @@ Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({
|
|||
's': '.topic-post.selected a.post-date' // share post
|
||||
},
|
||||
|
||||
FUNCTION_BINDINGS: {
|
||||
FUNCTION_BINDINGS = {
|
||||
'c': 'createTopic', // create new topic
|
||||
'home': 'goToFirstPost',
|
||||
'#': 'toggleProgress',
|
||||
|
@ -62,15 +54,18 @@ Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({
|
|||
'command+f': 'showBuiltinSearch',
|
||||
'?': 'showHelpModal', // open keyboard shortcut help
|
||||
'q': 'quoteReply'
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({
|
||||
bindEvents: function(keyTrapper, container) {
|
||||
this.keyTrapper = keyTrapper;
|
||||
this.container = container;
|
||||
_.each(this.PATH_BINDINGS, this._bindToPath, this);
|
||||
_.each(this.CLICK_BINDINGS, this._bindToClick, this);
|
||||
_.each(this.SELECTED_POST_BINDINGS, this._bindToSelectedPost, this);
|
||||
_.each(this.FUNCTION_BINDINGS, this._bindToFunction, this);
|
||||
|
||||
_.each(PATH_BINDINGS, this._bindToPath, this);
|
||||
_.each(CLICK_BINDINGS, this._bindToClick, this);
|
||||
_.each(SELECTED_POST_BINDINGS, this._bindToSelectedPost, this);
|
||||
_.each(FUNCTION_BINDINGS, this._bindToFunction, this);
|
||||
},
|
||||
|
||||
quoteReply: function(){
|
||||
|
@ -190,8 +185,20 @@ Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({
|
|||
_bindToClick: function(selector, binding) {
|
||||
binding = binding.split(',');
|
||||
this.keyTrapper.bind(binding, function(e) {
|
||||
if (e) { e.preventDefault(); }
|
||||
$(selector).click();
|
||||
var $sel = $(selector);
|
||||
|
||||
// Special case: We're binding to enter.
|
||||
if (e && e.keyCode === 13) {
|
||||
// Binding to enter should only be effective when there is something
|
||||
// to select.
|
||||
if ($sel.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If effective, prevent default.
|
||||
e.preventDefault();
|
||||
}
|
||||
$sel.click();
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -214,7 +221,7 @@ Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({
|
|||
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 (direction === 1 && index === ($articles.size()-1) ) { return; }
|
||||
}
|
||||
|
||||
// if nothing is selected go to the first post on screen
|
||||
|
|
Loading…
Reference in New Issue