mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-04-06 00:05:49 +00:00
deploy: a83779f7c9
This commit is contained in:
@@ -18,16 +18,53 @@ async function initDirectory() {
|
||||
const topBtn = document.querySelector('#top-pagination .top');
|
||||
const searchInput = document.getElementById('search');
|
||||
allEntries = listing.entries
|
||||
renderEntries('top', bySortPriority, topBtn)
|
||||
searchInput.addEventListener('input', (e) => renderEntries('top', bySortPriority, topBtn, e.target.value.trim()));
|
||||
|
||||
applyHash();
|
||||
|
||||
searchInput.addEventListener('input', (e) => renderEntries('top', bySortPriority, topBtn, e.target.value.trim(), true));
|
||||
liveBtn.addEventListener('click', () => renderEntries('live', byActiveAtDesc, liveBtn));
|
||||
newBtn.addEventListener('click', () => renderEntries('new', byCreatedAtDesc, newBtn));
|
||||
topBtn.addEventListener('click', () => renderEntries('top', bySortPriority, topBtn));
|
||||
window.addEventListener('popstate', applyHash);
|
||||
|
||||
function applyHash() {
|
||||
const hash = location.hash;
|
||||
let mode, comparator, btn, search = '';
|
||||
switch (hash) {
|
||||
case '#active':
|
||||
mode = 'live';
|
||||
comparator = byActiveAtDesc;
|
||||
btn = liveBtn;
|
||||
case '#new':
|
||||
mode = 'new';
|
||||
comparator = byCreatedAtDesc;
|
||||
btn = newBtn;
|
||||
default:
|
||||
mode = 'top';
|
||||
comparator = bySortPriority;
|
||||
btn = topBtn;
|
||||
try {
|
||||
if (hash.startsWith('#q=')) {
|
||||
search = decodeURIComponent(hash.slice(3));
|
||||
if (search) searchInput.value = search;
|
||||
}
|
||||
} catch(e) {}
|
||||
}
|
||||
currentSortMode = '';
|
||||
currentSearch = '';
|
||||
currentPage = 1;
|
||||
renderEntries(mode, comparator, btn, search);
|
||||
}
|
||||
|
||||
function renderEntries(mode, comparator, btn, search = '') {
|
||||
if (currentSortMode === mode && search == currentSearch) return;
|
||||
currentSortMode = mode;
|
||||
if (location.hash) location.hash = '';
|
||||
const hash = search ? '#q=' + encodeURIComponent(search)
|
||||
: mode === 'live' ? '#active'
|
||||
: mode === 'new' ? '#new'
|
||||
: '';
|
||||
const url = hash || (location.pathname + location.search);
|
||||
history.replaceState(null, '', url);
|
||||
liveBtn.classList.remove('active');
|
||||
newBtn.classList.remove('active');
|
||||
topBtn.classList.remove('active');
|
||||
|
||||
Reference in New Issue
Block a user