Added keyboard shortcuts to top navigation

This commit is contained in:
Marcin Kurczewski 2014-09-29 22:17:32 +02:00
parent 51b3342d62
commit 6c76f016e7
4 changed files with 84 additions and 17 deletions

1
TODO
View file

@ -109,7 +109,6 @@ refactors:
miscellaneous: miscellaneous:
- use 1 token for logins, so that session isn't killed - use 1 token for logins, so that session isn't killed
- endless pager should include information about page number - endless pager should include information about page number
- add hotkeys for focusing items in top navigation
- add customizable favicon - add customizable favicon
- add customizable logo - add customizable logo
- add log engine and log everything that should be logged - add log engine and log everything that should be logged

View file

@ -36,6 +36,7 @@ App.PresenterManager = function(jQuery, topNavigationPresenter, keyboard) {
if (lastContentPresenter === null || lastContentPresenter.name !== presenter.name) { if (lastContentPresenter === null || lastContentPresenter.name !== presenter.name) {
keyboard.reset(); keyboard.reset();
topNavigationPresenter.changeTitle(null); topNavigationPresenter.changeTitle(null);
topNavigationPresenter.focus();
presenter.init.call(presenter, args, contentPresenterLoaded); presenter.init.call(presenter, args, contentPresenterLoaded);
lastContentPresenter = presenter; lastContentPresenter = presenter;
} else if (lastContentPresenter.reinit) { } else if (lastContentPresenter.reinit) {

View file

@ -47,6 +47,13 @@ App.Presenters.TopNavigationPresenter = function(
$el.find('li.' + selectedElement).find('a').addClass('active'); $el.find('li.' + selectedElement).find('a').addClass('active');
} }
function focus() {
var $tmp = jQuery('<a href="#"> </a>');
$el.prepend($tmp);
$tmp.focus();
$tmp.remove();
}
function getBaseTitle() { function getBaseTitle() {
return baseTitle; return baseTitle;
} }
@ -63,6 +70,7 @@ App.Presenters.TopNavigationPresenter = function(
init: init, init: init,
render: render, render: render,
select: select, select: select,
focus: focus,
getBaseTitle: getBaseTitle, getBaseTitle: getBaseTitle,
changeTitle: changeTitle, changeTitle: changeTitle,
}; };

View file

@ -1,35 +1,94 @@
<ul> <ul>
<% <%
var links = [['home', '#/home', 'Home', 'fa-home']]; var links = [];
links.push({
target: '#/home',
title: 'Home',
icon: 'fa-home'});
if (canListPosts) { if (canListPosts) {
links.push(['posts', '#/posts', 'Posts', 'fa-th']); links.push({
target: '#/posts',
title: 'Posts',
icon: 'fa-th'});
if (canUploadPosts) { if (canUploadPosts) {
links.push(['upload', '#/upload', 'Upload', 'fa-upload']); links.push({
target: '#/upload',
title: 'Upload',
icon: 'fa-upload'});
} }
links.push(['comments', '#/comments', 'Comments', 'fa-comments']);
links.push({
target: '#/comments',
title: 'Comments',
icon: 'fa-comments'});
} }
if (canListTags) { if (canListTags) {
links.push(['tags', '#/tags', 'Tags', 'fa-tags']); links.push({
target: '#/tags',
title: 'Tags',
icon: 'fa-tags'});
} }
if (canListUsers) { if (canListUsers) {
links.push(['users', '#/users', 'Users', 'fa-users']); links.push({
target: '#/users',
title: 'Users',
icon: 'fa-users'});
} }
if (!loggedIn) { if (!loggedIn) {
links.push(['login', '#/login', 'Login', 'fa-sign-in']); links.push({
links.push(['register', '#/register', 'Register', 'fa-file-text-o']); target: '#/login',
title: 'Login',
icon: 'fa-sign-in'});
links.push({
target: '#/register',
title: 'Register',
icon: 'fa-file-text-o'});
} else { } else {
links.push(['my-account', '#/user/' + user.name, 'Account', 'fa-user']); links.push({
links.push(['logout', '#/logout', 'Logout', 'fa-sign-out']); className: 'my-account',
target: '#/user/' + user.name,
title: 'Account',
icon: 'fa-user'});
links.push({
target: '#/logout',
title: 'Logout',
icon: 'fa-sign-out'});
} }
links.push(['help', '#/help', 'Help', 'fa-question-circle']);
links.push({
target: '#/help',
title: 'Help',
icon: 'fa-question-circle'});
var takenAccessKeys = [];
links = _.map(links, function(link) {
if (typeof(link.className) === 'undefined') {
link.className = link.title.toLowerCase();
}
if (typeof(link.accessKey) === 'undefined') {
var accessKey = link.title.substring(0, 1);
if (!_.contains(takenAccessKeys, accessKey)) {
link.accessKey = accessKey;
takenAccessKeys.push(accessKey);
}
}
return link;
});
%> %>
<% _.each(links, function(link) { %><!-- <% _.each(links, function(link) { %><!--
--><% var className = link[0], target=link[1], title=link[2], iconClassName=link[3] %><!-- --><li class="<%= link.className %>">
--><li class="<%= className %>"> <a class="big-button" href="<%= link.target %>" <%= link.accessKey ? 'accessKey="' + link.accessKey + '"' : '' %>>
<a class="big-button" href="<%= target %>"> <i class="fa <%= link.icon %>"></i><br/>
<i class="fa <%= iconClassName %>"></i><br/> <%= link.title %>
<%= title %>
</a> </a>
</li><!-- </li><!--
--><% }) %> --><% }) %>