Remove SubmitEvent polyfill (#37276)
Remove this obsolete polyfill as per https://github.com/go-gitea/gitea/pull/37270#issuecomment-4273399551. Co-authored-by: Claude (Opus 4.7) <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import {GET, request} from '../modules/fetch.ts';
|
import {GET, request} from '../modules/fetch.ts';
|
||||||
import {hideToastsAll, showErrorToast} from '../modules/toast.ts';
|
import {hideToastsAll, showErrorToast} from '../modules/toast.ts';
|
||||||
import {addDelegatedEventListener, createElementFromHTML, submitEventSubmitter} from '../utils/dom.ts';
|
import {addDelegatedEventListener, createElementFromHTML} from '../utils/dom.ts';
|
||||||
import {confirmModal, createConfirmModal} from './comp/ConfirmModal.ts';
|
import {confirmModal, createConfirmModal} from './comp/ConfirmModal.ts';
|
||||||
import {ignoreAreYouSure} from '../vendor/jquery.are-you-sure.ts';
|
import {ignoreAreYouSure} from '../vendor/jquery.are-you-sure.ts';
|
||||||
import {registerGlobalSelectorFunc} from '../modules/observer.ts';
|
import {registerGlobalSelectorFunc} from '../modules/observer.ts';
|
||||||
@@ -146,7 +146,7 @@ async function performActionRequest(el: HTMLElement, opt: FetchActionOpts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SubmitFormFetchActionOpts = {
|
type SubmitFormFetchActionOpts = {
|
||||||
formSubmitter?: HTMLElement;
|
formSubmitter?: HTMLElement | null;
|
||||||
formData?: FormData;
|
formData?: FormData;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -396,10 +396,10 @@ export function initGlobalFetchAction() {
|
|||||||
// * it has "-header" and "-content" variants to set the header and content of the "confirm modal"
|
// * it has "-header" and "-content" variants to set the header and content of the "confirm modal"
|
||||||
// * it can refer an existing modal element by "#the-modal-id"
|
// * it can refer an existing modal element by "#the-modal-id"
|
||||||
|
|
||||||
addDelegatedEventListener(document, 'submit', '.form-fetch-action', async (el: HTMLFormElement, e) => {
|
addDelegatedEventListener<HTMLFormElement, SubmitEvent>(document, 'submit', '.form-fetch-action', async (el, e) => {
|
||||||
// "fetch-action" will use the form's data to send the request
|
// "fetch-action" will use the form's data to send the request
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
await submitFormFetchAction(el, {formSubmitter: submitEventSubmitter(e)});
|
await submitFormFetchAction(el, {formSubmitter: e.submitter});
|
||||||
});
|
});
|
||||||
|
|
||||||
addDelegatedEventListener(document, 'click', '.link-action', async (el, e) => {
|
addDelegatedEventListener(document, 'click', '.link-action', async (el, e) => {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {validateTextareaNonEmpty} from './comp/ComboMarkdownEditor.ts';
|
|||||||
import {initViewedCheckboxListenerFor, initExpandAndCollapseFilesButton} from './pull-view-file.ts';
|
import {initViewedCheckboxListenerFor, initExpandAndCollapseFilesButton} from './pull-view-file.ts';
|
||||||
import {initImageDiff} from './imagediff.ts';
|
import {initImageDiff} from './imagediff.ts';
|
||||||
import {showErrorToast} from '../modules/toast.ts';
|
import {showErrorToast} from '../modules/toast.ts';
|
||||||
import {submitEventSubmitter, queryElemSiblings, hideElem, showElem, animateOnce, addDelegatedEventListener, createElementFromHTML, queryElems} from '../utils/dom.ts';
|
import {queryElemSiblings, hideElem, showElem, animateOnce, addDelegatedEventListener, createElementFromHTML, queryElems} from '../utils/dom.ts';
|
||||||
import {POST, GET} from '../modules/fetch.ts';
|
import {POST, GET} from '../modules/fetch.ts';
|
||||||
import {createTippy} from '../modules/tippy.ts';
|
import {createTippy} from '../modules/tippy.ts';
|
||||||
import {invertFileFolding} from './file-fold.ts';
|
import {invertFileFolding} from './file-fold.ts';
|
||||||
@@ -41,8 +41,8 @@ function initRepoDiffConversationForm() {
|
|||||||
const formData = new FormData(form);
|
const formData = new FormData(form);
|
||||||
|
|
||||||
// if the form is submitted by a button, append the button's name and value to the form data
|
// if the form is submitted by a button, append the button's name and value to the form data
|
||||||
const submitter = submitEventSubmitter(e);
|
const submitter = e.submitter;
|
||||||
const isSubmittedByButton = (submitter?.nodeName === 'BUTTON') || (submitter?.nodeName === 'INPUT' && submitter.type === 'submit');
|
const isSubmittedByButton = submitter instanceof HTMLButtonElement || (submitter instanceof HTMLInputElement && submitter.type === 'submit');
|
||||||
if (isSubmittedByButton && submitter.name) {
|
if (isSubmittedByButton && submitter.name) {
|
||||||
formData.append(submitter.name, submitter.value);
|
formData.append(submitter.name, submitter.value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ import {initCaptcha} from './features/captcha.ts';
|
|||||||
import {initRepositoryActionView} from './features/repo-actions.ts';
|
import {initRepositoryActionView} from './features/repo-actions.ts';
|
||||||
import {initGlobalTooltips} from './modules/tippy.ts';
|
import {initGlobalTooltips} from './modules/tippy.ts';
|
||||||
import {initGiteaFomantic} from './modules/fomantic.ts';
|
import {initGiteaFomantic} from './modules/fomantic.ts';
|
||||||
import {initSubmitEventPolyfill} from './utils/dom.ts';
|
|
||||||
import {initRepoIssueList} from './features/repo-issue-list.ts';
|
import {initRepoIssueList} from './features/repo-issue-list.ts';
|
||||||
import {initCommonIssueListQuickGoto} from './features/common-issue-list.ts';
|
import {initCommonIssueListQuickGoto} from './features/common-issue-list.ts';
|
||||||
import {initRepoContributors} from './features/contributors.ts';
|
import {initRepoContributors} from './features/contributors.ts';
|
||||||
@@ -69,7 +68,6 @@ import {initDevtest} from './modules/devtest.ts';
|
|||||||
|
|
||||||
const initStartTime = performance.now();
|
const initStartTime = performance.now();
|
||||||
const initPerformanceTracer = callInitFunctions([
|
const initPerformanceTracer = callInitFunctions([
|
||||||
initSubmitEventPolyfill,
|
|
||||||
initGiteaFomantic,
|
initGiteaFomantic,
|
||||||
|
|
||||||
initGlobalComponent,
|
initGlobalComponent,
|
||||||
|
|||||||
@@ -257,28 +257,6 @@ export function loadElem(el: LoadableElement, src: string) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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: any) {
|
|
||||||
e = e.originalEvent ?? e; // if the event is wrapped by jQuery, use "originalEvent", otherwise, use the event itself
|
|
||||||
return needSubmitEventPolyfill ? (e.target._submitter || null) : e.submitter;
|
|
||||||
}
|
|
||||||
|
|
||||||
function submitEventPolyfillListener(e: Event) {
|
|
||||||
const form = (e.target as HTMLElement).closest('form');
|
|
||||||
if (!form) return;
|
|
||||||
form._submitter = (e.target as HTMLElement).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);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isElemVisible(el: HTMLElement): boolean {
|
export function isElemVisible(el: HTMLElement): boolean {
|
||||||
// Check if an element is visible, equivalent to jQuery's `:visible` pseudo.
|
// Check if an element is visible, equivalent to jQuery's `:visible` pseudo.
|
||||||
// This function DOESN'T account for all possible visibility scenarios, its behavior is covered by the tests of "querySingleVisibleElem"
|
// This function DOESN'T account for all possible visibility scenarios, its behavior is covered by the tests of "querySingleVisibleElem"
|
||||||
|
|||||||
Reference in New Issue
Block a user