Add keyboard shortcuts to main menu.

1. Show shortcuts for easy navigation.
This commit is contained in:
Jacob Schatz 2017-03-26 10:24:33 -04:00
parent 5fbb9e9544
commit 71eae2089e
3 changed files with 83 additions and 3 deletions

View file

@ -19,6 +19,45 @@
return _this.focusFilter(e); return _this.focusFilter(e);
}; };
})(this)); })(this));
function gotoMenu(menu){
if($('.global-dropdown.open').length) {
window.location.href = $('.global-dropdown-menu .dashboard-shortcuts-'+menu).attr('href');
}
}
Mousetrap.bind('m', function() {
$('.global-dropdown-menu').addClass('shortcuts')
$('.global-dropdown-toggle').trigger('click');
});
Mousetrap.bind('P', function() {
gotoMenu('projects');
});
Mousetrap.bind('A', function() {
gotoMenu('activity');
});
Mousetrap.bind('G', function() {
gotoMenu('groups');
});
Mousetrap.bind('L', function() {
gotoMenu('milestones');
});
Mousetrap.bind('I', function() {
gotoMenu('issues');
});
Mousetrap.bind('M', function() {
gotoMenu('merge_requests');
});
Mousetrap.bind('S', function() {
gotoMenu('snippets');
});
Mousetrap.bind(['ctrl+shift+p', 'command+shift+p'], this.toggleMarkdownPreview); Mousetrap.bind(['ctrl+shift+p', 'command+shift+p'], this.toggleMarkdownPreview);
if (typeof findFileURL !== "undefined" && findFileURL !== null) { if (typeof findFileURL !== "undefined" && findFileURL !== null) {
Mousetrap.bind('t', function() { Mousetrap.bind('t', function() {

View file

@ -187,6 +187,33 @@
} }
} }
.kbd {
display: none;
}
&.shortcuts span{
display: inline-block;
width: 140px;
}
&.shortcuts .kbd {
display: inline-block;
padding: 3px 5px;
font-size: 11px;
line-height: 10px;
color: #555;
vertical-align: middle;
background-color: #fcfcfc;
border-width: 1px;
border-style: solid;
border-color: #ccc #ccc #bbb;
border-image: none;
border-radius: 3px;
box-shadow: 0 -1px 0 #bbb inset;
width: 21px;
text-align: center;
}
ul { ul {
margin: 0; margin: 0;
padding: 0; padding: 0;

View file

@ -3,37 +3,51 @@
= link_to dashboard_projects_path, title: 'Projects', class: 'dashboard-shortcuts-projects' do = link_to dashboard_projects_path, title: 'Projects', class: 'dashboard-shortcuts-projects' do
%span %span
Projects Projects
.kbd
P
= nav_link(path: 'dashboard#activity') do = nav_link(path: 'dashboard#activity') do
= link_to activity_dashboard_path, class: 'dashboard-shortcuts-activity', title: 'Activity' do = link_to activity_dashboard_path, class: 'dashboard-shortcuts-activity', title: 'Activity' do
%span %span
Activity Activity
.kbd
A
- if koding_enabled? - if koding_enabled?
= nav_link(controller: :koding) do = nav_link(controller: :koding) do
= link_to koding_path, title: 'Koding' do = link_to koding_path, title: 'Koding' do
%span %span
Koding Koding
= nav_link(controller: [:groups, 'groups/milestones', 'groups/group_members']) do = nav_link(controller: [:groups, 'groups/milestones', 'groups/group_members']) do
= link_to dashboard_groups_path, title: 'Groups' do = link_to dashboard_groups_path, class: 'dashboard-shortcuts-groups', title: 'Groups' do
%span %span
Groups Groups
.kbd
G
= nav_link(controller: 'dashboard/milestones') do = nav_link(controller: 'dashboard/milestones') do
= link_to dashboard_milestones_path, title: 'Milestones' do = link_to dashboard_milestones_path, class: 'dashboard-shortcuts-milestones', title: 'Milestones' do
%span %span
Milestones Milestones
.kbd
L
= nav_link(path: 'dashboard#issues') do = nav_link(path: 'dashboard#issues') do
= link_to assigned_issues_dashboard_path, title: 'Issues', class: 'dashboard-shortcuts-issues' do = link_to assigned_issues_dashboard_path, title: 'Issues', class: 'dashboard-shortcuts-issues' do
%span %span
Issues Issues
.badge= number_with_delimiter(cached_assigned_issuables_count(current_user, :issues, :opened)) .badge= number_with_delimiter(cached_assigned_issuables_count(current_user, :issues, :opened))
.kbd
I
= nav_link(path: 'dashboard#merge_requests') do = nav_link(path: 'dashboard#merge_requests') do
= link_to assigned_mrs_dashboard_path, title: 'Merge Requests', class: 'dashboard-shortcuts-merge_requests' do = link_to assigned_mrs_dashboard_path, title: 'Merge Requests', class: 'dashboard-shortcuts-merge_requests' do
%span %span
Merge Requests Merge Requests
.badge= number_with_delimiter(cached_assigned_issuables_count(current_user, :merge_requests, :opened)) .badge= number_with_delimiter(cached_assigned_issuables_count(current_user, :merge_requests, :opened))
.kbd
M
= nav_link(controller: 'dashboard/snippets') do = nav_link(controller: 'dashboard/snippets') do
= link_to dashboard_snippets_path, title: 'Snippets' do = link_to dashboard_snippets_path, class: 'dashboard-shortcuts-snippets', title: 'Snippets' do
%span %span
Snippets Snippets
.kbd
S
%li.divider %li.divider
%li %li
= link_to "Help", help_path, title: 'About GitLab CE', class: 'about-gitlab' = link_to "Help", help_path, title: 'About GitLab CE', class: 'about-gitlab'