fix modal focus even more (now works on phones too)

This commit is contained in:
ed 2023-12-01 21:02:05 +00:00
parent 2eafaa88a2
commit 1be85bdb26

View file

@ -1482,6 +1482,7 @@ var modal = (function () {
a.onclick = ng; a.onclick = ng;
a = ebi('modal-ok'); a = ebi('modal-ok');
a.addEventListener('blur', onblur);
a.onclick = ok; a.onclick = ok;
var inp = ebi('modali'); var inp = ebi('modali');
@ -1500,6 +1501,10 @@ var modal = (function () {
r.hide = function () { r.hide = function () {
timer.rm(onfocus); timer.rm(onfocus);
try {
ebi('modal-ok').removeEventListener('blur', onblur);
}
catch (ex) { }
document.removeEventListener('selectionchange', onselch); document.removeEventListener('selectionchange', onselch);
document.removeEventListener('focus', onfocus); document.removeEventListener('focus', onfocus);
document.removeEventListener('keydown', onkey); document.removeEventListener('keydown', onkey);
@ -1522,24 +1527,35 @@ var modal = (function () {
cb_ng(null); cb_ng(null);
} }
var onselch = function (e) { var onselch = function () {
r.nofocus = 30; try {
if (window.getSelection() + '')
r.nofocus = 10;
}
catch (ex) { }
};
var onblur = function () {
r.nofocus = 3;
}; };
var onfocus = function (e) { var onfocus = function (e) {
if (MOBILE)
return;
var ctr = ebi('modalc'); var ctr = ebi('modalc');
if (!ctr || !ctr.contains || !document.activeElement || ctr.contains(document.activeElement)) if (!ctr || !ctr.contains || !document.activeElement || ctr.contains(document.activeElement))
return; return;
setTimeout(function () { setTimeout(function () {
if (--r.nofocus > 0) if (--r.nofocus >= 0)
return; return;
if (ctr = ebi('modal-ok')) if (ctr = ebi('modal-ok'))
ctr.focus(); ctr.focus();
}, 20); }, 20);
ev(e); ev(e);
} };
var onkey = function (e) { var onkey = function (e) {
var k = e.code, var k = e.code,