From d3db6d296f9e04fbc912124dca9be43908305b1a Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 1 Feb 2024 21:41:48 +0000 Subject: [PATCH] disable mkdir and new-doc buttons if no name is provided also fixes toast.hide() unintentionally stopping events from bubbling --- copyparty/web/browser.js | 36 +++++++++++++++++++++++++++++++++++- copyparty/web/util.js | 7 ++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index 9d045717..9301f1c0 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -332,6 +332,8 @@ var Ls = { "fp_confirm": "move these {0} items here?", "fp_etab": 'failed to read clipboard from other browser tab', + "mk_noname": "type a name into the text field on the left before you do that :p", + "tv_load": "Loading text document:\n\n{0}\n\n{1}% ({2} of {3} MiB loaded)", "tv_xe1": "could not load textfile:\n\nerror ", "tv_xe2": "404, file not found", @@ -821,6 +823,8 @@ var Ls = { "fp_confirm": "flytt disse {0} filene hit?", "fp_etab": 'kunne ikke lese listen med filer ifra den andre nettleserfanen', + "mk_noname": "skriv inn et navn i tekstboksen til venstre først :p", + "tv_load": "Laster inn tekstfil:\n\n{0}\n\n{1}% ({2} av {3} MiB lastet ned)", "tv_xe1": "kunne ikke laste tekstfil:\n\nfeil ", "tv_xe2": "404, Fil ikke funnet", @@ -7267,6 +7271,28 @@ var msel = (function () { })(); +(function () { + if (!window.FormData) + return; + + var form = QS('#op_new_md>form'), + tb = QS('#op_new_md input[name="name"]'); + + form.onsubmit = function (e) { + if (tb.value) { + if (toast.tag == L.mk_noname) + toast.hide(); + + return true; + } + + ev(e); + toast.err(10, L.mk_noname, L.mk_noname); + return false; + }; +})(); + + (function () { if (!window.FormData) return; @@ -7280,8 +7306,16 @@ var msel = (function () { form.onsubmit = function (e) { ev(e); - clmod(sf, 'vis', 1); var dn = tb.value; + if (!dn) { + toast.err(10, L.mk_noname, L.mk_noname); + return false; + } + + if (toast.tag == L.mk_noname || toast.tag == L.fd_xe1) + toast.hide(); + + clmod(sf, 'vis', 1); sf.textContent = 'creating "' + dn + '"...'; var fd = new FormData(); diff --git a/copyparty/web/util.js b/copyparty/web/util.js index dc548cab..6ea920b2 100644 --- a/copyparty/web/util.js +++ b/copyparty/web/util.js @@ -1455,7 +1455,9 @@ var toast = (function () { } r.hide = function (e) { - ev(e); + if (this === ebi('toastc')) + ev(e); + unscroll(); clearTimeout(te); clmod(obj, 'vis'); @@ -1985,6 +1987,9 @@ function xhrchk(xhr, prefix, e404, lvl, tag) { if (xhr.status < 400 && xhr.status >= 200) return true; + if (tag === undefined) + tag = prefix; + var errtxt = (xhr.response && xhr.response.err) || xhr.responseText, fun = toast[lvl || 'err'], is_cf = /[Cc]loud[f]lare|>Just a mo[m]ent|#cf-b[u]bbles|Chec[k]ing your br[o]wser|\/chall[e]nge-platform|"chall[e]nge-error|nable Ja[v]aScript and cook/.test(errtxt);