up2k: folder-upload without drag/drop

This commit is contained in:
ed 2022-09-22 21:58:04 +02:00
parent 8ee9de4291
commit 37c84021a2
4 changed files with 67 additions and 8 deletions

View file

@ -25,6 +25,9 @@ var Ls = {
"hz": "sample rate" "hz": "sample rate"
}, },
"m_ok": "OK",
"m_ng": "Cancel",
"ht_s": "second!s", "ht_s": "second!s",
"ht_m": "minute!s", "ht_m": "minute!s",
"ht_h": "hour!s", "ht_h": "hour!s",
@ -101,6 +104,9 @@ var Ls = {
"udt_srch": "Search", "udt_srch": "Search",
"udt_drop": "drop it here", "udt_drop": "drop it here",
"u_nav_m": '<h6>aight, what do you have?</h6><code>Enter</code> = Files (one or more)\n<code>ESC</code> = One folder (including subfolders)',
"u_nav_b": '<a href="#" id="modal-ok">Files</a><a href="#" id="modal-ng">One folder</a>',
"cl_opts": "switches", "cl_opts": "switches",
"cl_themes": "theme", "cl_themes": "theme",
"cl_langs": "language", "cl_langs": "language",
@ -394,6 +400,9 @@ var Ls = {
"hz": "lyd-oppløsning" "hz": "lyd-oppløsning"
}, },
"m_ok": "OK",
"m_ng": "Avbryt",
"ht_s": "sekund!er", "ht_s": "sekund!er",
"ht_m": "minutt!er", "ht_m": "minutt!er",
"ht_h": "time!r", "ht_h": "time!r",
@ -470,6 +479,9 @@ var Ls = {
"udt_srch": "Søk", "udt_srch": "Søk",
"udt_drop": "Slipp filene her", "udt_drop": "Slipp filene her",
"u_nav_m": '<h6>hva har du?</h6><code>Enter</code> = Filer (én eller flere)\n<code>ESC</code> = Én mappe (inkludert undermapper)',
"u_nav_b": '<a href="#" id="modal-ok">Filer</a><a href="#" id="modal-ng">Én mappe</a>',
"cl_opts": "brytere", "cl_opts": "brytere",
"cl_themes": "utseende", "cl_themes": "utseende",
"cl_langs": "språk", "cl_langs": "språk",
@ -747,6 +759,7 @@ if (Ls.eng && L != Ls.eng) {
if (!L[k]) if (!L[k])
L[k] = Ls.eng[k]; L[k] = Ls.eng[k];
} }
modal.load();
// toolbar // toolbar

View file

@ -236,6 +236,10 @@ html.y #tth {
max-height: 30em; max-height: 30em;
overflow: auto; overflow: auto;
} }
#modalc td {
text-align: unset;
padding: .2em;
}
@media (min-width: 40em) { @media (min-width: 40em) {
#modalc { #modalc {
min-width: 30em; min-width: 30em;

View file

@ -941,7 +941,16 @@ function up2k_init(subtle) {
function nav() { function nav() {
start_actx(); 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; ebi('u2btn').onclick = nav;
@ -1034,6 +1043,28 @@ function up2k_init(subtle) {
} }
ebi('drops').onclick = offdrag; // old ff 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) { function gotfile(e) {
ev(e); ev(e);
nenters = 0; nenters = 0;
@ -1350,9 +1381,13 @@ function up2k_init(subtle) {
function more_one_file() { function more_one_file() {
fdom_ctr++; fdom_ctr++;
var elm = mknod('div'); var elm = mknod('div');
elm.innerHTML = '<input id="file{0}" type="file" name="file{0}[]" multiple="multiple" tabindex="-1" />'.format(fdom_ctr); elm.innerHTML = (
'<input id="file{0}" type="file" name="file{0}[]" multiple="multiple" tabindex="-1" />' +
'<input id="dir{0}" type="file" name="dir{0}[]" multiple="multiple" tabindex="-1" webkitdirectory />'
).format(fdom_ctr);
ebi('u2form').appendChild(elm); ebi('u2form').appendChild(elm);
ebi('file' + fdom_ctr).onchange = gotfile; ebi('file' + fdom_ctr).onchange = gotfile;
ebi('dir' + fdom_ctr).onchange = gotdir;
} }
more_one_file(); more_one_file();

View file

@ -1248,9 +1248,16 @@ var modal = (function () {
cb_up = null, cb_up = null,
cb_ok = null, cb_ok = null,
cb_ng = null, cb_ng = null,
prim = '<a href="#" id="modal-ok">OK</a>', tok, tng, prim, sec, ok_cancel;
sec = '<a href="#" id="modal-ng">Cancel</a>',
r.load = function () {
tok = (window.L && L.m_ok) || 'OK';
tng = (window.L && L.m_ng) || 'Cancel';
prim = '<a href="#" id="modal-ok">' + tok + '</a>';
sec = '<a href="#" id="modal-ng">' + tng + '</a>';
ok_cancel = WINDOWS ? prim + sec : sec + prim; ok_cancel = WINDOWS ? prim + sec : sec + prim;
};
r.load();
r.busy = false; r.busy = false;
@ -1357,17 +1364,17 @@ var modal = (function () {
r.show(html); r.show(html);
} }
r.confirm = function (html, cok, cng, fun) { r.confirm = function (html, cok, cng, fun, btns) {
q.push(function () { q.push(function () {
_confirm(lf2br(html), cok, cng, fun); _confirm(lf2br(html), cok, cng, fun, btns);
}); });
next(); next();
} }
function _confirm(html, cok, cng, fun) { function _confirm(html, cok, cng, fun, btns) {
cb_ok = cok; cb_ok = cok;
cb_ng = cng === undefined ? cok : cng; cb_ng = cng === undefined ? cok : cng;
cb_up = fun; cb_up = fun;
html += '<div id="modalb">' + ok_cancel + '</div>'; html += '<div id="modalb">' + (btns || ok_cancel) + '</div>';
r.show(html); r.show(html);
} }