From 6632d1497c9fc644c696e9a1239cd62baa5dc29e Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Fri, 15 Dec 2023 07:26:36 +0800 Subject: Polyfill SubmitEvent for PaleMoon (#28441) --- web_src/js/utils/dom.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'web_src/js/utils/dom.js') diff --git a/web_src/js/utils/dom.js b/web_src/js/utils/dom.js index 403933883a..64a6a5affc 100644 --- a/web_src/js/utils/dom.js +++ b/web_src/js/utils/dom.js @@ -194,3 +194,24 @@ export function loadElem(el, src) { el.src = src; }); } + +// some browsers like PaleMoon don't have "SubmitEvent" support, so polyfill it by a tricky method: use the last clicked button as submitter +// it can't use other transparent polyfill patches because PaleMoon also doesn't support "addEventListener(capture)" +const needSubmitEventPolyfill = typeof SubmitEvent === 'undefined'; + +export function submitEventSubmitter(e) { + return needSubmitEventPolyfill ? (e.target._submitter || null) : e.submitter; +} + +function submitEventPolyfillListener(e) { + const form = e.target.closest('form'); + if (!form) return; + form._submitter = e.target.closest('button:not([type]), button[type="submit"], input[type="submit"]'); +} + +export function initSubmitEventPolyfill() { + if (!needSubmitEventPolyfill) return; + console.warn(`This browser doesn't have "SubmitEvent" support, use a tricky method to polyfill`); + document.body.addEventListener('click', submitEventPolyfillListener); + document.body.addEventListener('focus', submitEventPolyfillListener); +} -- cgit v1.2.3