Wiki/MediaWiki:Common.js
From Catglobe Wiki
More actions
$(function () {
const key = 'cgkb-open-nodes';
// Hàm lưu node đang mở vào localStorage
function saveOpenNodes() {
const openNodes = [];
$('.CategoryTreeNode:has(.CategoryTreeToggleOpen)').each(function () {
const title = $(this).data('ct-title');
if (title) openNodes.push(title);
});
localStorage.setItem(key, JSON.stringify(openNodes));
}
// Hàm khôi phục trạng thái cây
function restoreOpenNodes() {
const openNodes = JSON.parse(localStorage.getItem(key) || '[]');
openNodes.forEach(function (title) {
const $toggle = $('.CategoryTreeNode[data-ct-title="' + title + '"] .CategoryTreeToggleClosed');
if ($toggle.length) {
$toggle.trigger('click');
}
});
}
// Sau khi click mở nhánh, lưu trạng thái
$(document).on('click', '.CategoryTreeToggle', function () {
setTimeout(saveOpenNodes, 500); // delay để JS của CategoryTree xử lý xong
});
// Khôi phục khi trang load restoreOpenNodes();
});