code.gitea.io/gitea@v1.21.7/web_src/js/modules/fomantic/modal.js (about) 1 import $ from 'jquery'; 2 3 const fomanticModalFn = $.fn.modal; 4 5 // use our own `$.fn.modal` to patch Fomantic's modal module 6 export function initAriaModalPatch() { 7 if ($.fn.modal === ariaModalFn) throw new Error('initAriaModalPatch could only be called once'); 8 $.fn.modal = ariaModalFn; 9 ariaModalFn.settings = fomanticModalFn.settings; 10 } 11 12 // the patched `$.fn.modal` modal function 13 // * it does the one-time attaching on the first call 14 function ariaModalFn(...args) { 15 const ret = fomanticModalFn.apply(this, args); 16 if (args[0] === 'show' || args[0]?.autoShow) { 17 for (const el of this) { 18 // If there is a form in the modal, there might be a "cancel" button before "ok" button (all buttons are "type=submit" by default). 19 // In such case, the "Enter" key will trigger the "cancel" button instead of "ok" button, then the dialog will be closed. 20 // It breaks the user experience - the "Enter" key should confirm the dialog and submit the form. 21 // So, all "cancel" buttons without "[type]" must be marked as "type=button". 22 $(el).find('form button.cancel:not([type])').attr('type', 'button'); 23 } 24 } 25 return ret; 26 }