szurubooru/client/js/views/top_nav_view.js

34 lines
959 B
JavaScript
Raw Normal View History

'use strict';
const views = require('../util/views.js');
class TopNavView {
constructor() {
this._template = views.getTemplate('top-nav');
this._navHolder = document.getElementById('top-nav-holder');
2016-05-29 12:27:02 +02:00
this._lastCtx = null;
}
2016-04-08 10:35:38 +02:00
render(ctx) {
2016-05-29 12:27:02 +02:00
this._lastCtx = ctx;
const target = this._navHolder;
const source = this._template(ctx);
2016-05-29 12:27:02 +02:00
views.showView(this._navHolder, source);
}
2016-04-08 10:35:38 +02: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';
}
}
}
module.exports = TopNavView;