' + esc(uricom_dec(file.name)[0]) + ' ');
}
ebi('docul').innerHTML = html.join('\n');
};
r.updtree = function () {
var fn = QS('#path span:last-child'),
lis = QSA('#docul li a');
fn = fn ? fn.textContent : '';
for (var a = 0, aa = lis.length; a < aa; a++)
clmod(lis[a], 'hl', lis[a].textContent == fn);
};
var bdoc = ebi('bdoc');
bdoc.setAttribute('class', 'line-numbers');
bdoc.innerHTML = (
''
);
ebi('xdoc').onclick = function () {
thegrid.setvis(true);
};
ebi('dldoc').setAttribute('download', '');
ebi('prevdoc').onclick = function () { tree_neigh(-1); };
ebi('nextdoc').onclick = function () { tree_neigh(1); };
return r;
})();
var thegrid = (function () {
var lfiles = ebi('files'),
gfiles = mknod('div');
gfiles.setAttribute('id', 'gfiles');
gfiles.style.display = 'none';
gfiles.innerHTML = (
'' +
'
'
);
lfiles.parentNode.insertBefore(gfiles, lfiles);
var r = {
'sz': clamp(fcfg_get('gridsz', 10), 4, 40),
'ln': clamp(icfg_get('gridln', 3), 1, 7),
'isdirty': true,
'bbox': null
};
var btnclick = function (e) {
ev(e);
var s = this.getAttribute('s'),
z = this.getAttribute('z'),
l = this.getAttribute('l');
if (z)
return setsz(z > 0 ? r.sz * z : r.sz / (-z));
if (l)
return setln(parseInt(l));
var t = lfiles.tHead.rows[0].cells;
for (var a = 0; a < t.length; a++)
if (t[a].getAttribute('name') == s) {
t[a].click();
break;
}
r.setdirty();
};
var links = QSA('#ghead a');
for (var a = 0; a < links.length; a++)
links[a].onclick = btnclick;
r.setvis = function (force) {
if (showfile.active()) {
if (!force)
return;
hist_push(get_evpath());
}
var vis = has(perms, "read");
gfiles.style.display = vis && r.en ? '' : 'none';
lfiles.style.display = vis && !r.en ? '' : 'none';
ebi('pro').style.display = ebi('epi').style.display = ebi('treeul').style.display = ebi('treepar').style.display = '';
ebi('bdoc').style.display = 'none';
clmod(ebi('wrap'), 'doc');
qsr('#docname');
if (window['treectl'])
treectl.textmode(false);
};
r.setdirty = function () {
r.dirty = true;
if (r.en) {
loadgrid();
}
r.setvis();
};
function setln(v) {
if (v) {
r.ln += v;
if (r.ln < 1) r.ln = 1;
if (r.ln > 7) r.ln = v < 0 ? 7 : 99;
swrite('gridln', r.ln);
setTimeout(r.tippen, 20);
}
try {
document.documentElement.style.setProperty('--grid-ln', r.ln);
}
catch (ex) { }
}
setln();
function setsz(v) {
if (v !== undefined) {
r.sz = clamp(v, 4, 40);
swrite('gridsz', r.sz);
setTimeout(r.tippen, 20);
}
try {
document.documentElement.style.setProperty('--grid-sz', r.sz + 'em');
}
catch (ex) { }
}
setsz();
function gclick(e) {
if (ctrl(e))
return true;
var oth = ebi(this.getAttribute('ref')),
href = noq_href(this),
aplay = ebi('a' + oth.getAttribute('id')),
is_img = /\.(gif|jpe?g|png|webp|webm|mp4)(\?|$)/i.test(href),
in_tree = null,
have_sel = QS('#files tr.sel'),
td = oth.closest('td').nextSibling,
tr = td.parentNode;
if (href.endsWith('/'))
in_tree = treectl.find(oth.textContent.slice(0, -1));
if (r.sel) {
td.click();
clmod(this, 'sel', clgot(tr, 'sel'));
}
else if (widget.is_open && aplay)
aplay.click();
else if (in_tree && !have_sel)
in_tree.click();
else if (!is_img && have_sel)
window.open(href, '_blank');
else return true;
ev(e);
}
r.loadsel = function () {
if (r.dirty)
return;
var ths = QSA('#ggrid>a');
for (var a = 0, aa = ths.length; a < aa; a++) {
var tr = ebi(ths[a].getAttribute('ref')).closest('tr'),
cl = tr.getAttribute('class') || '';
if (noq_href(ths[a]).endsWith('/'))
cl += ' dir';
ths[a].setAttribute('class', cl);
}
var uns = QS('#ggrid a[ref="unsearch"]');
if (uns)
uns.onclick = function (e) {
ev(e);
ebi('unsearch').click();
};
};
r.tippen = function () {
var els = QSA('#ggrid>a>span'),
aa = els.length;
if (!aa)
return;
var cs = window.getComputedStyle(els[0]),
fs = parseFloat(cs.lineHeight),
pad = parseFloat(cs.paddingTop),
pels = [],
todo = [];
for (var a = 0; a < aa; a++) {
var vis = Math.round((els[a].offsetHeight - pad) / fs),
all = Math.round((els[a].scrollHeight - pad) / fs),
par = els[a].parentNode;
pels.push(par);
todo.push(vis < all ? par.getAttribute('ttt') : null);
}
for (var a = 0; a < todo.length; a++) {
if (todo[a])
pels[a].setAttribute('tt', todo[a]);
else
pels[a].removeAttribute('tt');
}
tt.att(ebi('ggrid'));
};
function loadgrid() {
if (have_webp === null)
return setTimeout(loadgrid, 50);
r.setvis();
if (!r.dirty)
return r.loadsel();
var html = [];
var files = QSA('#files>tbody>tr>td:nth-child(2) a[id]');
for (var a = 0, aa = files.length; a < aa; a++) {
var ao = files[a],
ohref = esc(ao.getAttribute('href')),
href = ohref.split('?')[0],
name = uricom_dec(vsplit(href)[1])[0],
ref = ao.getAttribute('id'),
isdir = href.endsWith('/'),
ac = isdir ? ' class="dir"' : '',
ihref = href;
if (r.thumbs) {
ihref += '?th=' + (have_webp ? 'w' : 'j');
if (href == "#")
ihref = '/.cpr/ico/โ๏ธ';
}
else if (isdir) {
ihref = '/.cpr/ico/folder';
}
else {
var ar = href.split('.');
if (ar.length > 1)
ar = ar.slice(1);
ihref = '';
ar.reverse();
for (var b = 0; b < ar.length; b++) {
if (ar[b].length > 7)
break;
ihref = ar[b] + '.' + ihref;
}
if (!ihref) {
ihref = 'unk.';
}
ihref = '/.cpr/ico/' + ihref.slice(0, -1);
}
ihref += (ihref.indexOf('?') > 0 ? '&' : '?') + 'cache=i';
html.push('' + ao.innerHTML + ' ');
}
ebi('ggrid').innerHTML = html.join('\n');
var ths = QSA('#ggrid>a');
for (var a = 0, aa = ths.length; a < aa; a++)
ths[a].onclick = gclick;
r.dirty = false;
r.bagit();
r.loadsel();
setTimeout(r.tippen, 20);
}
r.bagit = function () {
if (!window.baguetteBox)
return;
if (r.bbox)
baguetteBox.destroy();
r.bbox = baguetteBox.run('#ggrid', {
captions: function (g) {
var idx = -1,
h = '' + g;
for (var a = 0; a < r.bbox.length; a++)
if (r.bbox[a].imageElement == g)
idx = a;
return '' + (idx + 1) + ' / ' + r.bbox.length + ' -- ' +
esc(uricom_dec(h.split('/').pop())[0]) + ' ';
}
})[0];
};
bcfg_bind(r, 'thumbs', 'thumbs', true, r.setdirty);
bcfg_bind(r, 'sel', 'gridsel', false, r.loadsel);
bcfg_bind(r, 'en', 'griden', false, function (v) {
v ? loadgrid() : r.setvis(true);
pbar.onresize();
vbar.onresize();
});
ebi('wtgrid').onclick = ebi('griden').onclick;
setTimeout(function () {
import_js('/.cpr/baguettebox.js', r.bagit);
}, 1);
if (r.en) {
loadgrid();
}
return r;
})();
function th_onload(el) {
el.style.height = '';
}
function tree_scrollto(e) {
ev(e);
tree_scrolltoo('#treeul a.hl');
tree_scrolltoo('#docul a.hl');
}
function tree_scrolltoo(q) {
var act = QS(q),
ul = act ? act.offsetParent : null;
if (!ul)
return;
var ctr = ebi('tree'),
em = parseFloat(getComputedStyle(act).fontSize),
top = act.offsetTop + ul.offsetTop,
min = top - 11 * em,
max = top - (ctr.offsetHeight - 10 * em);
if (ctr.scrollTop > min)
ctr.scrollTop = Math.floor(min);
else if (ctr.scrollTop < max)
ctr.scrollTop = Math.floor(max);
}
function tree_neigh(n) {
var links = QSA(showfile.active() ? '#docul li>a' : '#treeul li>a+a');
if (!links.length) {
treectl.dir_cb = function () {
tree_neigh(n);
};
treectl.entree(null, true);
return;
}
var act = -1;
for (var a = 0, aa = links.length; a < aa; a++) {
if (links[a].getAttribute('class') == 'hl') {
act = a;
break;
}
}
if (act == -1)
return;
act += n;
if (act < 0)
act = links.length - 1;
if (act >= links.length)
act = 0;
treectl.dir_cb = tree_scrollto;
links[act].click();
}
function tree_up() {
if (showfile.active())
return thegrid.setvis(true);
var act = QS('#treeul a.hl');
if (!act) {
treectl.dir_cb = tree_up;
treectl.entree(null, true);
return;
}
if (act.previousSibling.textContent == '-')
return act.previousSibling.click();
act.parentNode.parentNode.parentNode.getElementsByTagName('a')[1].click();
}
document.onkeydown = function (e) {
var ae = document.activeElement, aet = '';
if (ae && ae != document.body)
aet = ae.nodeName.toLowerCase();
if (e.altKey || e.isComposing)
return;
if (QS('#bbox-overlay.visible'))
return;
var k = e.code + '', pos = -1, n;
if (aet == 'tr' && ae.closest('#files')) {
var d = '';
if (k == 'ArrowUp') d = 'previous';
if (k == 'ArrowDown') d = 'next';
if (d) {
var el = ae[d + 'ElementSibling'];
if (el) {
el.focus();
if (ctrl(e))
document.documentElement.scrollTop += (d == 'next' ? 1 : -1) * el.offsetHeight;
if (e.shiftKey) {
clmod(el, 'sel', 't');
msel.selui();
}
return ev(e);
}
}
if (k == 'Space') {
clmod(ae, 'sel', 't');
msel.selui();
return ev(e);
}
if (k == 'KeyA' && ctrl(e)) {
var sel = msel.getsel(),
all = msel.getall();
msel.evsel(e, sel.length < all.length);
return ev(e);
}
}
if (ae.closest('pre')) {
if (k == 'KeyA' && ctrl(e)) {
var sel = document.getSelection(),
ran = document.createRange();
sel.removeAllRanges();
ran.selectNode(ae.closest('pre'));
sel.addRange(ran);
return ev(e);
}
}
if (aet && aet != 'a' && aet != 'tr' && aet != 'pre')
return;
if (ctrl(e)) {
if (k == 'KeyX')
return fileman.cut();
if (k == 'KeyV')
return fileman.paste();
if (k == 'KeyK')
return fileman.delete();
return;
}
if (e.shiftKey && k != 'KeyA' && k != 'KeyD')
return;
if (k.indexOf('Digit') === 0)
pos = parseInt(k.slice(-1)) * 0.1;
if (pos !== -1)
return seek_au_mul(pos) || true;
if (k == 'KeyJ')
return prev_song() || true;
if (k == 'KeyL')
return next_song() || true;
if (k == 'KeyP')
return playpause() || true;
n = k == 'KeyU' ? -10 : k == 'KeyO' ? 10 : 0;
if (n !== 0)
return seek_au_rel(n) || true;
n = k == 'KeyI' ? -1 : k == 'KeyK' ? 1 : 0;
if (n !== 0)
return tree_neigh(n);
if (k == 'KeyM')
return tree_up();
if (k == 'KeyB')
return treectl.hidden ? treectl.entree() : treectl.detree();
if (k == 'KeyG')
return ebi('griden').click();
if (k == 'KeyT')
return ebi('thumbs').click();
if (k == 'KeyV')
return ebi('filetree').click();
if (k == 'F2')
return fileman.rename();
if (!treectl.hidden && (!e.shiftKey || !thegrid.en)) {
if (k == 'KeyA')
return QS('#twig').click();
if (k == 'KeyD')
return QS('#twobytwo').click();
}
if (thegrid.en) {
if (k == 'KeyS')
return ebi('gridsel').click();
if (k == 'KeyA')
return QSA('#ghead a[z]')[0].click();
if (k == 'KeyD')
return QSA('#ghead a[z]')[1].click();
}
};
// search
(function () {
var sconf = [
["size",
["szl", "sz_min", "minimum MiB", "16"],
["szu", "sz_max", "maximum MiB", "16"]
],
["date",
["dtl", "dt_min", "min. iso8601", "16"],
["dtu", "dt_max", "max. iso8601", "16"]
],
["path",
["path", "path", "path contains (space-separated)", "34"]
],
["name",
["name", "name", "name contains (negate with -nope)", "34"]
]
];
var oldcfg = [];
if (QS('#srch_form.tags')) {
sconf.push(["tags",
["tags", "tags", "tags contains (^=start, end=$)", "34"]
]);
sconf.push(["adv.",
["adv", "adv", "key>=1A key<=2B .bpm>165", "34"]
]);
}
var trs = [],
orig_url = null,
orig_html = null;
for (var a = 0; a < sconf.length; a++) {
var html = [' ' + sconf[a][0] + ' '];
for (var b = 1; b < 3; b++) {
var hn = "srch_" + sconf[a][b][0],
csp = (sconf[a].length == 2) ? 2 : 1;
html.push(
' \n' +
'' + sconf[a][b][2] + ' \n' +
' ');
if (csp == 2)
break;
}
html.push(' ');
trs.push(html);
}
var html = [];
for (var a = 0; a < trs.length; a += 2) {
html.push('' + (trs[a].concat(trs[a + 1])).join('\n') + '
');
}
html.push('');
ebi('srch_form').innerHTML = html.join('\n');
var o = QSA('#op_search input');
for (var a = 0; a < o.length; a++) {
o[a].oninput = ev_search_input;
}
function srch_msg(err, txt) {
var o = ebi('srch_q');
o.textContent = txt;
o.style.color = err ? '#f09' : '#c90';
}
var search_timeout,
defer_timeout,
search_in_progress = 0;
function ev_search_input() {
var v = this.value,
id = this.getAttribute('id');
if (id.slice(-1) == 'v') {
var chk = ebi(id.slice(0, -1) + 'c');
chk.checked = ((v + '').length > 0);
}
if (id != "q_raw")
encode_query();
set_vq();
clearTimeout(defer_timeout);
defer_timeout = setTimeout(try_search, 2000);
try_search(v);
}
function try_search(v) {
if (Date.now() - search_in_progress > 30 * 1000) {
clearTimeout(defer_timeout);
clearTimeout(search_timeout);
search_timeout = setTimeout(do_search,
v && v.length < (is_touch ? 4 : 3) ? 600 : 200);
}
}
function set_vq() {
if (search_in_progress)
return;
var q = ebi('q_raw').value,
vq = ebi('files').getAttribute('q_raw');
srch_msg(false, (q == vq) ? '' : 'search results below are from a previous query:\n ' + (vq ? vq : '(*)'));
}
function encode_query() {
var q = '';
for (var a = 0; a < sconf.length; a++) {
for (var b = 1; b < sconf[a].length; b++) {
var k = sconf[a][b][0],
chk = 'srch_' + k + 'c',
tvs = ebi('srch_' + k + 'v').value.split(/ +/g);
if (!ebi(chk).checked)
continue;
for (var c = 0; c < tvs.length; c++) {
var tv = tvs[c];
if (!tv.length)
break;
q += ' and ';
if (k == 'adv') {
q += tv.replace(/ +/g, " and ").replace(/([=!><]=?)/, " $1 ");
continue;
}
if (k.length == 3) {
q += k.replace(/sz/, 'size').replace(/dt/, 'date').replace(/l$/, ' >= ').replace(/u$/, ' <= ') + tv;
continue;
}
if (k == 'path' || k == 'name' || k == 'tags') {
var not = ' ';
if (tv.slice(0, 1) == '-') {
tv = tv.slice(1);
not = ' not ';
}
if (tv.slice(0, 1) == '^') {
tv = tv.slice(1);
}
else {
tv = '*' + tv;
}
if (tv.slice(-1) == '$') {
tv = tv.slice(0, -1);
}
else {
tv += '*';
}
q += k + not + 'like ' + tv;
}
}
}
}
ebi('q_raw').value = q.slice(5);
}
function do_search() {
search_in_progress = Date.now();
srch_msg(false, "searching...");
clearTimeout(search_timeout);
var xhr = new XMLHttpRequest();
xhr.open('POST', '/?srch', true);
xhr.setRequestHeader('Content-Type', 'text/plain');
xhr.onreadystatechange = xhr_search_results;
xhr.ts = Date.now();
xhr.q_raw = ebi('q_raw').value;
xhr.send(JSON.stringify({ "q": xhr.q_raw }));
}
function xhr_search_results() {
if (this.readyState != XMLHttpRequest.DONE)
return;
if (this.status !== 200) {
var msg = this.responseText;
if (msg.indexOf('') === 0)
msg = msg.slice(5);
srch_msg(true, "http " + this.status + ": " + msg);
search_in_progress = 0;
return;
}
search_in_progress = 0;
srch_msg(false, '');
var res = JSON.parse(this.responseText),
tagord = res.tag_order;
sortfiles(res.hits);
var ofiles = ebi('files');
if (ofiles.getAttribute('ts') > this.ts)
return;
treectl.hide();
var html = mk_files_header(tagord);
html.push('');
html.push('- [โ] close search results ');
for (var a = 0; a < res.hits.length; a++) {
var r = res.hits[a],
ts = parseInt(r.ts),
sz = esc(r.sz + ''),
rp = esc(uricom_dec(r.rp + '')[0]),
ext = rp.lastIndexOf('.') > 0 ? rp.split('.').pop() : '%',
links = linksplit(r.rp + '');
if (ext.length > 8)
ext = '%';
links = links.join('');
var nodes = ['- ' + links + '
', sz];
for (var b = 0; b < tagord.length; b++) {
var k = tagord[b],
v = r.tags[k] || "";
if (k == ".dur") {
var sv = v ? s2ms(v) : "";
nodes[nodes.length - 1] += '' + sv;
continue;
}
nodes.push(v);
}
nodes = nodes.concat([ext, unix2iso(ts)]);
html.push(nodes.join(' '));
html.push(' ');
}
if (!orig_html || orig_url != get_evpath()) {
orig_html = ebi('files').innerHTML;
orig_url = get_evpath();
}
ofiles = set_files_html(html.join('\n'));
ofiles.setAttribute("ts", this.ts);
ofiles.setAttribute("q_raw", this.q_raw);
set_vq();
mukey.render();
reload_browser();
filecols.set_style(['File Name']);
sethash('q=' + uricom_enc(this.q_raw));
ebi('unsearch').onclick = unsearch;
}
function unsearch(e) {
ev(e);
treectl.show();
set_files_html(orig_html);
ebi('files').removeAttribute('q_raw');
orig_html = null;
sethash('');
reload_browser();
}
})();
var treectl = (function () {
var r = {
"hidden": true,
"ls_cb": null,
"dir_cb": tree_scrollto,
"pdir": []
},
entreed = false,
fixedpos = false,
prev_atop = null,
prev_winh = null,
mentered = null,
treesz = clamp(icfg_get('treesz', 16), 10, 50);
bcfg_bind(r, 'ireadme', 'ireadme', true);
bcfg_bind(r, 'dyn', 'dyntree', true, onresize);
bcfg_bind(r, 'dots', 'dotfiles', false, function (v) {
r.goto(get_evpath());
});
setwrap(bcfg_bind(r, 'wtree', 'wraptree', true, setwrap));
setwrap(bcfg_bind(r, 'parpane', 'parpane', true, onscroll));
bcfg_bind(r, 'htree', 'hovertree', true, reload_tree);
function setwrap(v) {
clmod(ebi('tree'), 'nowrap', !v);
reload_tree();
}
setwrap(r.wtree);
r.entree = function (e, nostore) {
ev(e);
entreed = true;
if (!nostore)
swrite('entreed', 'tree');
get_tree("", get_evpath(), true);
r.show();
}
r.show = function () {
r.hidden = false;
if (!entreed) {
ebi('path').style.display = 'inline-block';
return;
}
ebi('path').style.display = 'none';
ebi('tree').style.display = 'block';
window.addEventListener('scroll', onscroll);
window.addEventListener('resize', onresize);
onresize();
};
r.detree = function (e) {
ev(e);
entreed = false;
swrite('entreed', 'na');
r.hide();
ebi('path').style.display = '';
}
r.hide = function () {
r.hidden = true;
ebi('path').style.display = 'none';
ebi('tree').style.display = 'none';
ebi('wrap').style.marginLeft = '';
window.removeEventListener('resize', onresize);
window.removeEventListener('scroll', onscroll);
}
function unmenter() {
if (mentered) {
mentered.style.position = '';
mentered = null;
}
}
r.textmode = function (ya) {
r.texts = ya;
ebi('docul').style.display = ya ? '' : 'none';
ebi('treeul').style.display = ebi('treepar').style.display = ya ? 'none' : '';
clmod(ebi('filetree'), 'on', ya);
tree_scrollto();
};
ebi('filetree').onclick = function (e) {
ev(e);
r.textmode(!r.texts);
};
r.textmode(false);
function onscroll() {
unmenter();
onscroll2();
}
function onscroll2() {
if (!entreed || r.hidden || document.visibilityState == 'hidden')
return;
var tree = ebi('tree'),
wrap = ebi('wrap'),
wraptop = null,
atop = wrap.getBoundingClientRect().top,
winh = window.innerHeight,
parp = ebi('treepar'),
y = tree.scrollTop,
w = tree.offsetWidth;
if (atop !== prev_atop || winh !== prev_winh)
wraptop = Math.floor(wrap.offsetTop);
if (r.parpane && r.pdir.length && w != r.pdirw) {
r.pdirw = w;
compy();
}
if (!r.parpane || !r.pdir.length || y >= r.pdir.slice(-1)[0][0] || y <= r.pdir[0][0]) {
clmod(parp, 'off', 1);
r.pdirh = null;
}
else {
var h1 = [], h2 = [], els = [];
for (var a = 0; a < r.pdir.length; a++) {
if (r.pdir[a][0] > y)
break;
var e2 = r.pdir[a][1], e1 = e2.previousSibling;
h1.push('' + e1.outerHTML + e2.outerHTML + ' ');
els.push([e1, e2]);
}
h1 = h1.join('\n') + h2.join('\n');
if (h1 != r.pdirh) {
r.pdirh = h1;
parp.innerHTML = h1;
clmod(parp, 'off');
var els = QSA('#treepar a');
for (var a = 0, aa = els.length; a < aa; a++)
els[a].onclick = bad_proxy;
}
y = ebi('treeh').offsetHeight;
if (!fixedpos)
y += tree.offsetTop - document.documentElement.scrollTop;
y = (y - 3) + 'px';
if (parp.style.top != y)
parp.style.top = y;
}
if (wraptop === null)
return;
prev_atop = atop;
prev_winh = winh;
if (fixedpos && atop >= 0) {
tree.style.position = 'absolute';
tree.style.bottom = '';
fixedpos = false;
}
else if (!fixedpos && atop < 0) {
tree.style.position = 'fixed';
tree.style.height = 'auto';
fixedpos = true;
}
if (fixedpos) {
tree.style.top = Math.max(0, parseInt(atop)) + 'px';
}
else {
var top = Math.max(0, wraptop),
treeh = winh - atop;
tree.style.top = top + 'px';
tree.style.height = treeh < 10 ? '' : Math.floor(treeh - 2) + 'px';
}
}
timer.add(onscroll2, true);
function onresize(e) {
if (!entreed || r.hidden)
return;
var q = '#tree',
nq = -3;
while (r.dyn) {
nq++;
q += '>ul>li';
if (!QS(q))
break;
}
var iw = (treesz + Math.max(0, nq)),
w = iw + 'em',
w2 = (iw + 2) + 'em';
try {
document.documentElement.style.setProperty('--nav-sz', w);
}
catch (ex) { }
ebi('tree').style.width = w;
ebi('wrap').style.marginLeft = w2;
onscroll();
}
r.find = function (txt) {
var ta = QSA('#treeul a.hl+ul>li>a+a');
for (var a = 0, aa = ta.length; a < aa; a++)
if (ta[a].textContent == txt)
return ta[a];
};
r.goto = function (url, push) {
get_tree("", url, true);
reqls(url, push, true);
};
function get_tree(top, dst, rst) {
var xhr = new XMLHttpRequest();
xhr.top = top;
xhr.dst = dst;
xhr.rst = rst;
xhr.ts = Date.now();
xhr.open('GET', dst + '?tree=' + top + (r.dots ? '&dots' : ''), true);
xhr.onreadystatechange = recvtree;
xhr.send();
enspin('#tree');
}
function recvtree() {
if (this.readyState != XMLHttpRequest.DONE)
return;
if (this.status !== 200) {
toast.err(0, "recvtree, http " + this.status + ": " + this.responseText);
return;
}
var cur = ebi('treeul').getAttribute('ts');
if (cur && parseInt(cur) > this.ts) {
console.log("reject tree");
return;
}
ebi('treeul').setAttribute('ts', this.ts);
var top = this.top == '.' ? this.dst : this.top,
name = uricom_dec(top.split('/').slice(-2)[0])[0],
rtop = top.replace(/^\/+/, ""),
res;
try {
res = JSON.parse(this.responseText);
}
catch (ex) {
return;
}
var html = parsetree(res, rtop);
if (!this.top) {
html = '- [root] \n' + html;
if (this.rst || !ebi('treeul').getElementsByTagName('li').length)
ebi('treeul').innerHTML = html + ' ';
}
else {
html = '- ' + esc(name) +
" \n";
var links = QSA('#treeul a+a');
for (var a = 0, aa = links.length; a < aa; a++) {
if (links[a].getAttribute('href') == top) {
var o = links[a].parentNode;
if (!o.getElementsByTagName('li').length)
o.innerHTML = html;
}
}
}
QS('#treeul>li>a+a').textContent = '[root]';
despin('#tree');
reload_tree();
onresize();
var fun = r.dir_cb;
if (fun) {
r.dir_cb = null;
try {
fun();
}
catch (ex) {
console.log("dir_cb failed", ex);
}
}
}
function reload_tree() {
var cdir = get_vpath(),
links = QSA('#treeul a+a'),
nowrap = QS('#tree.nowrap') && QS('#hovertree.on'),
act = null;
for (var a = 0, aa = links.length; a < aa; a++) {
var href = uricom_dec(links[a].getAttribute('href'))[0],
cl = '';
if (href == cdir) {
act = links[a];
cl = 'hl';
}
else if (cdir.startsWith(href)) {
cl = 'par';
}
links[a].setAttribute('class', cl);
links[a].onclick = treego;
links[a].onmouseenter = nowrap ? menter : null;
links[a].onmouseleave = nowrap ? mleave : null;
}
links = QSA('#treeul li>a:first-child');
for (var a = 0, aa = links.length; a < aa; a++) {
links[a].setAttribute('dst', links[a].nextSibling.getAttribute('href'));
links[a].onclick = treegrow;
}
ebi('tree').onscroll = nowrap ? unmenter : null;
r.pdir = [];
try {
while (act) {
r.pdir.unshift([-1, act]);
act = act.parentNode.parentNode.closest('li').querySelector('a:first-child+a');
}
}
catch (ex) { }
r.pdir.shift();
r.pdirw = -1;
}
function compy() {
for (var a = 0; a < r.pdir.length; a++)
r.pdir[a][0] = r.pdir[a][1].offsetTop;
var ofs = 0;
for (var a = 0; a < r.pdir.length - 1; a++) {
ofs += r.pdir[a][1].offsetHeight + 1;
r.pdir[a + 1][0] -= ofs;
}
}
function menter(e) {
var p = this.offsetParent,
pp = p.offsetParent,
ppy = pp.offsetTop,
y = this.offsetTop + p.offsetTop + ppy - p.scrollTop - pp.scrollTop - (ppy ? document.documentElement.scrollTop : 0);
this.style.top = y + 'px';
this.style.position = 'fixed';
mentered = this;
}
function mleave(e) {
this.style.position = '';
mentered = null;
}
function bad_proxy(e) {
ev(e);
var dst = this.getAttribute('dst'),
k = dst ? 'dst' : 'href',
v = dst ? dst : this.getAttribute('href'),
els = QSA('#treeul a');
for (var a = 0, aa = els.length; a < aa; a++)
if (els[a].getAttribute(k) === v)
return els[a].click();
}
function treego(e) {
if (ctrl(e))
return true;
ev(e);
if (this.getAttribute('class') == 'hl' &&
this.previousSibling.textContent == '-') {
treegrow.call(this.previousSibling, e);
return;
}
reqls(this.getAttribute('href'), true);
r.dir_cb = tree_scrollto;
thegrid.setvis(true);
}
function reqls(url, hpush, no_tree) {
var xhr = new XMLHttpRequest();
xhr.top = url;
xhr.hpush = hpush;
xhr.ts = Date.now();
xhr.open('GET', xhr.top + '?ls' + (r.dots ? '&dots' : ''), true);
xhr.onreadystatechange = recvls;
xhr.send();
if (hpush && !no_tree)
get_tree('.', xhr.top);
enspin(thegrid.en ? '#gfiles' : '#files');
}
function treegrow(e) {
ev(e);
if (this.textContent == '-') {
while (this.nextSibling.nextSibling) {
var rm = this.nextSibling.nextSibling;
rm.parentNode.removeChild(rm);
}
this.textContent = '+';
onresize();
return;
}
var dst = this.getAttribute('dst');
get_tree('.', dst);
}
function recvls() {
if (this.readyState != XMLHttpRequest.DONE)
return;
if (this.status !== 200) {
toast.err(0, "recvls, http " + this.status + ": " + this.responseText);
return;
}
var cur = ebi('files').getAttribute('ts');
if (cur && parseInt(cur) > this.ts) {
console.log("reject ls");
return;
}
ebi('files').setAttribute('ts', this.ts);
try {
var res = JSON.parse(this.responseText);
}
catch (ex) {
window.location = this.top;
return;
}
ebi('srv_info').innerHTML = '' + res.srvinf + ' ';
var top = this.top,
nodes = res.dirs.concat(res.files),
html = mk_files_header(res.taglist);
showfile.files = [];
html.push(' ');
nodes = sortfiles(nodes);
for (var a = 0; a < nodes.length; a++) {
var tn = nodes[a],
bhref = tn.href.split('?')[0],
fname = uricom_dec(bhref)[0],
hname = esc(fname),
sortv = (bhref.slice(-1) == '/' ? '\t' : '') + hname,
id = 'f-' + ('00000000' + crc32(fname)).slice(-8),
lang = showfile.getlang(fname);
if (lang)
showfile.files.push({ 'id': id, 'name': fname });
if (tn.lead == '-')
tn.lead = '-txt- ';
var ln = ['' + tn.lead + ' ' + hname + ' ', tn.sz];
for (var b = 0; b < res.taglist.length; b++) {
var k = res.taglist[b],
v = (tn.tags || {})[k] || "";
if (k == ".dur") {
var sv = v ? s2ms(v) : "";
ln[ln.length - 1] += '' + sv;
continue;
}
ln.push(v);
}
ln = ln.concat([tn.ext, unix2iso(tn.ts)]).join(' ');
html.push(ln + ' ');
}
html.push(' ');
html = html.join('\n');
set_files_html(html);
if (this.hpush && !showfile.active())
hist_push(this.top);
acct = res.acct;
apply_perms(res.perms);
despin('#files');
despin('#gfiles');
ebi('pro').innerHTML = res.logues ? res.logues[0] || "" : "";
ebi('epi').innerHTML = res.logues ? res.logues[1] || "" : "";
clmod(ebi('epi'), 'mdo');
if (res.readme)
show_readme(res.readme);
document.title = 'โ๐ ' + uricom_dec(document.location.pathname.slice(1, -1))[0];
filecols.set_style();
showfile.mktree();
mukey.render();
reload_tree();
reload_browser();
tree_scrollto();
var fun = r.ls_cb;
if (fun) {
r.ls_cb = null;
fun();
}
}
function parsetree(res, top) {
var ret = '';
for (var a = 0; a < res.a.length; a++) {
if (res.a[a] !== '')
res['k' + res.a[a]] = 0;
}
delete res['a'];
var keys = Object.keys(res);
keys.sort(function (a, b) { return a.localeCompare(b); });
for (var a = 0; a < keys.length; a++) {
var kk = keys[a],
ks = kk.slice(1),
k = uricom_dec(ks),
hek = esc(k[0]),
uek = k[1] ? uricom_enc(k[0], true) : k[0],
url = '/' + (top ? top + uek : uek) + '/',
sym = res[kk] ? '-' : '+',
link = '' + sym + ' ' + hek + ' ';
if (res[kk]) {
var subtree = parsetree(res[kk], url.slice(1));
ret += '