MediaWiki:Common.js: различия между версиями

Нет описания правки
мНет описания правки
Строка 471: Строка 471:
for (var i = 0; i < categories.length; i++) {
for (var i = 0; i < categories.length; i++) {
var category = categories[i];
var category = categories[i];
var categoryText = category.textContent || category.innerText;
category.setAttribute('id', generateIdFromText(category.textContent || category.innerText));
var categoryId = generateIdFromText(categoryText);
category.setAttribute('id', categoryId);


var menu = menus[i];
var menu = menus[i];
var menuItems = menu.querySelectorAll('div');
var menuItems = menu.querySelectorAll('div');
for (var j = 0; j < menuItems.length; j++) {
for (var j = 0; j < menuItems.length; j++) {
var menuItem = menuItems[j];
menuItems[j].setAttribute('id', generateIdFromText(menuItems[j].textContent || menuItems[j].innerText));
var menuItemText = menuItem.textContent || menuItem.innerText;
var menuItemId = generateIdFromText(menuItemText);
menuItem.setAttribute('id', menuItemId);
}
}
}
}
Строка 504: Строка 499:
if (selectedCategory) {
if (selectedCategory) {
selectedCategory.classList.add('active');
selectedCategory.classList.add('active');
var categoryClass = selectedCategory.classList[0];
var selectedMenu = document.querySelector('.' + selectedCategory.classList[0] + '-menu');
var selectedMenu = document.querySelector('.' + categoryClass + '-menu');
if (selectedMenu) {
if (selectedMenu) {
selectedMenu.classList.add('active');
selectedMenu.classList.add('active');
Строка 536: Строка 530:
var nextArrow = document.getElementById('next-category');
var nextArrow = document.getElementById('next-category');


if (currentCategoryIndex === 0) {
prevArrow.classList.toggle('disabled', currentCategoryIndex === 0);
prevArrow.classList.add('disabled');
prevArrow.style.pointerEvents = currentCategoryIndex === 0 ? 'none' : 'auto';
prevArrow.style.pointerEvents = 'none'; // Отключение кликов
} else {
prevArrow.classList.remove('disabled');
prevArrow.style.pointerEvents = 'auto'; // Включение кликов
}


if (currentCategoryIndex === categories.length - 1) {
nextArrow.classList.toggle('disabled', currentCategoryIndex === categories.length - 1);
nextArrow.classList.add('disabled');
nextArrow.style.pointerEvents = currentCategoryIndex === categories.length - 1 ? 'none' : 'auto';
nextArrow.style.pointerEvents = 'none'; // Отключение кликов
} else {
nextArrow.classList.remove('disabled');
nextArrow.style.pointerEvents = 'auto'; // Включение кликов
}
}
}


Строка 556: Строка 540:
document.getElementById('prev-category').addEventListener('click', function() {
document.getElementById('prev-category').addEventListener('click', function() {
if (currentCategoryIndex > 0) {
if (currentCategoryIndex > 0) {
currentCategoryIndex = currentCategoryIndex - 1;
switchCategory(--currentCategoryIndex); // Переключение на новую категорию
switchCategory(currentCategoryIndex); // Переключение на новую категорию
}
}
});
});
Строка 563: Строка 546:
document.getElementById('next-category').addEventListener('click', function() {
document.getElementById('next-category').addEventListener('click', function() {
if (currentCategoryIndex < categories.length - 1) {
if (currentCategoryIndex < categories.length - 1) {
currentCategoryIndex = currentCategoryIndex + 1;
switchCategory(++currentCategoryIndex); // Переключение на новую категорию
switchCategory(currentCategoryIndex); // Переключение на новую категорию
}
}
});
});
Строка 577: Строка 559:
for (var i = 0; i < menuItems.length; i++) {
for (var i = 0; i < menuItems.length; i++) {
if (menuItems[i].id === decodedAnchor) { // Сравниваем с декодированным значением
if (menuItems[i].id === decodedAnchor) { // Сравниваем с декодированным значением
// Найти индекс категории, к которой принадлежит пункт меню
var categoryIndex = Array.prototype.indexOf.call(categories, menuItems[i].closest('.navigation__menu-item').previousElementSibling);
var categoryIndex = Array.prototype.indexOf.call(categories, menuItems[i].closest('.navigation__menu-item').previousElementSibling);
if (categoryIndex !== -1) {
if (categoryIndex !== -1) {
Строка 618: Строка 599:
// Клик по элементам меню
// Клик по элементам меню
for (var i = 0; i < menuItems.length; i++) {
for (var i = 0; i < menuItems.length; i++) {
menuItems[i].addEventListener('click', function() {
(function(menuItem) {
switchContent(this); // Переключение контента при клике на пункт меню
menuItem.addEventListener('click', function() {
window.location.hash = this.id; // Изменение хеша при клике
switchContent(menuItem); // Переключение контента при клике на пункт меню
});
// Убрали изменение хеша при клике
});
})(menuItems[i]);
}
}