code.gitea.io/gitea@v1.21.7/web_src/js/features/tablesort.js (about)

     1  export function initTableSort() {
     2    for (const header of document.querySelectorAll('th[data-sortt-asc]') || []) {
     3      const sorttAsc = header.getAttribute('data-sortt-asc');
     4      const sorttDesc = header.getAttribute('data-sortt-desc');
     5      const sorttDefault = header.getAttribute('data-sortt-default');
     6      header.addEventListener('click', () => {
     7        tableSort(sorttAsc, sorttDesc, sorttDefault);
     8      });
     9    }
    10  }
    11  
    12  function tableSort(normSort, revSort, isDefault) {
    13    if (!normSort) return false;
    14    if (!revSort) revSort = '';
    15  
    16    const url = new URL(window.location);
    17    let urlSort = url.searchParams.get('sort');
    18    if (!urlSort && isDefault) urlSort = normSort;
    19  
    20    url.searchParams.set('sort', urlSort !== normSort ? normSort : revSort);
    21    window.location.replace(url.href);
    22  }