chore: enable no-jquery/no-trigger

- A lot of substitution to `.requestSubmit()`.
- Where possible, rewrite some other jquery to vanilla javascript to
ease the linter fix.
This commit is contained in:
Gusted 2025-04-01 04:41:57 +02:00
parent c124014115
commit 9420d3d0a5
No known key found for this signature in database
GPG key ID: FD821B732837125F
9 changed files with 34 additions and 31 deletions

View file

@ -381,7 +381,7 @@ export default tseslint.config(
'no-jquery/no-sub': [2], 'no-jquery/no-sub': [2],
'no-jquery/no-support': [2], 'no-jquery/no-support': [2],
'no-jquery/no-text': [0], 'no-jquery/no-text': [0],
'no-jquery/no-trigger': [0], 'no-jquery/no-trigger': [2],
'no-jquery/no-trim': [2], 'no-jquery/no-trim': [2],
'no-jquery/no-type': [2], 'no-jquery/no-type': [2],
'no-jquery/no-unique': [2], 'no-jquery/no-unique': [2],

View file

@ -98,14 +98,14 @@ const sfc = {
$(`#${this.branchForm} input[name="refType"]`).val('branch'); $(`#${this.branchForm} input[name="refType"]`).val('branch');
} }
if (this.submitForm) { if (this.submitForm) {
$(`#${this.branchForm}`).trigger('submit'); document.getElementById(this.branchForm).requestSubmit();
} }
this.menuVisible = false; this.menuVisible = false;
} }
}, },
createNewBranch() { createNewBranch() {
if (!this.showCreateNewBranch) return; if (!this.showCreateNewBranch) return;
$(this.$refs.newBranchForm).trigger('submit'); this.$refs.newBranchForm.requestSubmit();
}, },
focusSearchField() { focusSearchField() {
nextTick(() => { nextTick(() => {

View file

@ -175,7 +175,7 @@ export function initAdminCommon() {
onUsePagedSearchChange(); onUsePagedSearchChange();
} }
}); });
$('#auth_type').trigger('change'); document.getElementById('auth_type').dispatchEvent(new Event('change'));
document.getElementById('security_protocol')?.addEventListener('change', onSecurityProtocolChange); document.getElementById('security_protocol')?.addEventListener('change', onSecurityProtocolChange);
document.getElementById('use_paged_search')?.addEventListener('change', onUsePagedSearchChange); document.getElementById('use_paged_search')?.addEventListener('change', onUsePagedSearchChange);
document.getElementById('oauth2_provider')?.addEventListener('change', () => onOAuth2Change(true)); document.getElementById('oauth2_provider')?.addEventListener('change', () => onOAuth2Change(true));
@ -200,10 +200,12 @@ export function initAdminCommon() {
} }
if (document.querySelector('.admin.authentication')) { if (document.querySelector('.admin.authentication')) {
$('#auth_name').on('input', function () { const authNameEl = document.getElementById('auth_name');
authNameEl.addEventListener('input', (el) => {
// appSubUrl is either empty or is a path that starts with `/` and doesn't have a trailing slash. // appSubUrl is either empty or is a path that starts with `/` and doesn't have a trailing slash.
document.getElementById('oauth2-callback-url').textContent = `${window.location.origin}${appSubUrl}/user/oauth2/${encodeURIComponent(this.value)}/callback`; document.getElementById('oauth2-callback-url').textContent = `${window.location.origin}${appSubUrl}/user/oauth2/${encodeURIComponent(el.target.value)}/callback`;
}).trigger('input'); });
authNameEl.dispatchEvent(new Event('input'));
} }
// Notice // Notice

View file

@ -57,7 +57,7 @@ export function initGlobalEnterQuickSubmit() {
export function initGlobalButtonClickOnEnter() { export function initGlobalButtonClickOnEnter() {
$(document).on('keypress', 'div.ui.button,span.ui.button', (e) => { $(document).on('keypress', 'div.ui.button,span.ui.button', (e) => {
if (e.code === ' ' || e.code === 'Enter') { if (e.code === ' ' || e.code === 'Enter') {
$(e.target).trigger('click'); e.target.click();
e.preventDefault(); e.preventDefault();
} }
}); });
@ -314,7 +314,7 @@ export function initGlobalLinkActions() {
closable: false, closable: false,
onApprove: async () => { onApprove: async () => {
if ($this.data('type') === 'form') { if ($this.data('type') === 'form') {
$($this.data('form')).trigger('submit'); document.querySelector($this.data('form')).requestSubmit();
return; return;
} }
if ($this[0].getAttribute('hx-confirm')) { if ($this[0].getAttribute('hx-confirm')) {

View file

@ -38,7 +38,7 @@ export function initCompLabelEdit(selector) {
form.reportValidity(); form.reportValidity();
return false; return false;
} }
$('.new-label.form').trigger('submit'); document.querySelector('.new-label.form').requestSubmit();
}, },
}).modal('show'); }).modal('show');
return false; return false;
@ -75,7 +75,7 @@ export function initCompLabelEdit(selector) {
form.reportValidity(); form.reportValidity();
return false; return false;
} }
$('.edit-label.form').trigger('submit'); document.querySelector('.edit-label.form').requestSubmit();
}, },
}).modal('show'); }).modal('show');
return false; return false;

View file

@ -184,7 +184,8 @@ export function initRepoCodeView() {
$('html, body').scrollTop($first.offset().top - 200); $('html, body').scrollTop($first.offset().top - 200);
} }
} }
}).trigger('hashchange'); });
window.dispatchEvent(new Event('hashchange'));
} }
$(document).on('click', '.fold-file', ({currentTarget}) => { $(document).on('click', '.fold-file', ({currentTarget}) => {
invertFileFolding(currentTarget.closest('.file-content'), currentTarget); invertFileFolding(currentTarget.closest('.file-content'), currentTarget);

View file

@ -33,25 +33,25 @@ export function initRepoArchiveLinks() {
} }
export function initRepoCloneLink() { export function initRepoCloneLink() {
const $repoCloneSsh = $('#repo-clone-ssh'); const repoCloneSSH = document.getElementById('repo-clone-ssh');
const $repoCloneHttps = $('#repo-clone-https'); const repoCloneHTTPS = document.getElementById('repo-clone-https');
const $inputLink = $('#repo-clone-url'); const inputLink = document.getElementById('repo-clone-url');
if ((!$repoCloneSsh.length && !$repoCloneHttps.length) || !$inputLink.length) { if ((!repoCloneSSH && !repoCloneHTTPS) || !inputLink) {
return; return;
} }
$repoCloneSsh.on('click', () => { repoCloneSSH.addEventListener('click', () => {
localStorage.setItem('repo-clone-protocol', 'ssh'); localStorage.setItem('repo-clone-protocol', 'ssh');
window.updateCloneStates(); window.updateCloneStates();
}); });
$repoCloneHttps.on('click', () => { repoCloneHTTPS.addEventListener('click', () => {
localStorage.setItem('repo-clone-protocol', 'https'); localStorage.setItem('repo-clone-protocol', 'https');
window.updateCloneStates(); window.updateCloneStates();
}); });
$inputLink.on('focus', () => { inputLink.addEventListener('focus', () => {
$inputLink.trigger('select'); inputLink.select();
}); });
} }

View file

@ -185,7 +185,7 @@ export function initRepoEditor() {
$('#edit-empty-content-modal') $('#edit-empty-content-modal')
.modal({ .modal({
onApprove() { onApprove() {
$('.edit.form').trigger('submit'); document.querySelector('.edit.form').requestSubmit();
}, },
}) })
.modal('show'); .modal('show');

View file

@ -37,27 +37,27 @@ export function initRepoIssueTimeTracking() {
$('.issue-start-time-modal').modal({ $('.issue-start-time-modal').modal({
duration: 200, duration: 200,
onApprove() { onApprove() {
$('#add_time_manual_form').trigger('submit'); document.getElementById('add_time_manual_form').requestSubmit();
}, },
}).modal('show'); }).modal('show');
$('.issue-start-time-modal input').on('keydown', (e) => { $('.issue-start-time-modal input').on('keydown', (e) => {
if ((e.keyCode || e.key) === 13) { if ((e.keyCode || e.key) === 13) {
$('#add_time_manual_form').trigger('submit'); document.getElementById('add_time_manual_form').requestSubmit();
} }
}); });
}); });
$(document).on('click', '.issue-start-time, .issue-stop-time', () => { $(document).on('click', '.issue-start-time, .issue-stop-time', () => {
$('#toggle_stopwatch_form').trigger('submit'); document.getElementById('toggle_stopwatch_form').requestSubmit();
}); });
$(document).on('click', '.issue-cancel-time', () => { $(document).on('click', '.issue-cancel-time', () => {
$('#cancel_stopwatch_form').trigger('submit'); document.getElementById('cancel_stopwatch_form').requestSubmit();
}); });
$(document).on('click', 'button.issue-delete-time', function () { $(document).on('click', 'button.issue-delete-time', function () {
const sel = `.issue-delete-time-modal[data-id="${$(this).data('id')}"]`; const sel = `.issue-delete-time-modal[data-id="${$(this).data('id')}"]`;
$(sel).modal({ $(sel).modal({
duration: 200, duration: 200,
onApprove() { onApprove() {
$(`${sel} form`).trigger('submit'); document.getElementById(`${sel} form`).requestSubmit();
}, },
}).modal('show'); }).modal('show');
}); });
@ -247,7 +247,7 @@ export function initRepoIssueDependencyDelete() {
onApprove: () => { onApprove: () => {
$('#removeDependencyID').val(id); $('#removeDependencyID').val(id);
$('#dependencyType').val(type); $('#dependencyType').val(type);
$('#removeDependencyForm').trigger('submit'); document.getElementById('removeDependencyForm').requestSubmit();
}, },
}).modal('show'); }).modal('show');
}); });
@ -369,9 +369,9 @@ export function initRepoIssueWipTitle() {
$('.title_wip_desc > a').on('click', (e) => { $('.title_wip_desc > a').on('click', (e) => {
e.preventDefault(); e.preventDefault();
const $issueTitle = $('#issue_title'); const issueTitleEl = document.getElementById('issue_title');
$issueTitle.trigger('focus'); issueTitleEl.focus();
const value = $issueTitle.val().trim().toUpperCase(); const value = issueTitleEl.value.trim().toUpperCase();
const wipPrefixes = $('.title_wip_desc').data('wip-prefixes'); const wipPrefixes = $('.title_wip_desc').data('wip-prefixes');
for (const prefix of wipPrefixes) { for (const prefix of wipPrefixes) {
@ -380,7 +380,7 @@ export function initRepoIssueWipTitle() {
} }
} }
$issueTitle.val(`${wipPrefixes[0]} ${$issueTitle.val()}`); issueTitleEl.value = `${wipPrefixes[0]} ${issueTitleEl.value}`;
}); });
} }