From 1be85bdb26a82d0b5ce99c4ea416bc29d2edbe1b Mon Sep 17 00:00:00 2001 From: ed Date: Fri, 1 Dec 2023 21:02:05 +0000 Subject: [PATCH] fix modal focus even more (now works on phones too) --- copyparty/web/util.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/copyparty/web/util.js b/copyparty/web/util.js index acd19177..875fc218 100644 --- a/copyparty/web/util.js +++ b/copyparty/web/util.js @@ -1482,6 +1482,7 @@ var modal = (function () { a.onclick = ng; a = ebi('modal-ok'); + a.addEventListener('blur', onblur); a.onclick = ok; var inp = ebi('modali'); @@ -1500,6 +1501,10 @@ var modal = (function () { r.hide = function () { timer.rm(onfocus); + try { + ebi('modal-ok').removeEventListener('blur', onblur); + } + catch (ex) { } document.removeEventListener('selectionchange', onselch); document.removeEventListener('focus', onfocus); document.removeEventListener('keydown', onkey); @@ -1522,24 +1527,35 @@ var modal = (function () { cb_ng(null); } - var onselch = function (e) { - r.nofocus = 30; + var onselch = function () { + try { + if (window.getSelection() + '') + r.nofocus = 10; + } + catch (ex) { } + }; + + var onblur = function () { + r.nofocus = 3; }; var onfocus = function (e) { + if (MOBILE) + return; + var ctr = ebi('modalc'); if (!ctr || !ctr.contains || !document.activeElement || ctr.contains(document.activeElement)) return; setTimeout(function () { - if (--r.nofocus > 0) + if (--r.nofocus >= 0) return; if (ctr = ebi('modal-ok')) ctr.focus(); }, 20); ev(e); - } + }; var onkey = function (e) { var k = e.code,