| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- document.querySelectorAll('.accordion-header').forEach(button => {
- button.addEventListener('click', () => {
- const accordionContent = button.nextElementSibling;
- button.classList.toggle('active');
- if (button.classList.contains('active')) {
- accordionContent.style.maxHeight = accordionContent.scrollHeight + 'px';
- } else {
- accordionContent.style.maxHeight = 0;
- }
- // Close other open accordion items
- document.querySelectorAll('.accordion-header').forEach(otherButton => {
- if (otherButton !== button) {
- otherButton.classList.remove('active');
- otherButton.nextElementSibling.style.maxHeight = 0;
- }
- });
- });
- });
- // Меню-------------------------
- document.addEventListener('DOMContentLoaded', function () {
- const mobileMenuButton = document.querySelector('.header__mobile-menu');
- const menu = document.querySelector('.header__menu');
- const burger = document.querySelector('.burger');
- mobileMenuButton.addEventListener('click', function () {
- menu.classList.toggle('active');
- burger.classList.toggle('active');
- });
- });
- // Redirect
- function redirectJs(e) {
- e.preventDefault();
- let idp = this.getAttribute('data-idp');
- let label = this.getAttribute('data-label');
- let customUrl = this.getAttribute('data-url');
- let page = window.location.href;
- let redirectForm = document.createElement('form');
- redirectForm.target = '_blank';
- redirectForm.method = 'POST';
- redirectForm.action = 'redirecting.php';
- let redirectInput2 = document.createElement('input');
- redirectInput2.type = 'hidden';
- redirectInput2.name = 'idpage';
- redirectInput2.value = idp;
- redirectForm.appendChild(redirectInput2);
- let redirectInput3 = document.createElement('input');
- redirectInput3.type = 'hidden';
- redirectInput3.name = 'page';
- redirectInput3.value = page;
- redirectForm.appendChild(redirectInput3);
- let redirectInput4 = document.createElement('input');
- redirectInput4.type = 'hidden';
- redirectInput4.name = 'label';
- redirectInput4.value = label;
- redirectForm.appendChild(redirectInput4);
- // Добавляем custom_url если есть
- if (customUrl) {
- let redirectInput5 = document.createElement('input');
- redirectInput5.type = 'hidden';
- redirectInput5.name = 'custom_url';
- redirectInput5.value = customUrl;
- redirectForm.appendChild(redirectInput5);
- }
- document.body.appendChild(redirectForm);
- redirectForm.submit();
- }
- let redirectButtons = document.querySelectorAll('.redirect-js');
- for (let i = 0; i < redirectButtons.length; i++) {
- redirectButtons[i].addEventListener('click', redirectJs);
- }
- document.addEventListener('DOMContentLoaded', function () {
- var bLazy = new Blazy({
- selector: '.lazy', // Класс для ленивой загрузки
- });
- });
- // Автоматическое оборачивание всех таблиц в table-wrap
- (function() {
- function wrapTables(container) {
- if (!container || !container.querySelectorAll) {
- return;
- }
- const tables = container.querySelectorAll('table:not(.table-wrapped)');
- tables.forEach(function(table) {
- // Проверяем, не обёрнута ли уже таблица
- if (table.parentElement && table.parentElement.classList.contains('table-wrap')) {
- table.classList.add('table-wrapped');
- return;
- }
- // Создаём обёртку
- const wrapper = document.createElement('div');
- wrapper.className = 'table-wrap';
- // Вставляем обёртку перед таблицей
- table.parentNode.insertBefore(wrapper, table);
- // Перемещаем таблицу внутрь обёртки
- wrapper.appendChild(table);
- // Помечаем таблицу как обёрнутую
- table.classList.add('table-wrapped');
- });
- }
- function initTableWrapping() {
- // Оборачиваем все существующие таблицы
- wrapTables(document.body);
- // Повторно проверяем через небольшую задержку (для динамического контента)
- setTimeout(function() {
- wrapTables(document.body);
- }, 500);
- setTimeout(function() {
- wrapTables(document.body);
- }, 1500);
- }
- // Запускаем при загрузке
- if (document.readyState === 'loading') {
- document.addEventListener('DOMContentLoaded', initTableWrapping);
- } else {
- initTableWrapping();
- }
- // Наблюдаем за изменениями DOM (для динамического контента из TinyMCE)
- const observer = new MutationObserver(function(mutations) {
- let shouldProcess = false;
- mutations.forEach(function(mutation) {
- if (mutation.addedNodes.length) {
- mutation.addedNodes.forEach(function(node) {
- if (node.nodeType === 1) {
- // Если добавлена таблица или контейнер с таблицей
- if (node.tagName === 'TABLE' || (node.querySelectorAll && node.querySelectorAll('table').length > 0)) {
- shouldProcess = true;
- }
- }
- });
- }
- });
- if (shouldProcess) {
- wrapTables(document.body);
- }
- });
- // Запускаем наблюдатель
- function startObserver() {
- if (document.body) {
- observer.observe(document.body, {
- childList: true,
- subtree: true
- });
- }
- }
- if (document.body) {
- startObserver();
- } else {
- document.addEventListener('DOMContentLoaded', startObserver);
- }
- })();
- // Автоматическое добавление rel="nofollow noopener" target="_blank" ко всем внешним ссылкам
- (function() {
- const currentHost = window.location.hostname;
- function processExternalLinks(container) {
- if (!container || !container.querySelectorAll) {
- return;
- }
- // Находим все ссылки в контейнере
- const allLinks = container.querySelectorAll('a[href]');
- allLinks.forEach(function(link) {
- // Пропускаем уже обработанные ссылки
- if (link.hasAttribute('data-external-processed')) {
- return;
- }
- const href = link.getAttribute('href');
- // Пропускаем пустые, якорные ссылки, относительные пути и специальные протоколы
- if (!href || href.startsWith('#') || href.startsWith('javascript:') ||
- href.startsWith('mailto:') || href.startsWith('tel:') || href.startsWith('/')) {
- return;
- }
- try {
- // Проверяем, является ли ссылка внешней
- let isExternal = false;
- // Если ссылка начинается с http:// или https://
- if (href.startsWith('http://') || href.startsWith('https://')) {
- const linkUrl = new URL(href);
- isExternal = (linkUrl.hostname !== currentHost);
- }
- // Если это внешняя ссылка, добавляем атрибуты
- if (isExternal) {
- link.setAttribute('rel', 'nofollow noopener');
- link.setAttribute('target', '_blank');
- link.setAttribute('data-external-processed', 'true');
- }
- } catch (e) {
- // Если возникла ошибка при парсинге URL, игнорируем
- console.warn('Unable to parse URL:', href, e);
- }
- });
- }
- function initExternalLinks() {
- // Обрабатываем все ссылки на странице
- processExternalLinks(document.body);
- // Повторно обрабатываем через небольшую задержку (для динамического контента)
- setTimeout(function() {
- processExternalLinks(document.body);
- }, 500);
- setTimeout(function() {
- processExternalLinks(document.body);
- }, 1500);
- }
- // Обрабатываем существующие ссылки при загрузке
- if (document.readyState === 'loading') {
- document.addEventListener('DOMContentLoaded', initExternalLinks);
- } else {
- // DOM уже загружен
- initExternalLinks();
- }
- // Наблюдаем за изменениями DOM (для динамического контента, включая TinyMCE)
- const observer = new MutationObserver(function(mutations) {
- let shouldProcess = false;
- mutations.forEach(function(mutation) {
- if (mutation.addedNodes.length) {
- mutation.addedNodes.forEach(function(node) {
- if (node.nodeType === 1) { // Element node
- shouldProcess = true;
- }
- });
- }
- });
- if (shouldProcess) {
- processExternalLinks(document.body);
- }
- });
- // Запускаем наблюдатель после загрузки DOM
- function startObserver() {
- if (document.body) {
- observer.observe(document.body, {
- childList: true,
- subtree: true
- });
- }
- }
- if (document.body) {
- startObserver();
- } else {
- document.addEventListener('DOMContentLoaded', startObserver);
- }
- })();
|