Use querySelector
over alternative DOM methods (#31280)
As per https://github.com/go-gitea/gitea/pull/30115#discussion_r1626060164, prefer `querySelector` by enabling [`unicorn/prefer-query-selector`](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-query-selector.md) and autofixing all except 10 issues. According to [this](https://old.reddit.com/r/learnjavascript/comments/i0f5o8/performance_of_getelementbyid_vs_queryselector/), querySelector may be faster as well, so it's a win-win. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
parent
a2304cb163
commit
507fbf4c3c
47 changed files with 165 additions and 168 deletions
|
@ -44,14 +44,14 @@ export function initRepoIssueTimeTracking() {
|
|||
|
||||
async function updateDeadline(deadlineString) {
|
||||
hideElem('#deadline-err-invalid-date');
|
||||
document.getElementById('deadline-loader')?.classList.add('is-loading');
|
||||
document.querySelector('#deadline-loader')?.classList.add('is-loading');
|
||||
|
||||
let realDeadline = null;
|
||||
if (deadlineString !== '') {
|
||||
const newDate = Date.parse(deadlineString);
|
||||
|
||||
if (Number.isNaN(newDate)) {
|
||||
document.getElementById('deadline-loader')?.classList.remove('is-loading');
|
||||
document.querySelector('#deadline-loader')?.classList.remove('is-loading');
|
||||
showElem('#deadline-err-invalid-date');
|
||||
return false;
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ async function updateDeadline(deadlineString) {
|
|||
}
|
||||
|
||||
try {
|
||||
const response = await POST(document.getElementById('update-issue-deadline-form').getAttribute('action'), {
|
||||
const response = await POST(document.querySelector('#update-issue-deadline-form').getAttribute('action'), {
|
||||
data: {due_date: realDeadline},
|
||||
});
|
||||
|
||||
|
@ -70,7 +70,7 @@ async function updateDeadline(deadlineString) {
|
|||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
document.getElementById('deadline-loader').classList.remove('is-loading');
|
||||
document.querySelector('#deadline-loader').classList.remove('is-loading');
|
||||
showElem('#deadline-err-invalid-date');
|
||||
}
|
||||
}
|
||||
|
@ -182,7 +182,7 @@ export function initRepoIssueCommentDelete() {
|
|||
counter.textContent = String(num);
|
||||
}
|
||||
|
||||
document.getElementById(deleteButton.getAttribute('data-comment-id'))?.remove();
|
||||
document.querySelector(`#${deleteButton.getAttribute('data-comment-id')}`)?.remove();
|
||||
|
||||
if (conversationHolder && !conversationHolder.querySelector('.comment')) {
|
||||
const path = conversationHolder.getAttribute('data-path');
|
||||
|
@ -298,7 +298,7 @@ export function initRepoPullRequestMergeInstruction() {
|
|||
}
|
||||
|
||||
export function initRepoPullRequestAllowMaintainerEdit() {
|
||||
const wrapper = document.getElementById('allow-edits-from-maintainers');
|
||||
const wrapper = document.querySelector('#allow-edits-from-maintainers');
|
||||
if (!wrapper) return;
|
||||
const checkbox = wrapper.querySelector('input[type="checkbox"]');
|
||||
checkbox.addEventListener('input', async () => {
|
||||
|
@ -678,7 +678,7 @@ export function initSingleCommentEditor($commentForm) {
|
|||
// * normal new issue/pr page, no status-button
|
||||
// * issue/pr view page, with comment form, has status-button
|
||||
const opts = {};
|
||||
const statusButton = document.getElementById('status-button');
|
||||
const statusButton = document.querySelector('#status-button');
|
||||
if (statusButton) {
|
||||
opts.onContentChanged = (editor) => {
|
||||
const statusText = statusButton.getAttribute(editor.value().trim() ? 'data-status-and-comment' : 'data-status');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue