Нет описания правки |
Нет описания правки |
||
Строка 73: | Строка 73: | ||
} | } | ||
(function() { | |||
(function() { | 'use strict'; | ||
if (window.lawTooltipsLoaded) return; | |||
window.lawTooltipsLoaded = true; | |||
function loadTippy(callback) { | |||
if (window.tippy) { | |||
callback(); | |||
return; | |||
} | |||
var popperScript = document.createElement('script'); | |||
popperScript.src = 'https://unpkg.com/@popperjs/core@2/dist/umd/popper.min.js'; | |||
popperScript.onload = function() { | |||
var tippyScript = document.createElement('script'); | |||
tippyScript.src = 'https://unpkg.com/tippy.js@6/dist/tippy-bundle.umd.min.js'; | |||
tippyScript.onload = callback; | |||
document.head.appendChild(tippyScript); | |||
}; | |||
document.head.appendChild(popperScript); | |||
var tippyCSS = document.createElement('link'); | |||
tippyCSS.rel = 'stylesheet'; | |||
tippyCSS.href = 'https://unpkg.com/tippy.js@6/dist/tippy.css'; | |||
document.head.appendChild(tippyCSS); | |||
} | |||
function extractLawDataFromPage() { | |||
var lawData = {}; | |||
var detailTables = document.querySelectorAll('.mw-collapsible-content table'); | |||
detailTables.forEach(function(table) { | |||
var rows = table.querySelectorAll('tr'); | |||
rows.forEach(function(row) { | |||
var cells = row.querySelectorAll('td'); | |||
if (cells.length >= 3) { | |||
var crimeCell = cells[0]; | |||
var descriptionCell = cells[1]; | |||
var exampleCell = cells[2]; | |||
var anchor = crimeCell.querySelector('[id]'); | |||
if (anchor) { | |||
var lawCode = anchor.id; | |||
var titleElement = crimeCell.querySelector('b'); | |||
if (titleElement && lawCode.match(/^\d{3}$/)) { | |||
var titleText = titleElement.textContent.trim(); | |||
var titleParts = titleText.split('\n\n'); | |||
var lawTitle = titleParts.length > 1 ? titleParts[1] : titleText; | |||
var description = descriptionCell.textContent.trim(); | |||
var examples = []; | |||
var exampleItems = exampleCell.querySelectorAll('li'); | |||
exampleItems.forEach(function(item) { | |||
var text = item.textContent.trim(); | |||
if (text) { | |||
examples.push(text); | |||
} | |||
}); | |||
lawData[lawCode] = { | |||
title: lawTitle, | |||
description: description, | |||
examples: examples | |||
}; | |||
} | |||
} | |||
} | |||
}); | |||
}); | |||
return lawData; | |||
} | |||
function createTooltipContent(lawCode, lawData) { | |||
var data = lawData[lawCode]; | |||
if (!data) return null; | |||
var html = '<div class="law-tooltip">'; | |||
html += '<h4 class="law-tooltip-title">' + lawCode + ' - ' + data.title + '</h4>'; | |||
html += '<p class="law-tooltip-description">' + data.description + '</p>'; | |||
if (data.examples && data.examples.length > 0) { | |||
html += '<div class="law-tooltip-examples">'; | |||
html += '<strong>Примеры:</strong>'; | |||
html += '<ul>'; | |||
data.examples.slice(0, 5).forEach(function(example) { | |||
html += '<li>' + example + '</li>'; | |||
}); | |||
html += '</ul>'; | |||
html += '</div>'; | |||
} | |||
html += '</div>'; | |||
return html; | |||
} | |||
function initTooltips() { | |||
var lawData = extractLawDataFromPage(); | |||
var tableCells = document.querySelectorAll('.law-tooltips td, .law-tooltips th'); | |||
tableCells.forEach(function(cell) { | |||
var link = cell.querySelector('a[href*="#"]'); | |||
if (link) { | |||
var href = link.getAttribute('href'); | |||
var match = href.match(/#(\d{3})/); | |||
if (match) { | |||
var lawCode = match[1]; | |||
var tooltipContent = createTooltipContent(lawCode, lawData); | |||
if (tooltipContent) { | |||
cell.classList.add('law-cell-with-tooltip'); | |||
tippy(cell, { | |||
content: tooltipContent, | |||
allowHTML: true, | |||
interactive: true, | |||
placement: 'auto', | |||
maxWidth: 450, | |||
theme: 'law-theme', | |||
arrow: true, | |||
duration: [300, 200], | |||
delay: [400, 100], | |||
popperOptions: { | |||
modifiers: [ | |||
{ | |||
name: 'preventOverflow', | |||
options: { | |||
padding: 10 | |||
} | |||
}, | |||
{ | |||
name: 'flip', | |||
options: { | |||
fallbackPlacements: ['top', 'bottom', 'right', 'left'] | |||
} | |||
} | |||
] | |||
}, | |||
onShow: function(instance) { | |||
document.querySelectorAll('[data-tippy-root]').forEach(function(tooltip) { | |||
if (tooltip._tippy && tooltip._tippy !== instance) { | |||
tooltip._tippy.hide(); | |||
} | |||
}); | |||
} | |||
}); | |||
} | |||
} | |||
} | |||
}); | |||
} | |||
function init() { | |||
loadTippy(function() { | |||
setTimeout(initTooltips, 500); | |||
}); | |||
} | |||
if (document.readyState === 'loading') { | |||
document.addEventListener('DOMContentLoaded', init); | |||
} else { | |||
init(); | |||
} | |||
})(); | })(); | ||
}); | }); |
Версия от 10:57, 27 сентября 2025
$(document).ready(function() {
// Инициализация боковой панели
$('.боковая-панель-кнопка').on('click', function() {
var targetId = $(this).data('target');
// Удаляем активный класс у всех кнопок
$('.боковая-панель-кнопка').removeClass('active');
// Добавляем активный класс текущей кнопке
$(this).addClass('active');
// Скрываем все разделы
$('.боковая-панель-раздел').removeClass('default');
// Показываем выбранный раздел
$('#' + targetId).addClass('default');
});
// Активируем первую кнопку по умолчанию
$('.боковая-панель-кнопка:first').click();
// Подключаем Tippy.js через CDN динамически
if (!window.tippy) {
var tippyScript = document.createElement('script');
tippyScript.src = "https://unpkg.com/@popperjs/core@2/dist/umd/popper.min.js";
tippyScript.onload = function() {
var tippyCoreScript = document.createElement('script');
tippyCoreScript.src = "https://unpkg.com/tippy.js@6/dist/tippy-bundle.umd.min.js";
tippyCoreScript.onload = initTippy;
document.head.appendChild(tippyCoreScript);
};
document.head.appendChild(tippyScript);
// Подключаем CSS
var tippyCSS = document.createElement('link');
tippyCSS.rel = "stylesheet";
tippyCSS.href = "https://unpkg.com/tippy.js@6/dist/tippy.css";
document.head.appendChild(tippyCSS);
} else {
initTippy();
}
// Инициализация Tippy после загрузки скриптов
function initTippy() {
$('.допуск-контейнер').each(function() {
var content = $(this).find('.допуск-подсказка').html(); // берем содержимое подсказки
tippy(this, {
content: content,
allowHTML: true,
interactive: true,
placement: 'auto', // автоматический выбор позиции
maxWidth: '500px',
minHeight: 'auto',
theme: 'dark', // темная тема
arrow: true, // без стрелки
duration: [200, 200], // плавное появление/исчезание
popperOptions: {
modifiers: [
{
name: 'preventOverflow',
options: {
padding: 8 // отступ от краев экрана
}
},
{
name: 'flip',
options: {
fallbackPlacements: ['top', 'bottom', 'right', 'left']
}
}
]
}
});
});
}
(function() {
'use strict';
if (window.lawTooltipsLoaded) return;
window.lawTooltipsLoaded = true;
function loadTippy(callback) {
if (window.tippy) {
callback();
return;
}
var popperScript = document.createElement('script');
popperScript.src = 'https://unpkg.com/@popperjs/core@2/dist/umd/popper.min.js';
popperScript.onload = function() {
var tippyScript = document.createElement('script');
tippyScript.src = 'https://unpkg.com/tippy.js@6/dist/tippy-bundle.umd.min.js';
tippyScript.onload = callback;
document.head.appendChild(tippyScript);
};
document.head.appendChild(popperScript);
var tippyCSS = document.createElement('link');
tippyCSS.rel = 'stylesheet';
tippyCSS.href = 'https://unpkg.com/tippy.js@6/dist/tippy.css';
document.head.appendChild(tippyCSS);
}
function extractLawDataFromPage() {
var lawData = {};
var detailTables = document.querySelectorAll('.mw-collapsible-content table');
detailTables.forEach(function(table) {
var rows = table.querySelectorAll('tr');
rows.forEach(function(row) {
var cells = row.querySelectorAll('td');
if (cells.length >= 3) {
var crimeCell = cells[0];
var descriptionCell = cells[1];
var exampleCell = cells[2];
var anchor = crimeCell.querySelector('[id]');
if (anchor) {
var lawCode = anchor.id;
var titleElement = crimeCell.querySelector('b');
if (titleElement && lawCode.match(/^\d{3}$/)) {
var titleText = titleElement.textContent.trim();
var titleParts = titleText.split('\n\n');
var lawTitle = titleParts.length > 1 ? titleParts[1] : titleText;
var description = descriptionCell.textContent.trim();
var examples = [];
var exampleItems = exampleCell.querySelectorAll('li');
exampleItems.forEach(function(item) {
var text = item.textContent.trim();
if (text) {
examples.push(text);
}
});
lawData[lawCode] = {
title: lawTitle,
description: description,
examples: examples
};
}
}
}
});
});
return lawData;
}
function createTooltipContent(lawCode, lawData) {
var data = lawData[lawCode];
if (!data) return null;
var html = '<div class="law-tooltip">';
html += '<h4 class="law-tooltip-title">' + lawCode + ' - ' + data.title + '</h4>';
html += '<p class="law-tooltip-description">' + data.description + '</p>';
if (data.examples && data.examples.length > 0) {
html += '<div class="law-tooltip-examples">';
html += '<strong>Примеры:</strong>';
html += '<ul>';
data.examples.slice(0, 5).forEach(function(example) {
html += '<li>' + example + '</li>';
});
html += '</ul>';
html += '</div>';
}
html += '</div>';
return html;
}
function initTooltips() {
var lawData = extractLawDataFromPage();
var tableCells = document.querySelectorAll('.law-tooltips td, .law-tooltips th');
tableCells.forEach(function(cell) {
var link = cell.querySelector('a[href*="#"]');
if (link) {
var href = link.getAttribute('href');
var match = href.match(/#(\d{3})/);
if (match) {
var lawCode = match[1];
var tooltipContent = createTooltipContent(lawCode, lawData);
if (tooltipContent) {
cell.classList.add('law-cell-with-tooltip');
tippy(cell, {
content: tooltipContent,
allowHTML: true,
interactive: true,
placement: 'auto',
maxWidth: 450,
theme: 'law-theme',
arrow: true,
duration: [300, 200],
delay: [400, 100],
popperOptions: {
modifiers: [
{
name: 'preventOverflow',
options: {
padding: 10
}
},
{
name: 'flip',
options: {
fallbackPlacements: ['top', 'bottom', 'right', 'left']
}
}
]
},
onShow: function(instance) {
document.querySelectorAll('[data-tippy-root]').forEach(function(tooltip) {
if (tooltip._tippy && tooltip._tippy !== instance) {
tooltip._tippy.hide();
}
});
}
});
}
}
}
});
}
function init() {
loadTippy(function() {
setTimeout(initTooltips, 500);
});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
})();
});