@@ -195,19 +195,23 @@ export function loadElem(el, src) {
195195 } ) ;
196196}
197197
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)"
199200const needSubmitEventPolyfill = typeof SubmitEvent === 'undefined' ;
200201
201202export function submitEventSubmitter ( e ) {
202203 return needSubmitEventPolyfill ? ( e . target . _submitter || null ) : e . submitter ;
203204}
204205
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="button"], input[type="submit"]' ) ;
210+ }
211+
205212export function initSubmitEventPolyfill ( ) {
206213 if ( ! needSubmitEventPolyfill ) return ;
207214 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 ) ;
213217}
0 commit comments