szurubooru/client/js/views/top_nav_view.js

43 lines
1.3 KiB
JavaScript
Raw Normal View History

'use strict';
require('../util/handlebars-helpers.js');
const views = require('../util/views.js');
class TopNavView {
constructor() {
this.template = views.getTemplate('top-nav');
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
views.showView(this.navHolder, source);
}
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';
}
}
}
module.exports = TopNavView;