@@ -195,19 +195,23 @@ export function loadElem(el, src) {
195
195
} ) ;
196
196
}
197
197
198
- // some browsers like PaleMoon don't have "SubmitEvent" support, so we need to polyfill it (a tricky method): use the last clicked button as submitter
198
+ // some browsers like PaleMoon don't have "SubmitEvent" support, so polyfill it by a tricky method: use the last clicked button as submitter
199
+ // it can't use other transparent polyfill patches because PaleMoon also doesn't support "addEventListener(capture)"
199
200
const needSubmitEventPolyfill = typeof SubmitEvent === 'undefined' ;
200
201
201
202
export function submitEventSubmitter ( e ) {
202
203
return needSubmitEventPolyfill ? ( e . target . _submitter || null ) : e . submitter ;
203
204
}
204
205
206
+ function submitEventPolyfillListener ( e ) {
207
+ const form = e . target . closest ( 'form' ) ;
208
+ if ( ! form ) return ;
209
+ form . _submitter = e . target . closest ( 'button:not([type]), button[type="submit"], input[type="submit"]' ) ;
210
+ }
211
+
205
212
export function initSubmitEventPolyfill ( ) {
206
213
if ( ! needSubmitEventPolyfill ) return ;
207
214
console . warn ( `This browser doesn't have "SubmitEvent" support, use a tricky method to polyfill` ) ;
208
- document . addEventListener ( 'click' , ( e ) => {
209
- if ( ! e . target . form ) return ;
210
- const isSubmitButton = ( ( e . target . nodeName === 'INPUT' || e . target . nodeName === 'BUTTON' ) && e . target . type === 'submit' ) ;
211
- e . target . form . _submitter = isSubmitButton ? e . target : null ;
212
- } ) ;
215
+ document . body . addEventListener ( 'click' , submitEventPolyfillListener ) ;
216
+ document . body . addEventListener ( 'focus' , submitEventPolyfillListener ) ;
213
217
}
0 commit comments