MediaWiki:Common.js: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 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]; | ||
category.setAttribute('id', generateIdFromText(category.textContent || category.innerText)); | |||
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++) { | ||
menuItems[j].setAttribute('id', generateIdFromText(menuItems[j].textContent || menuItems[j].innerText)); | |||
} | } | ||
} | } | ||
| Строка 504: | Строка 499: | ||
if (selectedCategory) { | if (selectedCategory) { | ||
selectedCategory.classList.add('active'); | selectedCategory.classList.add('active'); | ||
var selectedMenu = document.querySelector('.' + selectedCategory.classList[0] + '-menu'); | |||
var selectedMenu = document.querySelector('.' + | |||
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'); | ||
prevArrow.classList.toggle('disabled', currentCategoryIndex === 0); | |||
prevArrow.style.pointerEvents = currentCategoryIndex === 0 ? 'none' : 'auto'; | |||
nextArrow.classList.toggle('disabled', currentCategoryIndex === categories.length - 1); | |||
nextArrow.style.pointerEvents = currentCategoryIndex === categories.length - 1 ? 'none' : 'auto'; | |||
} | } | ||
| Строка 556: | Строка 540: | ||
document.getElementById('prev-category').addEventListener('click', function() { | document.getElementById('prev-category').addEventListener('click', function() { | ||
if (currentCategoryIndex > 0) { | if (currentCategoryIndex > 0) { | ||
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) { | ||
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++) { | ||
(function(menuItem) { | |||
menuItem.addEventListener('click', function() { | |||
switchContent(menuItem); // Переключение контента при клике на пункт меню | |||
}); | // Убрали изменение хеша при клике | ||
}); | |||
})(menuItems[i]); | |||
} | } | ||