Skip to content

Commit 77ecf85

Browse files
committed
Remove jQuery .text()
1 parent b9f69b4 commit 77ecf85

9 files changed

+31
-30
lines changed

.eslintrc.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ rules:
321321
jquery/no-sizzle: [2]
322322
jquery/no-slide: [0]
323323
jquery/no-submit: [0]
324-
jquery/no-text: [0]
324+
jquery/no-text: [2]
325325
jquery/no-toggle: [2]
326326
jquery/no-trigger: [0]
327327
jquery/no-trim: [2]
@@ -474,7 +474,7 @@ rules:
474474
no-jquery/no-slide: [2]
475475
no-jquery/no-sub: [2]
476476
no-jquery/no-support: [2]
477-
no-jquery/no-text: [0]
477+
no-jquery/no-text: [2]
478478
no-jquery/no-trigger: [0]
479479
no-jquery/no-trim: [2]
480480
no-jquery/no-type: [2]

web_src/js/features/common-global.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,10 @@ export function initGlobalLinkActions() {
303303
}
304304

305305
const $dialog = $(`.delete.modal${filter}`);
306-
$dialog.find('.name').text($this.data('name'));
306+
$dialog.find('.name')[0].textContent = $this.data('name');
307307
for (const [key, value] of Object.entries(dataArray)) {
308308
if (key && key.startsWith('data')) {
309-
$dialog.find(`.${key}`).text(value);
309+
$dialog.find(`.${key}`)[0].textContent = value;
310310
}
311311
}
312312

@@ -373,7 +373,7 @@ function initGlobalShowModal() {
373373
} else if ($attrTarget[0].matches('input, textarea')) {
374374
$attrTarget.val(attrib.value); // FIXME: add more supports like checkbox
375375
} else {
376-
$attrTarget.text(attrib.value); // FIXME: it should be more strict here, only handle div/span/p
376+
$attrTarget[0].textContent = attrib.value; // FIXME: it should be more strict here, only handle div/span/p
377377
}
378378
}
379379

web_src/js/features/imagediff.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export function initImageDiff() {
9292
return loadElem(img, info.path);
9393
}));
9494
// only the first images is associated with $boundsInfo
95-
if (!success) info.$boundsInfo.text('(image error)');
95+
if (!success) info.$boundsInfo.textContent = '(image error)';
9696
if (info.mime === 'image/svg+xml') {
9797
const resp = await GET(info.path);
9898
const text = await resp.text();

web_src/js/features/notification.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,13 @@ async function receiveUpdateCount(event) {
4747

4848
export function initNotificationCount() {
4949
const $notificationCount = $('.notification_count');
50-
51-
if (!$notificationCount.length) {
52-
return;
53-
}
50+
if (!$notificationCount.length) return;
5451

5552
let usingPeriodicPoller = false;
5653
const startPeriodicPoller = (timeout, lastCount) => {
5754
if (timeout <= 0 || !Number.isFinite(timeout)) return;
5855
usingPeriodicPoller = true;
59-
lastCount = lastCount ?? $notificationCount.text();
56+
lastCount = lastCount ?? getCurrentCount();
6057
setTimeout(async () => {
6158
await updateNotificationCountWithCallback(startPeriodicPoller, timeout, lastCount);
6259
}, timeout);
@@ -120,8 +117,12 @@ export function initNotificationCount() {
120117
startPeriodicPoller(notificationSettings.MinTimeout);
121118
}
122119

120+
function getCurrentCount() {
121+
return document.querySelector('.notification_count').textContent;
122+
}
123+
123124
async function updateNotificationCountWithCallback(callback, timeout, lastCount) {
124-
const currentCount = $('.notification_count').text();
125+
const currentCount = getCurrentCount();
125126
if (lastCount !== currentCount) {
126127
callback(notificationSettings.MinTimeout, currentCount);
127128
return;

web_src/js/features/repo-editor.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,17 @@ export function initRepoEditor() {
7070
hideElem('.quick-pull-branch-name');
7171
document.querySelector('.quick-pull-branch-name input').required = false;
7272
}
73-
$('#commit-button').text(this.getAttribute('button_text'));
73+
$('#commit-button')[0].textContent = this.getAttribute('button_text');
7474
});
7575

7676
const joinTreePath = ($fileNameEl) => {
7777
const parts = [];
7878
$('.breadcrumb span.section').each(function () {
7979
const $element = $(this);
8080
if ($element.find('a').length) {
81-
parts.push($element.find('a').text());
81+
parts.push($element.find('a')[0].textContent);
8282
} else {
83-
parts.push($element.text());
83+
parts.push($element[0].textContent);
8484
}
8585
});
8686
if ($fileNameEl.val()) parts.push($fileNameEl.val());
@@ -116,7 +116,7 @@ export function initRepoEditor() {
116116
if (e.code === 'Backspace' && getCursorPosition($(this)) === 0 && $section.length > 0) {
117117
e.preventDefault();
118118
const $divider = $('.breadcrumb .breadcrumb-divider');
119-
const value = $section.last().find('a').text();
119+
const value = $section.last().find('a')[0].textContent;
120120
$(this).val(value + $(this).val());
121121
this.setSelectionRange(value.length, value.length);
122122
$section.last().remove();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export function initRepoIssueCommentEdit() {
183183
$(document).on('click', '.quote-reply', async function (event) {
184184
event.preventDefault();
185185
const target = $(this).data('target');
186-
const quote = $(`#${target}`).text().replace(/\n/g, '\n> ');
186+
const quote = $(`#${target}`)[0].textContent.replace(/\n/g, '\n> ');
187187
const content = `> ${quote}\n\n`;
188188
let editor;
189189
if ($(this).hasClass('quote-reply-diff')) {

web_src/js/features/repo-issue.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ export function initRepoPullRequestUpdate() {
281281
if (url) {
282282
const buttonText = pullUpdateButton.querySelector('.button-text');
283283
if (buttonText) {
284-
buttonText.textContent = $choice.text();
284+
buttonText.textContent = $choice[0].textContent;
285285
}
286286
pullUpdateButton.setAttribute('data-do', url);
287287
}
@@ -566,7 +566,7 @@ export function initRepoIssueReferenceIssue() {
566566
// Reference issue
567567
$(document).on('click', '.reference-issue', function (event) {
568568
const $this = $(this);
569-
const content = $(`#${$this.data('target')}`).text();
569+
const content = $(`#${$this.data('target')}`)[0].textContent;
570570
const poster = $this.data('poster-username');
571571
const reference = toAbsoluteUrl($this.data('reference'));
572572
const $modal = $($this.data('modal'));
@@ -603,8 +603,7 @@ export function initRepoIssueWipToggle() {
603603

604604
async function pullrequest_targetbranch_change(update_url) {
605605
const targetBranch = $('#pull-target-branch').data('branch');
606-
const $branchTarget = $('#branch_target');
607-
if (targetBranch === $branchTarget.text()) {
606+
if (targetBranch === $('#branch_target')[0].textContent) {
608607
window.location.reload();
609608
return false;
610609
}
@@ -640,8 +639,9 @@ export function initRepoIssueTitleEdit() {
640639
$('#cancel-edit-title').on('click', editTitleToggle);
641640
$('#save-edit-title').on('click', editTitleToggle).on('click', async function () {
642641
const pullrequest_target_update_url = this.getAttribute('data-target-update-url');
643-
if (!$editInput.val().length || $editInput.val() === $issueTitle.text()) {
644-
$editInput.val($issueTitle.text());
642+
const titleText = $issueTitle[0].textContent;
643+
if (!$editInput.val().length || $editInput.val() === titleText) {
644+
$editInput.val(titleText);
645645
await pullrequest_targetbranch_change(pullrequest_target_update_url);
646646
} else {
647647
try {
@@ -650,7 +650,7 @@ export function initRepoIssueTitleEdit() {
650650
const response = await POST(this.getAttribute('data-update-url'), {data: params});
651651
const data = await response.json();
652652
$editInput.val(data.title);
653-
$issueTitle.text(data.title);
653+
$issueTitle[0].textContent = data.title;
654654
if (pullrequest_target_update_url) {
655655
await pullrequest_targetbranch_change(pullrequest_target_update_url); // it will reload the window
656656
} else {

web_src/js/features/repo-legacy.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export function initRepoCommentForm() {
6464
const editMode = $('#editing_mode').val();
6565
$($(this).data('id-selector')).val(selectedValue);
6666
if ($isNewIssue) {
67-
$selectBranch.find('.ui .branch-name').text($(this).data('name'));
67+
$selectBranch.find('.ui .branch-name')[0].textContent = $(this).data('name');
6868
return;
6969
}
7070

@@ -79,7 +79,7 @@ export function initRepoCommentForm() {
7979
console.error(error);
8080
}
8181
} else if (editMode === '') {
82-
$selectBranch.find('.ui .branch-name').text(selectedValue);
82+
$selectBranch.find('.ui .branch-name')[0].textContent = selectedValue;
8383
}
8484
});
8585
$selectBranch.find('.reference.column').on('click', function () {
@@ -275,7 +275,7 @@ export function initRepoCommentForm() {
275275
$list.find('.selected').html(`
276276
<a class="item muted sidebar-item-link" href=${$(this).data('href')}>
277277
${icon}
278-
${htmlEscape($(this).text())}
278+
${htmlEscape(this.textContent)}
279279
</a>
280280
`);
281281

web_src/js/features/repo-settings.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ export function initRepoSettingsCollaboration() {
2222
data.append('mode', value);
2323
await POST(el.getAttribute('data-url'), {data});
2424
} catch {
25-
$text.text('(error)'); // prevent from misleading users when error occurs
25+
$text[0].textContent = '(error)'; // prevent from misleading users when error occurs
2626
el.setAttribute('data-last-value', lastValue);
2727
}
2828
},
2929
onChange(_value, text, _$choice) {
30-
$text.text(text); // update the text when using keyboard navigating
30+
$text[0].textextContent = text; // update the text when using keyboard navigating
3131
},
3232
onHide() {
3333
// set to the really selected value, defer to next tick to make sure `action` has finished its work because the calling order might be onHide -> action
@@ -36,7 +36,7 @@ export function initRepoSettingsCollaboration() {
3636
if ($item) {
3737
$dropdown.dropdown('set selected', el.getAttribute('data-last-value'));
3838
} else {
39-
$text.text('(none)'); // prevent from misleading users when the access mode is undefined
39+
$text[0].textContent = '(none)'; // prevent from misleading users when the access mode is undefined
4040
}
4141
}, 0);
4242
},

0 commit comments

Comments
 (0)