diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-12-15 07:26:36 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-15 07:26:36 +0800 |
commit | 6632d1497c9fc644c696e9a1239cd62baa5dc29e (patch) | |
tree | 29f05ede498b3e2283eceee3d864f6e98e02aacc /web_src/js/utils/dom.js | |
parent | 8c91e315406730937322fcbeea5115c6ac3f82c2 (diff) | |
download | gitea-6632d1497c9fc644c696e9a1239cd62baa5dc29e.tar.gz gitea-6632d1497c9fc644c696e9a1239cd62baa5dc29e.zip |
Polyfill SubmitEvent for PaleMoon (#28441)
Diffstat (limited to 'web_src/js/utils/dom.js')
-rw-r--r-- | web_src/js/utils/dom.js | 21 |
1 files changed, 21 insertions, 0 deletions
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); +} |