mirror of
https://github.com/shoelace-style/webawesome.git
synced 2026-01-12 12:09:26 +00:00
improve formdata event detection
This commit is contained in:
@@ -69,26 +69,8 @@ class FormDataPolyfill extends FormData {
|
||||
}
|
||||
}
|
||||
|
||||
function supportsFormDataEvent() {
|
||||
const form = document.createElement('form');
|
||||
let isSupported = false;
|
||||
|
||||
document.body.append(form);
|
||||
|
||||
form.addEventListener('submit', event => {
|
||||
new FormData(event.target as HTMLFormElement);
|
||||
event.preventDefault();
|
||||
});
|
||||
|
||||
form.addEventListener('formdata', () => (isSupported = true));
|
||||
form.dispatchEvent(new Event('submit', { cancelable: true }));
|
||||
form.remove();
|
||||
|
||||
return isSupported;
|
||||
}
|
||||
|
||||
function polyfillFormData() {
|
||||
if (!window.FormData || supportsFormDataEvent()) {
|
||||
if (!window.FormData || !('FormDataEvent' in window)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user