client/top-nav: reuse makeAccessLink

This commit is contained in:
rr- 2016-05-29 12:24:48 +02:00
parent 79f22d27cd
commit bab88f4739
4 changed files with 12 additions and 9 deletions

View file

@ -111,6 +111,9 @@ nav.text-nav
background: $focused-tab-background-color
outline: 0
a .access-key
text-decoration: underline
#top-nav
background: $top-nav-color
margin: 0

View file

@ -5,7 +5,7 @@
--><li data-name='<%= key %>'><!--
--><a href='<%= item.url %>' accesskey='<%= item.accessKey %>'><!--
--><% if (item.imageUrl) { print(ctx.makeThumbnail(item.imageUrl)); } %><!--
--><span class='text'><%- item.name %></span><!--
--><span class='text'><%= ctx.makeAccessKey(item.name, item.accessKey) %></span><!--
--></a><!--
--></li><!--
--><% } %><!--

View file

@ -159,6 +159,13 @@ function makeFlexboxAlign(options) {
.map(() => '<li class="flexbox-dummy"></li>').join('');
}
function makeAccessKey(html, key) {
const regex = new RegExp('(' + key + ')', 'i');
html = html.replace(
regex, '<span class="access-key" data-accesskey="$1">$1</span>');
return html;
}
function _serializeElement(name, attributes) {
return [name]
.concat(Object.keys(attributes).map(key => {
@ -260,6 +267,7 @@ function getTemplate(templatePath) {
makeColorInput: makeColorInput,
makeTagLink: makeTagLink,
makeFlexboxAlign: makeFlexboxAlign,
makeAccessKey: makeAccessKey,
});
return htmlToDom(templateFactory(ctx));
};

View file

@ -12,14 +12,6 @@ class TopNavView {
const target = this._navHolder;
const source = this._template(ctx);
for (let link of source.querySelectorAll('a')) {
const regex = new RegExp(
'(' + link.getAttribute('accesskey') + ')', 'i');
const span = link.querySelector('span.text');
span.innerHTML = span.textContent.replace(
regex,
'<span class="access-key" data-accesskey="$1">$1</span>');
}
views.showView(this._navHolder, source);
}