front/nav: add access keys

This commit is contained in:
rr- 2016-03-31 21:15:05 +02:00
parent a7bc3c3d99
commit cb980ddc45
4 changed files with 24 additions and 13 deletions

View file

@ -102,6 +102,9 @@ nav.text-nav ul li.active a {
#top-nav ul li[data-name=help] { #top-nav ul li[data-name=help] {
float: none; float: none;
} }
#top-nav .access-key {
text-decoration: underline;
}
.messages .message { .messages .message {
padding: 0.5em; padding: 0.5em;

View file

@ -3,7 +3,7 @@
-->{{#each items}}<!-- -->{{#each items}}<!--
-->{{#if this.available}}<!-- -->{{#if this.available}}<!--
--><li data-name='{{@key}}'><!-- --><li data-name='{{@key}}'><!--
--><a href='{{this.url}}'>{{this.name}}</a><!-- --><a href='{{this.url}}' accesskey='{{this.accessKey}}'>{{this.name}}</a><!--
--></li><!-- --></li><!--
-->{{/if}}<!-- -->{{/if}}<!--
-->{{/each}}<!-- -->{{/each}}<!--

View file

@ -1,7 +1,8 @@
'use strict'; 'use strict';
class NavigationItem { class NavigationItem {
constructor(name, url) { constructor(accessKey, name, url) {
this.accessKey = accessKey;
this.name = name; this.name = name;
this.url = url; this.url = url;
this.available = true; this.available = true;
@ -15,17 +16,17 @@ class TopNavigationController {
this.activeItem = null; this.activeItem = null;
this.items = { this.items = {
'home': new NavigationItem('Home', '/'), 'home': new NavigationItem('H', 'Home', '/'),
'posts': new NavigationItem('Posts', '/posts'), 'posts': new NavigationItem('P', 'Posts', '/posts'),
'upload': new NavigationItem('Upload', '/upload'), 'upload': new NavigationItem('U', 'Upload', '/upload'),
'comments': new NavigationItem('Comments', '/comments'), 'comments': new NavigationItem('C', 'Comments', '/comments'),
'tags': new NavigationItem('Tags', '/tags'), 'tags': new NavigationItem('T', 'Tags', '/tags'),
'users': new NavigationItem('Users', '/users'), 'users': new NavigationItem('S', 'Users', '/users'),
'account': new NavigationItem('Account', '/user/{me}'), 'account': new NavigationItem('A', 'Account', '/user/{me}'),
'register': new NavigationItem('Register', '/register'), 'register': new NavigationItem('R', 'Register', '/register'),
'login': new NavigationItem('Log in', '/login'), 'login': new NavigationItem('L', 'Log in', '/login'),
'logout': new NavigationItem('Logout', '/logout'), 'logout': new NavigationItem('O', 'Logout', '/logout'),
'help': new NavigationItem('Help', '/help'), 'help': new NavigationItem('E', 'Help', '/help'),
}; };
this.api.authenticated.listen(() => { this.api.authenticated.listen(() => {

View file

@ -11,6 +11,13 @@ class TopNavigationView extends BaseView {
render(items) { render(items) {
this.navHolder.innerHTML = this.template({items: items}); this.navHolder.innerHTML = this.template({items: items});
for (let link of this.navHolder.querySelectorAll('a')) {
const regex = new RegExp(
'(' + link.getAttribute('accesskey') + ')', 'i');
link.innerHTML = link.textContent.replace(
regex,
'<span class="access-key" data-accesskey="$1">$1</span>');
}
} }
activate(itemName) { activate(itemName) {