2016-03-19 21:37:04 +01:00
|
|
|
'use strict';
|
|
|
|
|
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-05-20 21:35:12 +02:00
|
|
|
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-03-19 21:37:04 +01:00
|
|
|
}
|
|
|
|
|
2016-04-08 10:35:38 +02:00
|
|
|
render(ctx) {
|
2016-05-29 12:27:02 +02:00
|
|
|
this._lastCtx = ctx;
|
2016-05-20 21:35:12 +02:00
|
|
|
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
|
|
|
|
2016-05-29 12:27:02 +02:00
|
|
|
show() {
|
|
|
|
this._navHolder.style.visibility = 'initial';
|
|
|
|
this._navHolder.style.position = 'initial';
|
|
|
|
}
|
2016-04-08 10:35:38 +02:00
|
|
|
|
2016-05-29 12:27:02 +02:00
|
|
|
hide() {
|
|
|
|
this._navHolder.style.visibility = 'hidden';
|
|
|
|
this._navHolder.style.position = 'fixed';
|
2016-03-19 21:37:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
activate(itemName) {
|
2016-05-29 12:27:02 +02:00
|
|
|
if (itemName == 'home') {
|
|
|
|
this.hide();
|
|
|
|
} else {
|
|
|
|
this.show();
|
|
|
|
}
|
2016-03-19 21:37:04 +01:00
|
|
|
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;
|