szurubooru/static/js/views/top_navigation_view.js

38 lines
1.2 KiB
JavaScript
Raw Normal View History

'use strict';
const BaseView = require('./base_view.js');
class TopNavigationView extends BaseView {
constructor() {
super();
2016-03-27 21:10:41 +02:00
this.template = this.getTemplate('top-navigation-template');
this.navHolder = document.getElementById('top-nav-holder');
}
render(items) {
this.navHolder.innerHTML = this.template({items: items});
2016-03-31 21:15:05 +02:00
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) {
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 = TopNavigationView;