Нет описания правки |
Нет описания правки |
||
Строка 73: | Строка 73: | ||
} | } | ||
// | // Универсальная система подсказок для таблиц законов | ||
(function() { | |||
'use strict'; | |||
if (window.lawTooltipsLoaded) return; | |||
window.lawTooltipsLoaded = true; | |||
// Функция загрузки Tippy.js | |||
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 | |||
// Ищем все таблицы с детальными описаниями | |||
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; | |||
} | |||
// Функция создания HTML для подсказки | |||
function createTooltipContent(lawCode, lawData) { | |||
var data = lawData[lawCode]; | |||
if (!data) return null; | |||
var html = '<div class="law-tooltip">'; | |||
var | 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) { // Ограничиваем до 5 примеров | |||
html += '<li>' + example + '</li>'; | |||
}); | }); | ||
html += '</ul>'; | |||
html += '</div>'; | |||
} | } | ||
html += '</div>'; | |||
return html; | |||
} | |||
// Инициализация подсказок | |||
function initTooltips() { | |||
var lawData = extractLawDataFromPage(); | |||
// Ищем все ссылки на статьи (и в основной таблице, и в детальных) | |||
var lawLinks = document.querySelectorAll('a[href*="#"]'); | |||
var | |||
lawLinks.forEach(function(link) { | |||
var href = link.getAttribute('href'); | |||
var match = href.match(/#(\d{3})/); | |||
var | |||
var | |||
if ( | if (match) { | ||
var lawCode = match[1]; | |||
var tooltipContent = createTooltipContent(lawCode, lawData); | |||
if (tooltipContent) { | |||
tippy(link, { | |||
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(); | |||
} | |||
}); | |||
} | |||
}); | |||
} | |||
} | } | ||
}); | }); | ||
console.log('Загружено подсказок для статей:', Object.keys(lawData).length); | |||
} | } | ||
function | // Запуск после загрузки страницы | ||
function init() { | |||
loadTippy(function() { | |||
// Ждем немного, чтобы все элементы MediaWiki загрузились | |||
setTimeout(initTooltips, 500); | |||
}); | }); | ||
} | } | ||
if (document.readyState === 'loading') { | |||
if (document. | document.addEventListener('DOMContentLoaded', init); | ||
} else { | |||
init(); | |||
} | } | ||
})(); | |||
}); | }); |
Версия от 10:52, 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;
// Функция загрузки Tippy.js
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;
}
// Функция создания HTML для подсказки
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) { // Ограничиваем до 5 примеров
html += '<li>' + example + '</li>';
});
html += '</ul>';
html += '</div>';
}
html += '</div>';
return html;
}
// Инициализация подсказок
function initTooltips() {
var lawData = extractLawDataFromPage();
// Ищем все ссылки на статьи (и в основной таблице, и в детальных)
var lawLinks = document.querySelectorAll('a[href*="#"]');
lawLinks.forEach(function(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) {
tippy(link, {
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();
}
});
}
});
}
}
});
console.log('Загружено подсказок для статей:', Object.keys(lawData).length);
}
// Запуск после загрузки страницы
function init() {
loadTippy(function() {
// Ждем немного, чтобы все элементы MediaWiki загрузились
setTimeout(initTooltips, 500);
});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
})();
});