Skip to content

Commit 21fe512

Browse files
silverwindGiteaBot
andauthored
Forbid jQuery .prop and fix related issues (#29832)
The issue checkbox code received a few more cleanups and I specifically tested it. The other changes are trivial. Also, I checked the cases for how many elements match the jQuery selection to determine querySelector vs. querySelectorAll. --------- Co-authored-by: Giteabot <[email protected]>
1 parent cb78648 commit 21fe512

File tree

6 files changed

+37
-27
lines changed

6 files changed

+37
-27
lines changed

.eslintrc.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ rules:
315315
jquery/no-parent: [0]
316316
jquery/no-parents: [0]
317317
jquery/no-parse-html: [2]
318-
jquery/no-prop: [0]
318+
jquery/no-prop: [2]
319319
jquery/no-proxy: [2]
320320
jquery/no-ready: [2]
321321
jquery/no-serialize: [2]
@@ -466,7 +466,7 @@ rules:
466466
no-jquery/no-parse-html: [2]
467467
no-jquery/no-parse-json: [2]
468468
no-jquery/no-parse-xml: [2]
469-
no-jquery/no-prop: [0]
469+
no-jquery/no-prop: [2]
470470
no-jquery/no-proxy: [2]
471471
no-jquery/no-ready-shorthand: [2]
472472
no-jquery/no-ready: [2]

web_src/js/features/admin/common.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function initAdminCommon() {
4949
}
5050

5151
function onUsePagedSearchChange() {
52-
if ($('#use_paged_search').prop('checked')) {
52+
if (document.getElementById('use_paged_search').checked) {
5353
showElem('.search-page-size');
5454
$('.search-page-size').find('input').attr('required', 'required');
5555
} else {

web_src/js/features/comp/LabelEdit.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function updateExclusiveLabelEdit(form) {
1414
if (isExclusiveScopeName($nameInput.val())) {
1515
$exclusiveField.removeClass('muted');
1616
$exclusiveField.removeAttr('aria-disabled');
17-
if ($exclusiveCheckbox.prop('checked') && $exclusiveCheckbox.data('exclusive-warn')) {
17+
if ($exclusiveCheckbox[0].checked && $exclusiveCheckbox.data('exclusive-warn')) {
1818
$exclusiveWarning.removeClass('gt-hidden');
1919
} else {
2020
$exclusiveWarning.addClass('gt-hidden');
@@ -50,10 +50,10 @@ export function initCompLabelEdit(selector) {
5050
$nameInput.val($(this).data('title'));
5151

5252
const $isArchivedCheckbox = $('.edit-label .label-is-archived-input');
53-
$isArchivedCheckbox.prop('checked', this.hasAttribute('data-is-archived'));
53+
$isArchivedCheckbox[0].checked = this.hasAttribute('data-is-archived');
5454

5555
const $exclusiveCheckbox = $('.edit-label .label-exclusive-input');
56-
$exclusiveCheckbox.prop('checked', this.hasAttribute('data-exclusive'));
56+
$exclusiveCheckbox[0].checked = this.hasAttribute('data-exclusive');
5757
// Warn when label was previously not exclusive and used in issues
5858
$exclusiveCheckbox.data('exclusive-warn',
5959
$(this).data('num-issues') > 0 &&

web_src/js/features/repo-editor.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ export function initRepoEditor() {
6767
$('.js-quick-pull-choice-option').on('change', function () {
6868
if ($(this).val() === 'commit-to-new-branch') {
6969
showElem($('.quick-pull-branch-name'));
70-
$('.quick-pull-branch-name input').prop('required', true);
70+
document.querySelector('.quick-pull-branch-name input').required = true;
7171
} else {
7272
hideElem($('.quick-pull-branch-name'));
73-
$('.quick-pull-branch-name input').prop('required', false);
73+
document.querySelector('.quick-pull-branch-name input').required = false;
7474
}
7575
$('#commit-button').text($(this).attr('button_text'));
7676
});
@@ -135,13 +135,13 @@ export function initRepoEditor() {
135135

136136
// Using events from https://github.com/codedance/jquery.AreYouSure#advanced-usage
137137
// to enable or disable the commit button
138-
const $commitButton = $('#commit-button');
138+
const commitButton = document.getElementById('commit-button');
139139
const $editForm = $('.ui.edit.form');
140140
const dirtyFileClass = 'dirty-file';
141141

142142
// Disabling the button at the start
143143
if ($('input[name="page_has_posted"]').val() !== 'true') {
144-
$commitButton.prop('disabled', true);
144+
commitButton.disabled = true;
145145
}
146146

147147
// Registering a custom listener for the file path and the file content
@@ -151,7 +151,7 @@ export function initRepoEditor() {
151151
fieldSelector: ':input:not(.commit-form-wrapper :input)',
152152
change() {
153153
const dirty = $(this).hasClass(dirtyFileClass);
154-
$commitButton.prop('disabled', !dirty);
154+
commitButton.disabled = !dirty;
155155
},
156156
});
157157

@@ -163,15 +163,15 @@ export function initRepoEditor() {
163163
editor.setValue(value);
164164
}
165165

166-
$commitButton.on('click', (event) => {
166+
commitButton?.addEventListener('click', (e) => {
167167
// A modal which asks if an empty file should be committed
168168
if ($editArea.val().length === 0) {
169169
$('#edit-empty-content-modal').modal({
170170
onApprove() {
171171
$('.edit.form').trigger('submit');
172172
},
173173
}).modal('show');
174-
event.preventDefault();
174+
e.preventDefault();
175175
}
176176
});
177177
})();

web_src/js/features/repo-issue-list.js

+23-13
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,49 @@
11
import $ from 'jquery';
22
import {updateIssuesMeta} from './repo-issue.js';
3-
import {toggleElem, hideElem} from '../utils/dom.js';
3+
import {toggleElem, hideElem, isElemHidden} from '../utils/dom.js';
44
import {htmlEscape} from 'escape-goat';
55
import {confirmModal} from './comp/ConfirmModal.js';
66
import {showErrorToast} from '../modules/toast.js';
77
import {createSortable} from '../modules/sortable.js';
88
import {DELETE, POST} from '../modules/fetch.js';
99

1010
function initRepoIssueListCheckboxes() {
11-
const $issueSelectAll = $('.issue-checkbox-all');
12-
const $issueCheckboxes = $('.issue-checkbox');
11+
const issueSelectAll = document.querySelector('.issue-checkbox-all');
12+
const issueCheckboxes = document.querySelectorAll('.issue-checkbox');
1313

1414
const syncIssueSelectionState = () => {
15-
const $checked = $issueCheckboxes.filter(':checked');
16-
const anyChecked = $checked.length !== 0;
17-
const allChecked = anyChecked && $checked.length === $issueCheckboxes.length;
15+
const checkedCheckboxes = Array.from(issueCheckboxes).filter((el) => el.checked);
16+
const anyChecked = Boolean(checkedCheckboxes.length);
17+
const allChecked = anyChecked && checkedCheckboxes.length === issueCheckboxes.length;
1818

1919
if (allChecked) {
20-
$issueSelectAll.prop({'checked': true, 'indeterminate': false});
20+
issueSelectAll.checked = true;
21+
issueSelectAll.indeterminate = false;
2122
} else if (anyChecked) {
22-
$issueSelectAll.prop({'checked': false, 'indeterminate': true});
23+
issueSelectAll.checked = false;
24+
issueSelectAll.indeterminate = true;
2325
} else {
24-
$issueSelectAll.prop({'checked': false, 'indeterminate': false});
26+
issueSelectAll.checked = false;
27+
issueSelectAll.indeterminate = false;
2528
}
2629
// if any issue is selected, show the action panel, otherwise show the filter panel
2730
toggleElem($('#issue-filters'), !anyChecked);
2831
toggleElem($('#issue-actions'), anyChecked);
2932
// there are two panels but only one select-all checkbox, so move the checkbox to the visible panel
30-
$('#issue-filters, #issue-actions').filter(':visible').find('.issue-list-toolbar-left').prepend($issueSelectAll);
33+
const panels = document.querySelectorAll('#issue-filters, #issue-actions');
34+
const visiblePanel = Array.from(panels).find((el) => !isElemHidden(el));
35+
const toolbarLeft = visiblePanel.querySelector('.issue-list-toolbar-left');
36+
toolbarLeft.prepend(issueSelectAll);
3137
};
3238

33-
$issueCheckboxes.on('change', syncIssueSelectionState);
39+
for (const el of issueCheckboxes) {
40+
el.addEventListener('change', syncIssueSelectionState);
41+
}
3442

35-
$issueSelectAll.on('change', () => {
36-
$issueCheckboxes.prop('checked', $issueSelectAll.is(':checked'));
43+
issueSelectAll.addEventListener('change', () => {
44+
for (const el of issueCheckboxes) {
45+
el.checked = issueSelectAll.checked;
46+
}
3747
syncIssueSelectionState();
3848
});
3949

web_src/js/features/repo-legacy.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ export function initRepository() {
533533
const gitignores = $('input[name="gitignores"]').val();
534534
const license = $('input[name="license"]').val();
535535
if (gitignores || license) {
536-
$('input[name="auto_init"]').prop('checked', true);
536+
document.querySelector('input[name="auto_init"]').checked = true;
537537
}
538538
});
539539
}

0 commit comments

Comments
 (0)