Compare commits

..

No commits in common. "e6df7be1cab52ea84a4c6752ad6f95ffa861cd32" and "d1caee0b54c4c656f3bc924fe1ccbea3fc346370" have entirely different histories.

View File

@ -278,15 +278,11 @@
// their own marketplace set this to their repo (a <meta name="lp-repo"> wins). // their own marketplace set this to their repo (a <meta name="lp-repo"> wins).
var REPO_URL = (document.querySelector('meta[name="lp-repo"]') || {}).content || 'https://github.com/librelad/LibrePortal'; var REPO_URL = (document.querySelector('meta[name="lp-repo"]') || {}).content || 'https://github.com/librelad/LibrePortal';
// The hash is either a view (#view=submit) or an app focus (#<slug>). function readFocus() {
function parseHash() {
var h = (window.location.hash || '').replace(/^#/, ''); var h = (window.location.hash || '').replace(/^#/, '');
if (/^view=(howto|submit|submissions)$/.test(h)) return { view: h.slice(5), focus: '' }; return /^[a-z0-9][a-z0-9_]{0,31}$/.test(h) ? h : '';
if (/^[a-z0-9][a-z0-9_]{0,31}$/.test(h)) return { view: 'browse', focus: h };
return { view: 'browse', focus: '' };
} }
var _ph = parseHash(); var state = { view: 'browse', apps: [], cat: 'all', q: '', focus: readFocus(),
var state = { view: _ph.view, apps: [], cat: 'all', q: '', focus: _ph.focus,
idx: null, channel: 'stable', signed: false, submissions: null }; idx: null, channel: 'stable', signed: false, submissions: null };
var main = document.getElementById('main'); var main = document.getElementById('main');
var cats = document.getElementById('cats'); var cats = document.getElementById('cats');
@ -434,20 +430,12 @@
else if (state.view === 'submissions') main.innerHTML = submissionsHtml(); else if (state.view === 'submissions') main.innerHTML = submissionsHtml();
else renderBrowse(); else renderBrowse();
} }
function setHash(h) { function go(view) { state.view = view; window.scrollTo(0, 0); render(); }
try { history.replaceState(null, '', h ? ('#' + h) : (window.location.pathname + window.location.search)); }
catch (_) { window.location.hash = h; }
}
function go(view) {
state.view = view; state.focus = '';
setHash(view === 'browse' ? '' : ('view=' + view));
window.scrollTo(0, 0); render();
}
function toBrowse() { state.view = 'browse'; } function toBrowse() { state.view = 'browse'; }
function clearFocus() { function clearFocus() {
if (!state.focus && state.view === 'browse') return; if (!state.focus) return;
state.focus = ''; state.focus = '';
if (window.location.hash) setHash(''); if (window.location.hash) { try { history.replaceState(null, '', window.location.pathname + window.location.search); } catch (_) { window.location.hash = ''; } }
} }
// ---- data ---- // ---- data ----
@ -515,7 +503,7 @@
if (e.target.closest('#showall')) { clearFocus(); render(); } if (e.target.closest('#showall')) { clearFocus(); render(); }
}); });
document.getElementById('q').addEventListener('input', function (e) { clearFocus(); toBrowse(); state.q = e.target.value; render(); }); document.getElementById('q').addEventListener('input', function (e) { clearFocus(); toBrowse(); state.q = e.target.value; render(); });
window.addEventListener('hashchange', function () { var ph = parseHash(); state.view = ph.view; state.focus = ph.focus; render(); }); window.addEventListener('hashchange', function () { state.focus = readFocus(); if (state.focus) toBrowse(); render(); });
render(); render();
load(); load();