Toggle menu
876
3.8K
30.2K
279.1K
Catglobe Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Wiki/MediaWiki:Common.js

From Catglobe Wiki
Revision as of 09:09, 29 July 2025 by Phuadmin@voxmeter.dk (talk | contribs) (Created page with "$(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 openN...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

$(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();

});