support upload by dragdrop from other browser windows,

hello from LO484 https://ocv.me/stuff/aircode.jpg
This commit is contained in:
ed 2023-07-28 21:43:40 +02:00
parent ca0cd04085
commit f9d5bb3b29
3 changed files with 42 additions and 4 deletions

View file

@ -403,6 +403,7 @@ var Ls = {
"u_https3": "for better performance", "u_https3": "for better performance",
"u_ancient": 'your browser is impressively ancient -- maybe you should <a href="#" onclick="goto(\'bup\')">use bup instead</a>', "u_ancient": 'your browser is impressively ancient -- maybe you should <a href="#" onclick="goto(\'bup\')">use bup instead</a>',
"u_nowork": "need firefox 53+ or chrome 57+ or iOS 11+", "u_nowork": "need firefox 53+ or chrome 57+ or iOS 11+",
"u_uri": "to dragdrop images from other browser windows,\nplease drop it onto the big upload button",
"u_enpot": 'switch to <a href="#">potato UI</a> (may improve upload speed)', "u_enpot": 'switch to <a href="#">potato UI</a> (may improve upload speed)',
"u_depot": 'switch to <a href="#">fancy UI</a> (may reduce upload speed)', "u_depot": 'switch to <a href="#">fancy UI</a> (may reduce upload speed)',
"u_gotpot": 'switching to the potato UI for improved upload speed,\n\nfeel free to disagree and switch back!', "u_gotpot": 'switching to the potato UI for improved upload speed,\n\nfeel free to disagree and switch back!',
@ -865,6 +866,7 @@ var Ls = {
"u_https3": "for høyere hastighet", "u_https3": "for høyere hastighet",
"u_ancient": 'nettleseren din er prehistorisk -- mulig du burde <a href="#" onclick="goto(\'bup\')">bruke bup istedenfor</a>', "u_ancient": 'nettleseren din er prehistorisk -- mulig du burde <a href="#" onclick="goto(\'bup\')">bruke bup istedenfor</a>',
"u_nowork": "krever firefox 53+, chrome 57+, eller iOS 11+", "u_nowork": "krever firefox 53+, chrome 57+, eller iOS 11+",
"u_uri": "for å laste opp bilder ifra andre nettleservinduer,\nslipp bildet rett på den store last-opp-knappen",
"u_enpot": 'bytt til <a href="#">enkelt UI</a> (gir sannsynlig raskere opplastning)', "u_enpot": 'bytt til <a href="#">enkelt UI</a> (gir sannsynlig raskere opplastning)',
"u_depot": 'bytt til <a href="#">snæsent UI</a> (gir sannsynlig tregere opplastning)', "u_depot": 'bytt til <a href="#">snæsent UI</a> (gir sannsynlig tregere opplastning)',
"u_gotpot": 'byttet til et enklere UI for å laste opp raskere,\n\ndu kan gjerne bytte tilbake altså!', "u_gotpot": 'byttet til et enklere UI for å laste opp raskere,\n\ndu kan gjerne bytte tilbake altså!',

View file

@ -998,13 +998,26 @@ function up2k_init(subtle) {
return onover.bind(this)(e); return onover.bind(this)(e);
} }
function onover(e) { function onover(e) {
return onovercmn(this, e, false);
}
function onoverbtn(e) {
return onovercmn(this, e, true);
}
function onovercmn(self, e, btn) {
try { try {
var ok = false, dt = e.dataTransfer.types; var ok = false, dt = e.dataTransfer.types;
for (var a = 0; a < dt.length; a++) for (var a = 0; a < dt.length; a++)
if (dt[a] == 'Files') if (dt[a] == 'Files')
ok = true; ok = true;
else if (dt[a] == 'text/uri-list') else if (dt[a] == 'text/uri-list') {
return true; if (btn) {
ok = true;
if (toast.txt == L.u_uri)
toast.hide();
}
else
return toast.inf(10, L.u_uri) || true;
}
if (!ok) if (!ok)
return true; return true;
@ -1020,8 +1033,11 @@ function up2k_init(subtle) {
document.body.ondragenter = document.body.ondragleave = document.body.ondragover = null; document.body.ondragenter = document.body.ondragleave = document.body.ondragover = null;
return modal.alert('your browser does not support drag-and-drop uploading'); return modal.alert('your browser does not support drag-and-drop uploading');
} }
if (btn)
return;
clmod(ebi('drops'), 'vis', 1); clmod(ebi('drops'), 'vis', 1);
var v = this.getAttribute('v'); var v = self.getAttribute('v');
if (v) if (v)
clmod(ebi(v), 'hl', 1); clmod(ebi(v), 'hl', 1);
} }
@ -1045,6 +1061,8 @@ function up2k_init(subtle) {
document.body.ondragleave = offdrag; document.body.ondragleave = offdrag;
document.body.ondragover = onover; document.body.ondragover = onover;
document.body.ondrop = gotfile; document.body.ondrop = gotfile;
ebi('u2btn').ondrop = gotfile;
ebi('u2btn').ondragover = onoverbtn;
var drops = [ebi('up_dz'), ebi('srch_dz')]; var drops = [ebi('up_dz'), ebi('srch_dz')];
for (var a = 0; a < 2; a++) { for (var a = 0; a < 2; a++) {
@ -1132,7 +1150,7 @@ function up2k_init(subtle) {
dst = good_files; dst = good_files;
if (is_itemlist) { if (is_itemlist) {
if (fobj.kind !== 'file') if (fobj.kind !== 'file' && fobj.type !== 'text/uri-list')
continue; continue;
try { try {
@ -1144,6 +1162,8 @@ function up2k_init(subtle) {
} }
catch (ex) { } catch (ex) { }
fobj = fobj.getAsFile(); fobj = fobj.getAsFile();
if (!fobj)
continue;
} }
try { try {
if (fobj.size < 1) if (fobj.size < 1)

View file

@ -1274,6 +1274,9 @@ var toast = (function () {
r.visible = false; r.visible = false;
r.txt = null; r.txt = null;
r.tag = obj; // filler value (null is scary) r.tag = obj; // filler value (null is scary)
r.p_txt = '';
r.p_sec = 0;
r.p_t = 0;
function scrollchk() { function scrollchk() {
if (scrolling) if (scrolling)
@ -1306,10 +1309,23 @@ var toast = (function () {
}; };
r.show = function (cl, sec, txt, tag) { r.show = function (cl, sec, txt, tag) {
var same = r.visible && txt == r.p_txt && r.p_sec == sec,
delta = Date.now() - r.p_t;
if (same && delta < 100)
return;
r.p_txt = txt;
r.p_sec = sec;
r.p_t = Date.now();
clearTimeout(te); clearTimeout(te);
if (sec) if (sec)
te = setTimeout(r.hide, sec * 1000); te = setTimeout(r.hide, sec * 1000);
if (same && delta < 1000)
return;
if (txt.indexOf('<body>') + 1) if (txt.indexOf('<body>') + 1)
txt = txt.slice(0, txt.indexOf('<')) + ' [...]'; txt = txt.slice(0, txt.indexOf('<')) + ' [...]';