From 179d7a9ad81209e4c3cce3006d8293e93935c3a1 Mon Sep 17 00:00:00 2001 From: ed Date: Sun, 25 Jul 2021 19:47:40 +0200 Subject: [PATCH] bikeshedding --- copyparty/web/browser.css | 4 +-- copyparty/web/browser.js | 74 ++++++++++++++++++++++++--------------- copyparty/web/util.js | 9 +++++ 3 files changed, 57 insertions(+), 30 deletions(-) diff --git a/copyparty/web/browser.css b/copyparty/web/browser.css index 3adae1f4..1f5132ae 100644 --- a/copyparty/web/browser.css +++ b/copyparty/web/browser.css @@ -453,10 +453,10 @@ html.light #ggrid a.sel { html.light #wfm a:not(.en) { color: #c4a; } -#files tbody td.c1 { +#files tbody tr.c1 td { animation: fcut1 .5s ease-out; } -#files tbody td.c2 { +#files tbody tr.c2 td { animation: fcut2 .5s ease-out; } @keyframes fcut1 { diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index 373993b8..34055a6c 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -1504,37 +1504,42 @@ var fileman = (function () { r.delete = function (e) { ev(e); var sel = msel.getsel(), - req = msel.selu; + vps = []; + + for (var a = 0; a < sel.length; a++) + vps.push(sel.vp); if (!sel.length) return alert('select at least 1 item to delete'); - if (!confirm('===== DANGER =====\nDELETE these ' + req.length + ' items?\n\n' + req.join('\n'))) + if (!confirm('===== DANGER =====\nDELETE these ' + vps.length + ' items?\n\n' + vps.join('\n'))) return; if (!confirm('Last chance! Delete?')) return; - toast.show(req.length + ' deletes left', 2000); + toast.show(vps.length + ' deletes left', 2000); }; r.cut = function (e) { ev(e); var sel = msel.getsel(), - vsel = msel.selu; + vps = []; if (!sel.length) return alert('select at least 1 item to cut'); - var tds = QSA('#files tbody tr.sel td'); - for (var a = 0; a < tds.length; a++) { - var cl = tds[a].classList, inv = cl.contains('c1'); + for (var a = 0; a < sel.length; a++) { + vps.push(sel[a].vp); + var cl = ebi(sel[a].id).closest('tr').classList, + inv = cl.contains('c1'); + cl.remove(inv ? 'c1' : 'c2'); cl.add(inv ? 'c2' : 'c1'); } toast.show('cut ' + sel.length + ' items', 1000); - jwrite('fman_clip', vsel); + jwrite('fman_clip', vps); r.tx(); }; @@ -1631,9 +1636,6 @@ var thegrid = (function () { ebi('griden').onclick = ebi('wtgrid').onclick = function (e) { ev(e); - if (!this.closest) - return; - r.en = !r.en; bcfg_set('griden', r.en); if (r.en) { @@ -2256,6 +2258,7 @@ document.onkeydown = function (e) { ofiles.setAttribute("q_raw", this.q_raw); set_vq(); mukey.render(); + msel.render(); reload_browser(); filecols.set_style(['File Name']); @@ -3171,31 +3174,45 @@ var arcfmt = (function () { var msel = (function () { var r = {}; - r.selu = null; - r.seln = null; + r.sel = null; + r.all = null; - r.getsel = function () { - if (r.seln !== null) - return r.seln; + r.load = function () { + if (r.sel) + return; - r.selu = []; - r.seln = []; - var links = QSA('#files tbody tr.sel td:nth-child(2) a'), + r.sel = []; + r.all = []; + var links = QSA('#files tbody td:nth-child(2) a:last-child'), vbase = get_evpath(); for (var a = 0, aa = links.length; a < aa; a++) { - var url = links[a].getAttribute('href').replace(/\/$/, ""), - name = url.split('/').slice(-1); + var href = links[a].getAttribute('href').replace(/\/$/, ""), + item = {}; - r.selu.push(url.indexOf('/') !== -1 ? url : vbase + url); - r.seln.push(name); - links[a].setAttribute('name', name); + item.id = links[a].getAttribute('id'); + item.sel = links[a].closest('tr').classList.contains('sel'); + item.vp = href.indexOf('/') !== -1 ? href : vbase + href; + item.name = href.split('/').slice(-1); + + r.all.push(item); + if (item.sel) + r.sel.push(item); + + links[a].setAttribute('name', item.name); } + }; - return r.seln; - } + r.getsel = function () { + r.load(); + return r.sel; + }; + r.getall = function () { + r.load(); + return r.all; + }; function selui() { - r.selu = r.seln = null; + r.sel = r.all = null; clmod(ebi('wtoggle'), 'sel', r.getsel().length); thegrid.loadsel(); fileman.render(); @@ -3249,9 +3266,10 @@ var msel = (function () { for (var a = 0, aa = tds.length; a < aa; a++) { tds[a].onclick = seltgl; } - r.selu = r.seln = null; + r.sel = r.all = null; arcfmt.render(); fileman.render(); + ebi('selzip').style.display = ebi('unsearch') ? 'none' : ''; } return r; })(); diff --git a/copyparty/web/util.js b/copyparty/web/util.js index cf37e61a..e8800c79 100644 --- a/copyparty/web/util.js +++ b/copyparty/web/util.js @@ -123,6 +123,15 @@ if (!String.startsWith) { return this.substring(i, i + s.length) === s; }; } +if (!Element.prototype.closest) { + Element.prototype.closest = function (s) { + var el = this; + do { + if (el.msMatchesSelector(s)) return el; + el = el.parentElement || el.parentNode; + } while (el !== null && el.nodeType === 1); + } +} // https://stackoverflow.com/a/950146