From 37c84021a28857ab3f5e39ced3e8dd04bb6c7eae Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 22 Sep 2022 21:58:04 +0200 Subject: [PATCH] up2k: folder-upload without drag/drop --- copyparty/web/browser.js | 13 +++++++++++++ copyparty/web/ui.css | 4 ++++ copyparty/web/up2k.js | 39 +++++++++++++++++++++++++++++++++++++-- copyparty/web/util.js | 19 +++++++++++++------ 4 files changed, 67 insertions(+), 8 deletions(-) diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index d3019695..31c244dc 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -25,6 +25,9 @@ var Ls = { "hz": "sample rate" }, + "m_ok": "OK", + "m_ng": "Cancel", + "ht_s": "second!s", "ht_m": "minute!s", "ht_h": "hour!s", @@ -101,6 +104,9 @@ var Ls = { "udt_srch": "Search", "udt_drop": "drop it here", + "u_nav_m": '
aight, what do you have?
Enter = Files (one or more)\nESC = One folder (including subfolders)', + "u_nav_b": 'FilesOne folder', + "cl_opts": "switches", "cl_themes": "theme", "cl_langs": "language", @@ -394,6 +400,9 @@ var Ls = { "hz": "lyd-oppløsning" }, + "m_ok": "OK", + "m_ng": "Avbryt", + "ht_s": "sekund!er", "ht_m": "minutt!er", "ht_h": "time!r", @@ -470,6 +479,9 @@ var Ls = { "udt_srch": "Søk", "udt_drop": "Slipp filene her", + "u_nav_m": '
hva har du?
Enter = Filer (én eller flere)\nESC = Én mappe (inkludert undermapper)', + "u_nav_b": 'FilerÉn mappe', + "cl_opts": "brytere", "cl_themes": "utseende", "cl_langs": "språk", @@ -747,6 +759,7 @@ if (Ls.eng && L != Ls.eng) { if (!L[k]) L[k] = Ls.eng[k]; } +modal.load(); // toolbar diff --git a/copyparty/web/ui.css b/copyparty/web/ui.css index b0c55194..0c6f8256 100644 --- a/copyparty/web/ui.css +++ b/copyparty/web/ui.css @@ -236,6 +236,10 @@ html.y #tth { max-height: 30em; overflow: auto; } +#modalc td { + text-align: unset; + padding: .2em; +} @media (min-width: 40em) { #modalc { min-width: 30em; diff --git a/copyparty/web/up2k.js b/copyparty/web/up2k.js index 152c4b54..eef5aa17 100644 --- a/copyparty/web/up2k.js +++ b/copyparty/web/up2k.js @@ -941,7 +941,16 @@ function up2k_init(subtle) { function nav() { start_actx(); - ebi('file' + fdom_ctr).click(); + + // too buggy on chrome <= 72 + var m = / Chrome\/([0-9]+)\./.exec(navigator.userAgent); + if (m && parseInt(m[1]) < 73) + return ebi('file' + fdom_ctr).click(); + + modal.confirm(L.u_nav_m, + function () { ebi('file' + fdom_ctr).click(); }, + function () { ebi('dir' + fdom_ctr).click(); }, + null, L.u_nav_b); } ebi('u2btn').onclick = nav; @@ -1034,6 +1043,28 @@ function up2k_init(subtle) { } ebi('drops').onclick = offdrag; // old ff + function gotdir(e) { + ev(e); + var good_files = [], + nil_files = [], + bad_files = []; + + for (var a = 0, aa = e.target.files.length; a < aa; a++) { + var fobj = e.target.files[a], + dst = good_files; + + try { + if (fobj.size < 1) + dst = nil_files; + } + catch (ex) { + dst = bad_files; + } + dst.push([fobj, fobj.webkitRelativePath]); + } + return read_dirs(null, [], [], good_files, nil_files, bad_files); + } + function gotfile(e) { ev(e); nenters = 0; @@ -1350,9 +1381,13 @@ function up2k_init(subtle) { function more_one_file() { fdom_ctr++; var elm = mknod('div'); - elm.innerHTML = ''.format(fdom_ctr); + elm.innerHTML = ( + '' + + '' + ).format(fdom_ctr); ebi('u2form').appendChild(elm); ebi('file' + fdom_ctr).onchange = gotfile; + ebi('dir' + fdom_ctr).onchange = gotdir; } more_one_file(); diff --git a/copyparty/web/util.js b/copyparty/web/util.js index 00595b61..e469da80 100644 --- a/copyparty/web/util.js +++ b/copyparty/web/util.js @@ -1248,9 +1248,16 @@ var modal = (function () { cb_up = null, cb_ok = null, cb_ng = null, - prim = 'OK', - sec = 'Cancel', + tok, tng, prim, sec, ok_cancel; + + r.load = function () { + tok = (window.L && L.m_ok) || 'OK'; + tng = (window.L && L.m_ng) || 'Cancel'; + prim = '' + tok + ''; + sec = '' + tng + ''; ok_cancel = WINDOWS ? prim + sec : sec + prim; + }; + r.load(); r.busy = false; @@ -1357,17 +1364,17 @@ var modal = (function () { r.show(html); } - r.confirm = function (html, cok, cng, fun) { + r.confirm = function (html, cok, cng, fun, btns) { q.push(function () { - _confirm(lf2br(html), cok, cng, fun); + _confirm(lf2br(html), cok, cng, fun, btns); }); next(); } - function _confirm(html, cok, cng, fun) { + function _confirm(html, cok, cng, fun, btns) { cb_ok = cok; cb_ng = cng === undefined ? cok : cng; cb_up = fun; - html += '
' + ok_cancel + '
'; + html += '
' + (btns || ok_cancel) + '
'; r.show(html); }