Mobile sidebar nav (burger, overlay, Esc), bigger bolder accordion arrow, text/arrow centering, nav active on both menus
This commit is contained in:
@@ -84,17 +84,20 @@
|
||||
/* Активный пункт меню */
|
||||
function initNavActive() {
|
||||
var path = window.location.pathname;
|
||||
var links = [].slice.call(document.querySelectorAll('#top-nav .nav-link'));
|
||||
var best = null;
|
||||
var links = [].slice.call(document.querySelectorAll('#top-nav .nav-link, #mobile-nav .nav-link'));
|
||||
var bestHref = null;
|
||||
var bestLen = -1;
|
||||
links.forEach(function (a) {
|
||||
var href = a.getAttribute('href') || '';
|
||||
if (href === '/') return;
|
||||
if (path === href || path.indexOf(href + '/') === 0) {
|
||||
if (href.length > bestLen) { best = a; bestLen = href.length; }
|
||||
if (href.length > bestLen) { bestHref = href; bestLen = href.length; }
|
||||
}
|
||||
});
|
||||
if (best) best.classList.add('active');
|
||||
if (!bestHref) return;
|
||||
links.forEach(function (a) {
|
||||
if (a.getAttribute('href') === bestHref) a.classList.add('active');
|
||||
});
|
||||
}
|
||||
|
||||
/* Серверные уведомления: автоскрытие и кнопка закрытия */
|
||||
@@ -238,6 +241,34 @@
|
||||
else if (kind === 'comment-add' && typeof window.csRow === 'function') window.csRow('', 'neutral');
|
||||
});
|
||||
|
||||
/* Мобильное меню */
|
||||
function openMobileNav() {
|
||||
var n = document.getElementById('mobile-nav');
|
||||
var o = document.getElementById('mobile-nav-overlay');
|
||||
var b = document.getElementById('nav-burger');
|
||||
if (n) n.classList.add('open');
|
||||
if (o) o.hidden = false;
|
||||
if (b) b.setAttribute('aria-expanded', 'true');
|
||||
document.documentElement.classList.add('nav-open');
|
||||
}
|
||||
function closeMobileNav() {
|
||||
var n = document.getElementById('mobile-nav');
|
||||
var o = document.getElementById('mobile-nav-overlay');
|
||||
var b = document.getElementById('nav-burger');
|
||||
if (n) n.classList.remove('open');
|
||||
if (o) o.hidden = true;
|
||||
if (b) b.setAttribute('aria-expanded', 'false');
|
||||
document.documentElement.classList.remove('nav-open');
|
||||
}
|
||||
document.addEventListener('click', function (e) {
|
||||
if (e.target.closest('#nav-burger')) { openMobileNav(); return; }
|
||||
if (e.target.closest('#mobile-nav-overlay') || e.target.closest('.mobile-nav-close')) { closeMobileNav(); return; }
|
||||
if (e.target.closest('.mobile-nav a')) { closeMobileNav(); return; }
|
||||
});
|
||||
document.addEventListener('keydown', function (e) {
|
||||
if (e.key === 'Escape') closeMobileNav();
|
||||
});
|
||||
|
||||
/* Изменение полей: автоотправка форм (data-auto-submit),
|
||||
подтверждение занятия занятого варианта (select.js-variant-select) */
|
||||
document.addEventListener('change', function (e) {
|
||||
|
||||
Reference in New Issue
Block a user