Merge pull request from cpradio/master

UX: Add focus to menu only if it comes from a keyboard shortcut and improve keyboard functionality for search
This commit is contained in:
Neil Lalonde 2014-08-29 17:04:52 -04:00
commit 1291e94c78
4 changed files with 15 additions and 29 deletions
app/assets/javascripts/discourse
test/javascripts/integration

View file

@ -36,8 +36,6 @@ Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({
'm t': 'div.notification-options li[data-id="2"] a', // mark topic as tracking
'm w': 'div.notification-options li[data-id="3"] a', // mark topic as watching
'n': '#user-notifications', // open notifications menu
'=': '#site-map', // open site map menu
'p': '#current-user', // open current user menu
'o,enter': '.topic-list tr.selected a.title', // open selected topic
'shift+r': '#topic-footer-buttons button.create', // reply to topic
'shift+s': '#topic-footer-buttons button.share', // share topic
@ -54,6 +52,8 @@ Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({
'`': 'nextSection',
'~': 'prevSection',
'/': 'showSearch',
'=': 'showSiteMap', // open site map menu
'p': 'showCurrentUser', // open current user menu
'ctrl+f': 'showBuiltinSearch',
'command+f': 'showBuiltinSearch',
'?': 'showHelpModal', // open keyboard shortcut help
@ -145,6 +145,16 @@ Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({
return false;
},
showSiteMap: function() {
$('#site-map').click();
$('#site-map-dropdown a:first').focus();
},
showCurrentUser: function() {
$('#current-user').click();
$('#user-dropdown a:first').focus();
},
showHelpModal: function() {
Discourse.__container__.lookup('controller:application').send('showKeyboardShortcutsHelp');
},

View file

@ -3,7 +3,6 @@ export default Ember.CollectionView.extend({
itemViewClass: Discourse.GroupedView.extend({
tagName: 'li',
classNameBindings: ['selected'],
templateName: Discourse.computed.fmt('parentView.type', "search/%@_result"),
selected: Discourse.computed.propertyEqual('content.index', 'controller.selectedIndex')
templateName: Discourse.computed.fmt('parentView.type', "search/%@_result")
})
});

View file

@ -2,28 +2,5 @@ export default Discourse.View.extend({
tagName: 'div',
classNames: ['d-dropdown'],
elementId: 'search-dropdown',
templateName: 'search',
didInsertElement: function() {
// Delegate ESC to the composer
var controller = this.get('controller');
return $('body').on('keydown.search', function(e) {
if ($('#search-dropdown').is(':visible')) {
switch (e.which) {
case 13:
controller.select();
e.preventDefault();
break;
case 38:
controller.moveUp();
e.preventDefault();
break;
case 40:
controller.moveDown();
e.preventDefault();
break;
}
}
});
}
templateName: 'search'
});

View file

@ -39,6 +39,6 @@ test("header", function() {
fillIn("#search-term", "hello");
andThen(function() {
ok(exists("#search-dropdown .heading"), "when user completes a search, search box shows search results");
equal(find("#search-dropdown .selected a").attr("href"), "some-url", "the first search result is selected");
equal(find("#search-dropdown a:not(.filter):first").attr("href"), "some-url", "there is a search result");
});
});