5737
редагувань
Admin (обговорення | внесок) Немає опису редагування |
Admin (обговорення | внесок) Немає опису редагування |
||
| Рядок 244: | Рядок 244: | ||
} | } | ||
} | } | ||
}); | |||
// ================================================== | |||
// PLAYER TABS WITH LAZY LOADING | |||
// ================================================== | |||
$(function() { | |||
var $tabs = $('.player-tab'); | |||
var $contents = $('.player-tab-content'); | |||
if ($tabs.length === 0) return; | |||
$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'); | |||
// Lazy load для ігор | |||
if (tabId === 'games' && !$content.data('loaded')) { | |||
var playerName = $content.data('player'); | |||
if (playerName) { | |||
// Завантажуємо через API | |||
var apiUrl = mw.util.getUrl('Спеціальна:ExpandTemplates'); | |||
$.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) { | |||
// Парсимо wikitext в HTML | |||
$.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>'); | |||
} | |||
}); | |||
} | |||
} | |||
}); | |||
}); | }); | ||