allow free text selection in modals by deferring focus

This commit is contained in:
ed 2023-11-30 22:41:16 +00:00
parent 4a98b73915
commit 4f8a1f5f6a

View file

@ -1466,6 +1466,7 @@ var modal = (function () {
r.load(); r.load();
r.busy = false; r.busy = false;
r.nofocus = 0;
r.show = function (html) { r.show = function (html) {
o = mknod('div', 'modal'); o = mknod('div', 'modal');
@ -1489,6 +1490,7 @@ var modal = (function () {
}, 0); }, 0);
document.addEventListener('focus', onfocus); document.addEventListener('focus', onfocus);
document.addEventListener('selectionchange', onselch);
timer.add(onfocus); timer.add(onfocus);
if (cb_up) if (cb_up)
setTimeout(cb_up, 1); setTimeout(cb_up, 1);
@ -1496,6 +1498,7 @@ var modal = (function () {
r.hide = function () { r.hide = function () {
timer.rm(onfocus); timer.rm(onfocus);
document.removeEventListener('selectionchange', onselch);
document.removeEventListener('focus', onfocus); document.removeEventListener('focus', onfocus);
document.removeEventListener('keydown', onkey); document.removeEventListener('keydown', onkey);
o.parentNode.removeChild(o); o.parentNode.removeChild(o);
@ -1517,12 +1520,19 @@ var modal = (function () {
cb_ng(null); cb_ng(null);
} }
var onselch = function (e) {
r.nofocus = 30;
};
var onfocus = function (e) { var onfocus = function (e) {
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)
return;
if (ctr = ebi('modal-ok')) if (ctr = ebi('modal-ok'))
ctr.focus(); ctr.focus();
}, 20); }, 20);