/* ============================================================
MEDIQ V52 - FIX "FIELD JUMPS AWAY AFTER SELECTION"
WHERE: paste RIGHT BELOW the V51 block
(after the last line of mediq-v51-patch.js,
and still BEFORE the INITIAL / bindTree(); part)
Cause found from the console output:
- after selection Select2 focuses a hidden input that sits at
left:-10000px; the browser scrolls the form content sideways
to reach it, so the row is pushed out of view (it is still
"visible" in the DOM, just scrolled away)
- the closed Select2 drop is forced visible by an old CSS rule
============================================================ */
(function mqV52InjectCss() {
if (document.getElementById('mq-v52-css')) return;
var st = document.createElement('style');
st.id = 'mq-v52-css';
st.textContent =
/* 1) hidden Select2 helper inputs stay INSIDE their cell (no -10000px) */
'body.mq-flow-open-v50 .mq-flow-active-panel-v50 td{position:relative !important;}' +
'body.mq-flow-open-v50 .mq-flow-active-panel-v50 td input.select2-offscreen,' +
'body.mq-flow-open-v50 .mq-flow-active-panel-v50 td select.select2-offscreen,' +
'body.mq-flow-open-v50 .mq-flow-active-panel-v50 td input.select2-focusser{' +
'position:absolute !important;left:0 !important;top:0 !important;right:auto !important;' +
'width:1px !important;height:1px !important;min-width:1px !important;max-width:1px !important;' +
'min-height:1px !important;margin:0 !important;padding:0 !important;border:0 !important;' +
'opacity:0 !important;pointer-events:none !important;}' +
/* 2) a closed Select2 drop must stay closed */
'html body.mq-flow-open-v50 .select2-drop.select2-drop-active.select2-display-none,' +
'html body.mq-flow-open-v50 .aui-select2-drop.select2-drop-active.select2-display-none{' +
'display:none !important;visibility:hidden !important;opacity:0 !important;' +
'pointer-events:none !important;}';
document.head.appendChild(st);
})();
/* 3) If anything still scrolls the form sideways, put it back immediately */
function mqV52ResetScroll() {
var p = document.querySelector('.mq-flow-active-panel-v50');
if (!p) return;
var list = [p].concat(Array.prototype.slice.call(p.querySelectorAll(
'.confiFormsFormContent, form, .table-wrap, table, tbody, tr, td'
)));
for (var i = 0; i < list.length; i++) {
try {
if (list[i].scrollLeft) list[i].scrollLeft = 0;
} catch (ignore) {}
}
}
document.addEventListener('scroll', function (e) {
if (!mqFlowStateV50.open) return;
var t = e.target;
if (!t || t === document || !t.closest) return;
if (!t.closest('.mq-flow-active-panel-v50')) return;
if (t.scrollLeft) t.scrollLeft = 0;
}, true);
document.addEventListener('focusin', function () {
if (!mqFlowStateV50.open) return;
window.setTimeout(mqV52ResetScroll, 0);
window.setTimeout(mqV52ResetScroll, 120);
}, true);
try {
var mqV52Obs = new MutationObserver(function () {
if (!mqFlowStateV50.open) return;
window.setTimeout(mqV52ResetScroll, 80);
});
mqV52Obs.observe(document.body, { childList: true, subtree: true });
} catch (ignoreV52) {}