Polyfill SubmitEvent for PaleMoon (#28441)
This commit is contained in:
parent
8c91e31540
commit
6632d1497c
6 changed files with 31 additions and 7 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue