1201function t_menusubmulti__highlight() {1202const url = window.location.href;1203let pathname = window.location.pathname;1204const hash = window.location.hash;12051206if (pathname.charAt(0) === '/') pathname = pathname.slice(1);1207if (pathname === '') pathname = '/';12081209let selector =1210'.t-menusub a[href="' +1211url +1212'"], ' +
'.t-menusub a[href="' + url + '/"], ' + '.t-menusub a[href="' + pathname + '"], ' + '.t-menusub a[href="/' + pathname + '"], ' + '.t-menusub a[href="' + pathname + '/"], ' + '.t-menusub a[href="/' + pathname + '/"]'; if (hash && hash !== '') { selector += ', .t-menusub a[href="' + hash + '"]'; } const shouldBeActiveElements = document.querySelectorAll(selector); shouldBeActiveElements.forEach(function (element) { const linkWrapper = element.closest('.t-menu__link-wrapper'); const hookAttr = linkWrapper ? linkWrapper.getAttribute('data-menu-submenu-hook') : null; if (hookAttr && hookAttr !== '') return; t_menusubmulti__addActiveClassWithParents(element); });}/** * Находит все якорные ссылки в блоке и передаёт их в `t_menusubmulti__catchScroll` * для отслеживания позиции скролла * @param {string|number} recid */function t_menusubmulti__checkAnchorLinks(recid) { const rec = document.getElementById('rec' + recid); if (!rec) return; let navLinks = rec.querySelectorAll('a[href*="#"].t-menusub__link-item, a[href*="#"].t-menusub__innermenu-link'); navLinks = Array.from(navLinks); navLinks = navLinks.filter(function (navLink) { return !navLink.classList.contains('tooltipstered'); }); if (navLinks.length) t_menusubmulti__catchScroll(navLinks);}/** * Подписывается на события `scroll` и `resize`, отслеживает текущую секцию * и подсвечивает соответствующую навигационную ссылку * Также обрабатывает клики по якорным ссылкам * @param {HTMLElement[]} navLinks - массив ссылок */function t_menusubmulti__catchScroll(navLinks) { const navLinksArray = Array.from(navLinks); navLinksArray.reverse(); let clickedSectionID = null; const sections = []; const sectionToNavigationLinkID = {}; navLinksArray.forEach(function (link) { const currentSection = t_menusubmulti__getSectionByHref(link); if (currentSection && currentSection.id) { sections.push(currentSection); sectionToNavigationLinkID[currentSection.id] = link; } }); t_menusubmulti__updateSectionsOffsets(sections); sections.sort(function (a, b) { const firstTopOffset = parseInt(a.getAttribute('data-offset-top'), 10) || 0; const secondTopOffset = parseInt(b.getAttribute('data-offset-top'), 10) || 0; return secondTopOffset - firstTopOffset; }); window.addEventListener( 'resize', t_throttle(function () { t_menusubmulti__updateSectionsOffsets(sections); }, 200) ); t_menusubmulti__highlightNavLinks(navLinksArray, sections, sectionToNavigationLinkID, clickedSectionID); t_menusubmulti__checkCurrentActiveClass(); const SCROLL_RECALC_DELAY = 1000; setTimeout(function () {