MediaWiki:Common.js: відмінності між версіями
Admin (обговорення | внесок) Немає опису редагування |
Admin (обговорення | внесок) Немає опису редагування |
||
| (Не показано 18 проміжних версій цього користувача) | |||
| Рядок 1: | Рядок 1: | ||
// ================================================== | |||
// RANDOM ARTICLES | |||
// ================================================== | |||
$(document).ready(function() { | $(document).ready(function() { | ||
var apiUrl = mw.config.get('wgScriptPath') + '/api.php'; | var apiUrl = mw.config.get('wgScriptPath') + '/api.php'; | ||
| Рядок 6: | Рядок 9: | ||
list: 'random', | list: 'random', | ||
rnnamespace: '0', | rnnamespace: '0', | ||
rnlimit: '5', | rnlimit: '5', | ||
prop: 'extracts', | prop: 'extracts', | ||
exchars: '250', | exchars: '250', | ||
exlimit: 'max', | exlimit: 'max', | ||
explaintext: true | explaintext: true | ||
| Рядок 23: | Рядок 26: | ||
}); | }); | ||
// ================================================== | |||
// L-BOX NAVIGATION | |||
// ================================================== | |||
$(function() { | $(function() { | ||
var items = $('.l-box-item'); | var items = $('.l-box-item'); | ||
| Рядок 28: | Рядок 34: | ||
items.each(function() { | items.each(function() { | ||
var | var target = $(this).data('target'); | ||
if (target === 'top') { | |||
var | sections.push({item: $(this), target: null, offset: 0}); | ||
if ( | } else { | ||
sections.push({item: $(this), target: | var el = document.getElementById(target); | ||
if (el) { | |||
sections.push({item: $(this), target: $(el), offset: $(el).offset().top}); | |||
} | } | ||
} | } | ||
}); | |||
items.on('click', function() { | |||
var target = $(this).data('target'); | |||
var scrollTo = 0; | |||
if (target === 'top') { | |||
scrollTo = 0; | |||
} else { | |||
var el = document.getElementById(target); | |||
if (el) { | |||
scrollTo = $(el).offset().top - 100; | |||
} | |||
} | |||
$('html, body').animate({scrollTop: scrollTo}, 300); | |||
}); | }); | ||
$(window).on('scroll', function() { | $(window).on('scroll', function() { | ||
var scrollPos = $(window).scrollTop() + | var scrollPos = $(window).scrollTop() + 120; | ||
var current = null; | var current = null; | ||
sections. | for (var i = 0; i < sections.length; i++) { | ||
var checkPos = sections[i].target ? sections[i].target.offset().top : 0; | |||
current = | if (checkPos <= scrollPos) { | ||
current = sections[i].item; | |||
} | } | ||
} | } | ||
items.removeClass('active'); | items.removeClass('active'); | ||
if (current) { | if (current) { | ||
current.addClass('active'); | current.addClass('active'); | ||
} | |||
}); | |||
$(window).trigger('scroll'); | |||
}); | |||
// ================================================== | |||
// PROFILE ICONS | |||
// ================================================== | |||
$(document).ready(function() { | |||
$('.profile-icon').each(function() { | |||
var icon = $(this); | |||
var url = icon.attr('data-url'); | |||
if (url && url.trim() !== '') { | |||
icon.css('cursor', 'pointer'); | |||
icon.on('click', function() { | |||
window.open(url, '_blank'); | |||
}); | |||
} else { | |||
icon.css({ | |||
'opacity': '0.3', | |||
'filter': 'grayscale(100%)', | |||
'-webkit-filter': 'grayscale(100%)', | |||
'cursor': 'default' | |||
}); | |||
} | |||
}); | |||
}); | |||
// ================================================== | |||
// ВИПРАВЛЕННЯ ПОШУКУ - БЕЗ OVERLAY | |||
// ================================================== | |||
$(document).ready(function() { | |||
var $searchInput = $('#searchInput'); | |||
var $body = $('body'); | |||
// Невелика затримка щоб DOM повністю завантажився | |||
setTimeout(function() { | |||
// Змінюємо placeholder | |||
$searchInput.attr('placeholder', 'Пошук...'); | |||
// Прибираємо readonly | |||
$searchInput.prop('readonly', false); | |||
$searchInput.removeAttr('readonly'); | |||
// Прибираємо класи тригера | |||
$searchInput.removeClass('skin-minerva-search-trigger'); | |||
// Прибираємо всі обробники подій з input | |||
$searchInput.off(); | |||
// Блокуємо overlay при кліку/фокусі | |||
$searchInput.on('click focus', function(e) { | |||
e.stopPropagation(); | |||
e.stopImmediatePropagation(); | |||
// Прибираємо overlay класи | |||
$body.removeClass('overlay-enabled search-enabled'); | |||
// Ховаємо overlay | |||
$('.overlay, .search-overlay').remove(); | |||
// Прибираємо hash | |||
if (window.location.hash === '#/search') { | |||
history.replaceState(null, null, window.location.pathname); | |||
} | |||
// Фокус на input | |||
$(this).focus(); | |||
}); | |||
// При введенні тексту | |||
$searchInput.on('input', function(e) { | |||
$body.removeClass('overlay-enabled search-enabled'); | |||
$('.overlay, .search-overlay').remove(); | |||
}); | |||
// При Enter - перехід на сторінку пошуку | |||
$searchInput.on('keydown', function(e) { | |||
if (e.which === 13 || e.keyCode === 13) { | |||
e.preventDefault(); | |||
e.stopPropagation(); | |||
var query = $(this).val().trim(); | |||
if (query) { | |||
window.location.href = '/index.php?title=Спеціальна:Пошук&search=' + encodeURIComponent(query); | |||
} | |||
return false; | |||
} | |||
}); | |||
}, 50); | |||
// MutationObserver - блокуємо overlay класи на body | |||
var observer = new MutationObserver(function(mutations) { | |||
mutations.forEach(function(mutation) { | |||
if (mutation.attributeName === 'class') { | |||
if ($body.hasClass('overlay-enabled')) { | |||
$body.removeClass('overlay-enabled search-enabled'); | |||
$('.overlay, .search-overlay').remove(); | |||
// Прибираємо hash | |||
if (window.location.hash === '#/search') { | |||
history.replaceState(null, null, window.location.pathname); | |||
} | |||
} | |||
} | |||
}); | |||
}); | |||
observer.observe(document.body, { attributes: true }); | |||
// Блокуємо hashchange на #/search | |||
$(window).on('hashchange', function(e) { | |||
if (window.location.hash === '#/search') { | |||
e.preventDefault(); | |||
history.replaceState(null, null, window.location.pathname); | |||
$body.removeClass('overlay-enabled search-enabled'); | |||
$('.overlay, .search-overlay').remove(); | |||
} | |||
}); | |||
// Перевіряємо hash при завантаженні | |||
if (window.location.hash === '#/search') { | |||
history.replaceState(null, null, window.location.pathname); | |||
} | |||
}); | |||
// ================================================== | |||
// ДИНАМІЧНІ ПОСИЛАННЯ НА ГОЛОВНІЙ | |||
// ================================================== | |||
$(document).ready(function() { | |||
// Тільки на головній сторінці | |||
if ($('body').hasClass('page-Головна_сторінка')) { | |||
// Списки посилань для кожного блоку | |||
var block1Links = [ | |||
{ title: 'Фінал Року', url: '/index.php/Фінал_Року' } | |||
]; | |||
var block2Links = [ | |||
{ title: 'Перша статистика', url: '/index.php/Перша_статистика' }, | |||
{ title: 'Період', url: '/index.php/Період' }, | |||
{ title: 'Друга статистика', url: '/index.php/Статистика' } | |||
]; | |||
var block3Links = [ | |||
{ title: 'Mafia Closed Cup I', url: '/index.php/Mafia_Closed_Cup_I' }, | |||
{ title: 'Mafia Closed Cup I Online', url: '/index.php/Mafia_Closed_Cup_I_Online' }, | |||
{ title: 'My Closest Circle I', url: '/index.php/My_Closest_Circle_I' } | |||
]; | |||
// Функція випадкового вибору | |||
function getRandomItem(arr) { | |||
return arr[Math.floor(Math.random() * arr.length)]; | |||
} | |||
// Знаходимо блоки і замінюємо посилання | |||
var $blocks = $('.home__block-image-block p'); | |||
if ($blocks.length >= 3) { | |||
var link1 = getRandomItem(block1Links); | |||
var link2 = getRandomItem(block2Links); | |||
var link3 = getRandomItem(block3Links); | |||
$blocks.eq(0).html('<a href="' + link1.url + '">' + link1.title + '</a>'); | |||
$blocks.eq(1).html('<a href="' + link2.url + '">' + link2.title + '</a>'); | |||
$blocks.eq(2).html('<a href="' + link3.url + '">' + link3.title + '</a>'); | |||
} | |||
} | |||
}); | |||
// ================================================== | |||
// PLAYER TABS WITH LAZY LOADING | |||
// ================================================== | |||
$(function() { | |||
var $tabs = $('.player-tab'); | |||
var $contents = $('.player-tab-content'); | |||
var $lbox = $('.l-box'); | |||
var $rbox = $('.r-box'); | |||
if ($tabs.length === 0) return; | |||
// Функція перевірки мобільної версії | |||
function isMobile() { | |||
return $(window).width() <= 768; | |||
} | |||
$tabs.on('click', function() { | |||
var $tab = $(this); | |||
var tabId = $tab.data('tab'); | |||
var $content = $('#tab-' + tabId); | |||
// Перемикаємо активні класи | |||
$tabs.removeClass('active'); | |||
$tab.addClass('active'); | |||
$contents.removeClass('active'); | |||
$content.addClass('active'); | |||
// Ховаємо/показуємо l-box залежно від табу (на десктопі) | |||
if (tabId === 'games') { | |||
$lbox.fadeOut(200); | |||
} else { | |||
$lbox.fadeIn(200); | |||
} | |||
// Ховаємо/показуємо r-box на МОБІЛЬНИХ при переході на "games" | |||
if (isMobile()) { | |||
if (tabId === 'games') { | |||
$rbox.slideUp(200); | |||
} else { | |||
$rbox.slideDown(200); | |||
} | |||
} | |||
// Lazy load для ігор | |||
if (tabId === 'games' && !$content.data('loaded')) { | |||
var playerName = $content.data('player'); | |||
if (playerName) { | |||
// Показуємо loader | |||
$content.html('<div class="tab-loader">Завантаження...</div>'); | |||
$.ajax({ | |||
url: mw.config.get('wgScriptPath') + '/api.php', | |||
data: { | |||
action: 'expandtemplates', | |||
format: 'json', | |||
text: '{{#invoke:FetchData|player_games|player=' + playerName + '}}', | |||
prop: 'wikitext' | |||
}, | |||
dataType: 'json', | |||
success: function(response) { | |||
if (response.expandtemplates && response.expandtemplates.wikitext) { | |||
$.ajax({ | |||
url: mw.config.get('wgScriptPath') + '/api.php', | |||
data: { | |||
action: 'parse', | |||
format: 'json', | |||
text: response.expandtemplates.wikitext, | |||
contentmodel: 'wikitext', | |||
disablelimitreport: true | |||
}, | |||
dataType: 'json', | |||
success: function(parseResponse) { | |||
if (parseResponse.parse && parseResponse.parse.text) { | |||
$content.html(parseResponse.parse.text['*']); | |||
$content.data('loaded', true); | |||
$content.find('table.sortable').tablesorter(); | |||
} | |||
}, | |||
error: function() { | |||
$content.html('<p style="color: #ff7777; text-align: center;">Помилка завантаження. Спробуйте оновити сторінку.</p>'); | |||
} | |||
}); | |||
} | |||
}, | |||
error: function() { | |||
$content.html('<p style="color: #ff7777; text-align: center;">Помилка завантаження. Спробуйте оновити сторінку.</p>'); | |||
} | |||
}); | |||
} | |||
} | |||
}); | |||
// При зміні розміру вікна - показуємо r-box на десктопі | |||
$(window).on('resize', function() { | |||
if (!isMobile()) { | |||
$rbox.show(); | |||
} | |||
}); | |||
}); | |||
// ================================================== | |||
// МОБІЛЬНИЙ ПОШУК | |||
// ================================================== | |||
$(function() { | |||
// Тільки на мобільних | |||
if ($(window).width() > 768) return; | |||
// Створюємо overlay для пошуку | |||
var $overlay = $('<div class="mobile-search-overlay">' + | |||
'<input type="search" placeholder="Пошук..." id="mobileSearchInput">' + | |||
'<span class="mobile-search-close">×</span>' + | |||
'</div>'); | |||
$('body').append($overlay); | |||
var $input = $('#mobileSearchInput'); | |||
var $close = $overlay.find('.mobile-search-close'); | |||
var $searchIcon = $('#searchIcon'); | |||
// Клік на іконку пошуку - відкриваємо | |||
$searchIcon.on('click', function(e) { | |||
e.preventDefault(); | |||
e.stopPropagation(); | |||
$overlay.addClass('active'); | |||
$input.focus(); | |||
}); | |||
// Клік на хрестик - закриваємо | |||
$close.on('click', function() { | |||
$overlay.removeClass('active'); | |||
$input.val(''); | |||
}); | |||
// Enter - пошук | |||
$input.on('keydown', function(e) { | |||
if (e.which === 13 || e.keyCode === 13) { | |||
e.preventDefault(); | |||
var query = $(this).val().trim(); | |||
if (query) { | |||
window.location.href = '/index.php?title=Спеціальна:Пошук&search=' + encodeURIComponent(query); | |||
} | |||
} | |||
}); | |||
// Escape - закриваємо | |||
$(document).on('keydown', function(e) { | |||
if (e.which === 27 && $overlay.hasClass('active')) { | |||
$overlay.removeClass('active'); | |||
$input.val(''); | |||
} | |||
}); | |||
// Клік поза overlay - закриваємо | |||
$overlay.on('click', function(e) { | |||
if (e.target === this) { | |||
$overlay.removeClass('active'); | |||
$input.val(''); | |||
} | |||
}); | |||
}); | |||
/* ==================================================== */ | |||
/* МОБІЛЬНИЙ ПОШУК - ІКОНКА + OVERLAY */ | |||
/* ==================================================== */ | |||
$(function() { | |||
// Тільки для мобільних | |||
if (window.innerWidth > 768) return; | |||
// Створюємо кнопку пошуку | |||
var $searchBtn = $('<div class="mobile-search-btn">' + | |||
'<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#fff" stroke-width="2">' + | |||
'<circle cx="11" cy="11" r="8"/>' + | |||
'<path d="m21 21-4.35-4.35"/>' + | |||
'</svg>' + | |||
'</div>'); | |||
// Створюємо overlay | |||
var $overlay = $('<div class="mobile-search-overlay">' + | |||
'<input type="text" placeholder="Пошук..." autocomplete="off" autocapitalize="off">' + | |||
'<div class="mobile-search-close">×</div>' + | |||
'</div>'); | |||
// Додаємо в DOM | |||
$('.minerva-header .branding-box').after($searchBtn); | |||
$('body').append($overlay); | |||
var $input = $overlay.find('input'); | |||
var $close = $overlay.find('.mobile-search-close'); | |||
// Відкриття пошуку | |||
$searchBtn.on('click', function(e) { | |||
e.preventDefault(); | |||
e.stopPropagation(); | |||
$overlay.addClass('active'); | |||
setTimeout(function() { | |||
$input.focus(); | |||
}, 100); | |||
}); | |||
// Закриття пошуку | |||
$close.on('click', function() { | |||
$overlay.removeClass('active'); | |||
$input.val(''); | |||
}); | |||
// Enter - пошук | |||
$input.on('keydown', function(e) { | |||
if (e.keyCode === 13) { // Enter | |||
var query = $input.val().trim(); | |||
if (query) { | |||
window.location.href = '/index.php?title=Спеціальна:Пошук&search=' + encodeURIComponent(query); | |||
} | |||
} | |||
if (e.keyCode === 27) { // Escape | |||
$overlay.removeClass('active'); | |||
$input.val(''); | |||
} | |||
}); | |||
// Клік поза overlay - закриття | |||
$overlay.on('click', function(e) { | |||
if (e.target === this) { | |||
$overlay.removeClass('active'); | |||
$input.val(''); | |||
} | } | ||
}); | }); | ||
}); | }); | ||
Поточна версія на 00:35, 29 грудня 2025
// ==================================================
// RANDOM ARTICLES
// ==================================================
$(document).ready(function() {
var apiUrl = mw.config.get('wgScriptPath') + '/api.php';
$.getJSON(apiUrl, {
action: 'query',
format: 'json',
list: 'random',
rnnamespace: '0',
rnlimit: '5',
prop: 'extracts',
exchars: '250',
exlimit: 'max',
explaintext: true
}, function(data) {
var html = '';
$.each(data.query.random, function(i, article) {
html += '<div class="random-article-preview">';
html += '<h2><a href="/wiki/' + encodeURIComponent(article.title) + '">' + article.title + '</a></h2>';
html += '<p>' + article.extract + '</p>';
html += '</div>';
});
$('#random-articles-container').html(html);
});
});
// ==================================================
// L-BOX NAVIGATION
// ==================================================
$(function() {
var items = $('.l-box-item');
var sections = [];
items.each(function() {
var target = $(this).data('target');
if (target === 'top') {
sections.push({item: $(this), target: null, offset: 0});
} else {
var el = document.getElementById(target);
if (el) {
sections.push({item: $(this), target: $(el), offset: $(el).offset().top});
}
}
});
items.on('click', function() {
var target = $(this).data('target');
var scrollTo = 0;
if (target === 'top') {
scrollTo = 0;
} else {
var el = document.getElementById(target);
if (el) {
scrollTo = $(el).offset().top - 100;
}
}
$('html, body').animate({scrollTop: scrollTo}, 300);
});
$(window).on('scroll', function() {
var scrollPos = $(window).scrollTop() + 120;
var current = null;
for (var i = 0; i < sections.length; i++) {
var checkPos = sections[i].target ? sections[i].target.offset().top : 0;
if (checkPos <= scrollPos) {
current = sections[i].item;
}
}
items.removeClass('active');
if (current) {
current.addClass('active');
}
});
$(window).trigger('scroll');
});
// ==================================================
// PROFILE ICONS
// ==================================================
$(document).ready(function() {
$('.profile-icon').each(function() {
var icon = $(this);
var url = icon.attr('data-url');
if (url && url.trim() !== '') {
icon.css('cursor', 'pointer');
icon.on('click', function() {
window.open(url, '_blank');
});
} else {
icon.css({
'opacity': '0.3',
'filter': 'grayscale(100%)',
'-webkit-filter': 'grayscale(100%)',
'cursor': 'default'
});
}
});
});
// ==================================================
// ВИПРАВЛЕННЯ ПОШУКУ - БЕЗ OVERLAY
// ==================================================
$(document).ready(function() {
var $searchInput = $('#searchInput');
var $body = $('body');
// Невелика затримка щоб DOM повністю завантажився
setTimeout(function() {
// Змінюємо placeholder
$searchInput.attr('placeholder', 'Пошук...');
// Прибираємо readonly
$searchInput.prop('readonly', false);
$searchInput.removeAttr('readonly');
// Прибираємо класи тригера
$searchInput.removeClass('skin-minerva-search-trigger');
// Прибираємо всі обробники подій з input
$searchInput.off();
// Блокуємо overlay при кліку/фокусі
$searchInput.on('click focus', function(e) {
e.stopPropagation();
e.stopImmediatePropagation();
// Прибираємо overlay класи
$body.removeClass('overlay-enabled search-enabled');
// Ховаємо overlay
$('.overlay, .search-overlay').remove();
// Прибираємо hash
if (window.location.hash === '#/search') {
history.replaceState(null, null, window.location.pathname);
}
// Фокус на input
$(this).focus();
});
// При введенні тексту
$searchInput.on('input', function(e) {
$body.removeClass('overlay-enabled search-enabled');
$('.overlay, .search-overlay').remove();
});
// При Enter - перехід на сторінку пошуку
$searchInput.on('keydown', function(e) {
if (e.which === 13 || e.keyCode === 13) {
e.preventDefault();
e.stopPropagation();
var query = $(this).val().trim();
if (query) {
window.location.href = '/index.php?title=Спеціальна:Пошук&search=' + encodeURIComponent(query);
}
return false;
}
});
}, 50);
// MutationObserver - блокуємо overlay класи на body
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.attributeName === 'class') {
if ($body.hasClass('overlay-enabled')) {
$body.removeClass('overlay-enabled search-enabled');
$('.overlay, .search-overlay').remove();
// Прибираємо hash
if (window.location.hash === '#/search') {
history.replaceState(null, null, window.location.pathname);
}
}
}
});
});
observer.observe(document.body, { attributes: true });
// Блокуємо hashchange на #/search
$(window).on('hashchange', function(e) {
if (window.location.hash === '#/search') {
e.preventDefault();
history.replaceState(null, null, window.location.pathname);
$body.removeClass('overlay-enabled search-enabled');
$('.overlay, .search-overlay').remove();
}
});
// Перевіряємо hash при завантаженні
if (window.location.hash === '#/search') {
history.replaceState(null, null, window.location.pathname);
}
});
// ==================================================
// ДИНАМІЧНІ ПОСИЛАННЯ НА ГОЛОВНІЙ
// ==================================================
$(document).ready(function() {
// Тільки на головній сторінці
if ($('body').hasClass('page-Головна_сторінка')) {
// Списки посилань для кожного блоку
var block1Links = [
{ title: 'Фінал Року', url: '/index.php/Фінал_Року' }
];
var block2Links = [
{ title: 'Перша статистика', url: '/index.php/Перша_статистика' },
{ title: 'Період', url: '/index.php/Період' },
{ title: 'Друга статистика', url: '/index.php/Статистика' }
];
var block3Links = [
{ title: 'Mafia Closed Cup I', url: '/index.php/Mafia_Closed_Cup_I' },
{ title: 'Mafia Closed Cup I Online', url: '/index.php/Mafia_Closed_Cup_I_Online' },
{ title: 'My Closest Circle I', url: '/index.php/My_Closest_Circle_I' }
];
// Функція випадкового вибору
function getRandomItem(arr) {
return arr[Math.floor(Math.random() * arr.length)];
}
// Знаходимо блоки і замінюємо посилання
var $blocks = $('.home__block-image-block p');
if ($blocks.length >= 3) {
var link1 = getRandomItem(block1Links);
var link2 = getRandomItem(block2Links);
var link3 = getRandomItem(block3Links);
$blocks.eq(0).html('<a href="' + link1.url + '">' + link1.title + '</a>');
$blocks.eq(1).html('<a href="' + link2.url + '">' + link2.title + '</a>');
$blocks.eq(2).html('<a href="' + link3.url + '">' + link3.title + '</a>');
}
}
});
// ==================================================
// PLAYER TABS WITH LAZY LOADING
// ==================================================
$(function() {
var $tabs = $('.player-tab');
var $contents = $('.player-tab-content');
var $lbox = $('.l-box');
var $rbox = $('.r-box');
if ($tabs.length === 0) return;
// Функція перевірки мобільної версії
function isMobile() {
return $(window).width() <= 768;
}
$tabs.on('click', function() {
var $tab = $(this);
var tabId = $tab.data('tab');
var $content = $('#tab-' + tabId);
// Перемикаємо активні класи
$tabs.removeClass('active');
$tab.addClass('active');
$contents.removeClass('active');
$content.addClass('active');
// Ховаємо/показуємо l-box залежно від табу (на десктопі)
if (tabId === 'games') {
$lbox.fadeOut(200);
} else {
$lbox.fadeIn(200);
}
// Ховаємо/показуємо r-box на МОБІЛЬНИХ при переході на "games"
if (isMobile()) {
if (tabId === 'games') {
$rbox.slideUp(200);
} else {
$rbox.slideDown(200);
}
}
// Lazy load для ігор
if (tabId === 'games' && !$content.data('loaded')) {
var playerName = $content.data('player');
if (playerName) {
// Показуємо loader
$content.html('<div class="tab-loader">Завантаження...</div>');
$.ajax({
url: mw.config.get('wgScriptPath') + '/api.php',
data: {
action: 'expandtemplates',
format: 'json',
text: '{{#invoke:FetchData|player_games|player=' + playerName + '}}',
prop: 'wikitext'
},
dataType: 'json',
success: function(response) {
if (response.expandtemplates && response.expandtemplates.wikitext) {
$.ajax({
url: mw.config.get('wgScriptPath') + '/api.php',
data: {
action: 'parse',
format: 'json',
text: response.expandtemplates.wikitext,
contentmodel: 'wikitext',
disablelimitreport: true
},
dataType: 'json',
success: function(parseResponse) {
if (parseResponse.parse && parseResponse.parse.text) {
$content.html(parseResponse.parse.text['*']);
$content.data('loaded', true);
$content.find('table.sortable').tablesorter();
}
},
error: function() {
$content.html('<p style="color: #ff7777; text-align: center;">Помилка завантаження. Спробуйте оновити сторінку.</p>');
}
});
}
},
error: function() {
$content.html('<p style="color: #ff7777; text-align: center;">Помилка завантаження. Спробуйте оновити сторінку.</p>');
}
});
}
}
});
// При зміні розміру вікна - показуємо r-box на десктопі
$(window).on('resize', function() {
if (!isMobile()) {
$rbox.show();
}
});
});
// ==================================================
// МОБІЛЬНИЙ ПОШУК
// ==================================================
$(function() {
// Тільки на мобільних
if ($(window).width() > 768) return;
// Створюємо overlay для пошуку
var $overlay = $('<div class="mobile-search-overlay">' +
'<input type="search" placeholder="Пошук..." id="mobileSearchInput">' +
'<span class="mobile-search-close">×</span>' +
'</div>');
$('body').append($overlay);
var $input = $('#mobileSearchInput');
var $close = $overlay.find('.mobile-search-close');
var $searchIcon = $('#searchIcon');
// Клік на іконку пошуку - відкриваємо
$searchIcon.on('click', function(e) {
e.preventDefault();
e.stopPropagation();
$overlay.addClass('active');
$input.focus();
});
// Клік на хрестик - закриваємо
$close.on('click', function() {
$overlay.removeClass('active');
$input.val('');
});
// Enter - пошук
$input.on('keydown', function(e) {
if (e.which === 13 || e.keyCode === 13) {
e.preventDefault();
var query = $(this).val().trim();
if (query) {
window.location.href = '/index.php?title=Спеціальна:Пошук&search=' + encodeURIComponent(query);
}
}
});
// Escape - закриваємо
$(document).on('keydown', function(e) {
if (e.which === 27 && $overlay.hasClass('active')) {
$overlay.removeClass('active');
$input.val('');
}
});
// Клік поза overlay - закриваємо
$overlay.on('click', function(e) {
if (e.target === this) {
$overlay.removeClass('active');
$input.val('');
}
});
});
/* ==================================================== */
/* МОБІЛЬНИЙ ПОШУК - ІКОНКА + OVERLAY */
/* ==================================================== */
$(function() {
// Тільки для мобільних
if (window.innerWidth > 768) return;
// Створюємо кнопку пошуку
var $searchBtn = $('<div class="mobile-search-btn">' +
'<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#fff" stroke-width="2">' +
'<circle cx="11" cy="11" r="8"/>' +
'<path d="m21 21-4.35-4.35"/>' +
'</svg>' +
'</div>');
// Створюємо overlay
var $overlay = $('<div class="mobile-search-overlay">' +
'<input type="text" placeholder="Пошук..." autocomplete="off" autocapitalize="off">' +
'<div class="mobile-search-close">×</div>' +
'</div>');
// Додаємо в DOM
$('.minerva-header .branding-box').after($searchBtn);
$('body').append($overlay);
var $input = $overlay.find('input');
var $close = $overlay.find('.mobile-search-close');
// Відкриття пошуку
$searchBtn.on('click', function(e) {
e.preventDefault();
e.stopPropagation();
$overlay.addClass('active');
setTimeout(function() {
$input.focus();
}, 100);
});
// Закриття пошуку
$close.on('click', function() {
$overlay.removeClass('active');
$input.val('');
});
// Enter - пошук
$input.on('keydown', function(e) {
if (e.keyCode === 13) { // Enter
var query = $input.val().trim();
if (query) {
window.location.href = '/index.php?title=Спеціальна:Пошук&search=' + encodeURIComponent(query);
}
}
if (e.keyCode === 27) { // Escape
$overlay.removeClass('active');
$input.val('');
}
});
// Клік поза overlay - закриття
$overlay.on('click', function(e) {
if (e.target === this) {
$overlay.removeClass('active');
$input.val('');
}
});
});