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: Difference between revisions

From Catglobe Wiki
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..."
 
Blanked the page
 
Line 1: Line 1:
$(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();
});

Latest revision as of 09:11, 29 July 2025