function t_skiplink__addButton() { var allRecords = document.getElementById('allrecords'); if (!allRecords) return; /* Прекращаем выполнение, если на странице не подключен header */ if (!allRecords.querySelector('#t-header')) { return; } var skipLinkHTML = '' + t_skiplink__dict('skiplink') + ''; document.head.insertAdjacentHTML( 'beforeend', '' ); allRecords.insertAdjacentHTML('afterbegin', skipLinkHTML); t_skiplink__addAnchor(); } function t_skiplink__addAnchor() { var menuBlocks = document.querySelectorAll('[data-menu="yes"]'); var header = document.getElementById('t-header'); var anchorDiv = '
'; if (header) { header.insertAdjacentHTML('afterend', anchorDiv); } if (menuBlocks && menuBlocks.length > 0 && !header) { var menuFirstParentRec = menuBlocks[0].parentNode; if (menuBlocks.length === 1) { menuFirstParentRec.insertAdjacentHTML('afterend', anchorDiv); } else { for (var i = 0; i < menuBlocks.length; i++) { var menuBlockParentRec = menuBlocks[i].closest('.t-rec'); if (menuBlockParentRec.nextSibling && menuBlockParentRec.nextSibling.querySelector('[data-menu="yes"]') === null) { menuBlockParentRec.insertAdjacentHTML('afterend', anchorDiv); return; } } } } } function t_skiplink__dict(msg) { var dict = []; dict['skiplink'] = { EN: 'To main content', RU: 'К основному контенту', }; dict['skiplinkAriaLabel'] = { EN: 'Skip to main content', RU: 'К основному контенту', }; var lang; var projectLang = document.querySelector('html').getAttribute('lang'); if (projectLang) { lang = projectLang.toUpperCase(); } else { lang = window.browserLang; } if (dict[msg]) { if (dict[msg][lang]) { return dict[msg][lang]; } else { return dict[msg].EN; } } return 'Text not found #' + msg; } t_skiplink__addButton(); // Element.closest() if (!Element.prototype.closest) { Element.prototype.closest = function (s) { var el = this; while (el && el.nodeType === 1) { if (Element.prototype.matches.call(el, s)) { return el; } el = el.parentElement || el.parentNode; } return null; }; }