From d5892341b667788fb5b16060f219b4501ebc0c7f Mon Sep 17 00:00:00 2001 From: ed Date: Wed, 1 Sep 2021 22:34:48 +0200 Subject: [PATCH] prevent vertical toast overflow --- copyparty/web/ui.css | 11 ++++++++++- copyparty/web/util.js | 26 +++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/copyparty/web/ui.css b/copyparty/web/ui.css index 0e877bbc..7ebe02e3 100644 --- a/copyparty/web/ui.css +++ b/copyparty/web/ui.css @@ -52,7 +52,7 @@ html { opacity: 0; padding: .3em 0; margin: -.3em 0 0 0; - line-height: 1.5em; + line-height: 1.3em; color: #000; border: none; outline: none; @@ -60,6 +60,15 @@ html { border-radius: .5em 0 0 .5em; transition: left .3s, width .3s, padding .3s, opacity .3s; } +#toastb { + max-height: 70vh; + overflow-y: auto; +} +#toast.scroll #toastb { + overflow-y: scroll; + margin-right: -1.2em; + padding-right: .7em; +} #toast pre { margin: 0; } diff --git a/copyparty/web/util.js b/copyparty/web/util.js index f8a403a9..18f4539e 100644 --- a/copyparty/web/util.js +++ b/copyparty/web/util.js @@ -744,6 +744,7 @@ function lf2br(txt) { var toast = (function () { var r = {}, te = null, + scrolling = false, obj = mknod('div'); obj.setAttribute('id', 'toast'); @@ -751,8 +752,30 @@ var toast = (function () { r.visible = false; r.txt = null; + function scrollchk() { + if (scrolling) + return; + + var tb = ebi('toastb'), + vis = tb.offsetHeight, + all = tb.scrollHeight; + + if (8 + vis >= all) + return; + + clmod(obj, 'scroll', 1); + scrolling = true; + } + + function unscroll() { + timer.rm(scrollchk); + clmod(obj, 'scroll'); + scrolling = false; + } + r.hide = function (e) { ev(e); + unscroll(); clearTimeout(te); clmod(obj, 'vis'); r.visible = false; @@ -763,11 +786,12 @@ var toast = (function () { if (ms) te = setTimeout(r.hide, ms * 1000); - obj.innerHTML = 'x' + lf2br(txt); + obj.innerHTML = 'x
' + lf2br(txt) + '
'; obj.className = cl; ms += obj.offsetWidth; obj.className += ' vis'; ebi('toastc').onclick = r.hide; + timer.add(scrollchk); r.visible = true; r.txt = txt; };