Skip to content

Commit 1ab88da

Browse files
CommanderRootlunny
andauthored
Replace deprecated String.prototype.substr() with String.prototype.slice() (#18796)
String.prototype.substr() is deprecated (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr) so we replace it with the slice() method which works similarily but isn't deprecated. Signed-off-by: Tobias Speicher <[email protected]> Co-authored-by: Lunny Xiao <[email protected]>
1 parent a7b9d44 commit 1ab88da

File tree

6 files changed

+11
-11
lines changed

6 files changed

+11
-11
lines changed

web_src/js/features/common-global.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ export function initGlobalLinkActions() {
211211
};
212212
for (const [key, value] of Object.entries(dataArray)) {
213213
if (key && key.startsWith('data')) {
214-
postData[key.substr(4)] = value;
214+
postData[key.slice(4)] = value;
215215
}
216216
if (key === 'id') {
217217
postData['id'] = value;

web_src/js/features/common-issue.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function initCommonIssue() {
2020
const issueIDs = $('.issue-checkbox').children('input:checked').map((_, el) => {
2121
return el.getAttribute('data-issue-id');
2222
}).get().join(',');
23-
if (elementId === '0' && url.substr(-9) === '/assignee') {
23+
if (elementId === '0' && url.slice(-9) === '/assignee') {
2424
elementId = '';
2525
action = 'clear';
2626
}

web_src/js/features/comp/ImagePaste.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export function initCompImagePaste($target) {
6565
for (const textarea of this.querySelectorAll('textarea')) {
6666
textarea.addEventListener('paste', async (e) => {
6767
for (const img of clipboardPastedImages(e)) {
68-
const name = img.name.substr(0, img.name.lastIndexOf('.'));
68+
const name = img.name.slice(0, img.name.lastIndexOf('.'));
6969
insertAtCursor(textarea, `![${name}]()`);
7070
const data = await uploadFile(img, uploadUrl);
7171
replaceAndKeepCursor(textarea, `![${name}]()`, `![${name}](/attachments/${data.uuid})`);
@@ -81,7 +81,7 @@ export function initEasyMDEImagePaste(easyMDE, dropzone, files) {
8181
const uploadUrl = dropzone.getAttribute('data-upload-url');
8282
easyMDE.codemirror.on('paste', async (_, e) => {
8383
for (const img of clipboardPastedImages(e)) {
84-
const name = img.name.substr(0, img.name.lastIndexOf('.'));
84+
const name = img.name.slice(0, img.name.lastIndexOf('.'));
8585
const data = await uploadFile(img, uploadUrl);
8686
const pos = easyMDE.codemirror.getCursor();
8787
easyMDE.codemirror.replaceRange(`![${name}](/attachments/${data.uuid})`, pos);

web_src/js/features/repo-code.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ function selectRange($list, $select, $from) {
3636
};
3737

3838
if ($from) {
39-
let a = parseInt($select.attr('rel').substr(1));
40-
let b = parseInt($from.attr('rel').substr(1));
39+
let a = parseInt($select.attr('rel').slice(1));
40+
let b = parseInt($from.attr('rel').slice(1));
4141
let c;
4242
if (a !== b) {
4343
if (a > b) {

web_src/js/features/repo-issue.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ export function initRepoPullRequestReview() {
412412
// get the name of the parent id
413413
const groupID = commentDiv.closest('div[id^="code-comments-"]').attr('id');
414414
if (groupID && groupID.startsWith('code-comments-')) {
415-
const id = groupID.substr(14);
415+
const id = groupID.slice(14);
416416
$(`#show-outdated-${id}`).addClass('hide');
417417
$(`#code-comments-${id}`).removeClass('hide');
418418
$(`#code-preview-${id}`).removeClass('hide');
@@ -560,7 +560,7 @@ export function initRepoIssueWipToggle() {
560560
const updateUrl = toggleWip.getAttribute('data-update-url');
561561
await $.post(updateUrl, {
562562
_csrf: csrfToken,
563-
title: title?.startsWith(wipPrefix) ? title.substr(wipPrefix.length).trim() : `${wipPrefix.trim()} ${title}`,
563+
title: title?.startsWith(wipPrefix) ? title.slice(wipPrefix.length).trim() : `${wipPrefix.trim()} ${title}`,
564564
});
565565
window.location.reload();
566566
});

web_src/js/features/repo-projects.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,9 @@ export default function initRepoProject() {
171171
}
172172

173173
function setLabelColor(label, color) {
174-
const red = getRelativeColor(parseInt(color.substr(1, 2), 16));
175-
const green = getRelativeColor(parseInt(color.substr(3, 2), 16));
176-
const blue = getRelativeColor(parseInt(color.substr(5, 2), 16));
174+
const red = getRelativeColor(parseInt(color.slice(1, 3), 16));
175+
const green = getRelativeColor(parseInt(color.slice(3, 5), 16));
176+
const blue = getRelativeColor(parseInt(color.slice(5, 7), 16));
177177
const luminance = 0.2126 * red + 0.7152 * green + 0.0722 * blue;
178178

179179
if (luminance > 0.179) {

0 commit comments

Comments
 (0)