From e4ae5f74e6c3508b6acfdc384f3f83254484a0fb Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 20 Nov 2021 01:47:16 +0100 Subject: [PATCH] add tooltip indicator --- copyparty/web/browser.js | 2 -- copyparty/web/ui.css | 16 ++++++++++++++ copyparty/web/util.js | 48 +++++++++++++++++++++++++++++++--------- 3 files changed, 54 insertions(+), 12 deletions(-) diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index 9369e7d3..3ee89b51 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -1,7 +1,5 @@ "use strict"; -window.onerror = vis_exh; - function dbg(msg) { ebi('path').innerHTML = msg; } diff --git a/copyparty/web/ui.css b/copyparty/web/ui.css index a0da1e34..db38771a 100644 --- a/copyparty/web/ui.css +++ b/copyparty/web/ui.css @@ -116,6 +116,18 @@ html { #toast.err #toastc { background: #d06; } +#tth { + color: #fff; + background: #111; + font-size: .9em; + padding: 0 .3em; + border-radius: 1em; + position: absolute; + display: none; +} +#tth.act { + display: block; +} #tt.b { padding: 0 2em; border-radius: .5em; @@ -159,6 +171,10 @@ html.light #tt code { html.light #tt em { color: #d38; } +html.light #tth { + color: #000; + background: #fff; +} #modal { position: fixed; overflow: auto; diff --git a/copyparty/web/util.js b/copyparty/web/util.js index 0e14dfda..7d2a8069 100644 --- a/copyparty/web/util.js +++ b/copyparty/web/util.js @@ -180,6 +180,7 @@ function ignex(all) { if (!all) window.onerror = vis_exh; } +window.onerror = vis_exh; function noop() { } @@ -791,14 +792,18 @@ var timer = (function () { var tt = (function () { var r = { "tt": mknod("div"), + "th": mknod("div"), "en": true, "el": null, "skip": false, "lvis": 0 }; + r.th.innerHTML = '?'; r.tt.setAttribute('id', 'tt'); + r.th.setAttribute('id', 'tth'); document.body.appendChild(r.tt); + document.body.appendChild(r.th); var prev = null; r.cshow = function () { @@ -809,12 +814,32 @@ var tt = (function () { }; var tev; - r.dshow = function () { + r.dshow = function (e) { clearTimeout(tev); + if (!r.getmsg(this)) + return; + if (Date.now() - r.lvis < 400) return r.show.bind(this)(); - tev = setTimeout(r.show.bind(this), 700); + tev = setTimeout(r.show.bind(this), 800); + if (is_touch) + return; + + this.addEventListener('mousemove', r.move); + clmod(r.th, 'act', 1); + r.move(e); + }; + + r.getmsg = function (el) { + if (QS('body.bbox-open')) + return; + + var cfg = sread('tooltips'); + if (cfg !== null && cfg != '1') + return; + + return el.getAttribute('tt'); }; r.show = function () { @@ -823,14 +848,7 @@ var tt = (function () { r.skip = false; return; } - if (QS('body.bbox-open')) - return; - - var cfg = sread('tooltips'); - if (cfg !== null && cfg != '1') - return; - - var msg = this.getAttribute('tt'); + var msg = r.getmsg(this); if (!msg) return; @@ -844,6 +862,7 @@ var tt = (function () { if (dir.indexOf('u') + 1) top = false; if (dir.indexOf('d') + 1) top = true; + clmod(r.th, 'act'); clmod(r.tt, 'b', big); r.tt.style.left = '0'; r.tt.style.top = '0'; @@ -873,11 +892,20 @@ var tt = (function () { window.removeEventListener('scroll', r.hide); clmod(r.tt, 'b'); + clmod(r.th, 'act'); if (clmod(r.tt, 'show')) r.lvis = Date.now(); if (r.el) r.el.removeEventListener('mouseleave', r.hide); + + if (e && e.target) + e.target.removeEventListener('mousemove', r.move); + }; + + r.move = function (e) { + r.th.style.left = (e.pageX + 12) + 'px'; + r.th.style.top = (e.pageY + 12) + 'px'; }; if (IPHONE) {