2016-03-19 21:37:04 +01:00
|
|
|
'use strict';
|
|
|
|
|
2016-04-11 18:36:27 +02:00
|
|
|
require('../util/handlebars-helpers.js');
|
2016-04-09 18:54:23 +02:00
|
|
|
const views = require('../util/views.js');
|
2016-03-19 21:37:04 +01:00
|
|
|
|
2016-04-09 18:54:23 +02:00
|
|
|
class TopNavView {
|
2016-03-29 12:32:51 +02:00
|
|
|
constructor() {
|
2016-04-09 18:54:23 +02:00
|
|
|
this.template = views.getTemplate('top-nav');
|
2016-03-19 21:37:04 +01:00
|
|
|
this.navHolder = document.getElementById('top-nav-holder');
|
|
|
|
}
|
|
|
|
|
2016-04-08 10:35:38 +02:00
|
|
|
render(ctx) {
|
|
|
|
const target = this.navHolder;
|
|
|
|
const source = this.template(ctx);
|
|
|
|
|
2016-04-14 20:24:22 +02:00
|
|
|
for (let link of source.querySelectorAll('a')) {
|
2016-03-31 21:15:05 +02:00
|
|
|
const regex = new RegExp(
|
|
|
|
'(' + link.getAttribute('accesskey') + ')', 'i');
|
2016-04-14 20:24:22 +02:00
|
|
|
const span = link.querySelector('span.text');
|
|
|
|
span.innerHTML = span.textContent.replace(
|
2016-03-31 21:15:05 +02:00
|
|
|
regex,
|
|
|
|
'<span class="access-key" data-accesskey="$1">$1</span>');
|
|
|
|
}
|
2016-04-08 10:35:38 +02:00
|
|
|
|
2016-04-09 18:54:23 +02:00
|
|
|
views.showView(this.navHolder, source);
|
2016-03-19 21:37:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
activate(itemName) {
|
|
|
|
const allItemsSelector = '#top-nav-holder [data-name]';
|
|
|
|
const currentItemSelector =
|
|
|
|
'#top-nav-holder [data-name="' + itemName + '"]';
|
|
|
|
for (let item of document.querySelectorAll(allItemsSelector)) {
|
|
|
|
item.className = '';
|
|
|
|
}
|
|
|
|
const currentItem = document.querySelectorAll(currentItemSelector);
|
|
|
|
if (currentItem.length > 0) {
|
|
|
|
currentItem[0].className = 'active';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-01 00:20:34 +02:00
|
|
|
module.exports = TopNavView;
|