Issue #3454079 by Tom Konda, smustgrave: Prefer to use Array.prototype.includes() for some of Array.prototype.indexOf()

(cherry picked from commit 0819b7aaf4)
merge-requests/8529/head
nod_ 2024-06-18 22:30:06 +02:00
parent 4424bc8070
commit 6f61856980
No known key found for this signature in database
GPG Key ID: 76624892606FA197
3 changed files with 7 additions and 9 deletions

View File

@ -112,9 +112,8 @@
const tagged = autocomplete.splitValues(request.term);
const il = tagged.length;
for (let i = 0; i < il; i++) {
const index = suggestions.indexOf(tagged[i]);
if (index >= 0) {
suggestions.splice(index, 1);
if (suggestions.includes(tagged[i])) {
suggestions.splice(suggestions.indexOf(tagged[i]), 1);
}
}
response(suggestions);

View File

@ -326,15 +326,14 @@
const id = e.currentTarget.value;
// Update the selection.
const position = currentSelection.indexOf(id);
if (e.currentTarget.checked) {
// Check if the ID is not already in the selection and add if needed.
if (position === -1) {
if (!currentSelection.includes(id)) {
currentSelection.push(id);
}
} else if (position !== -1) {
} else if (currentSelection.includes(id)) {
// Remove the ID when it is in the current selection.
currentSelection.splice(position, 1);
currentSelection.splice(currentSelection.indexOf(id), 1);
}
const mediaLibraryModalSelection = document.querySelector(

View File

@ -39,7 +39,7 @@
messageWrapper.setAttribute('data-drupal-message-type', type);
let svg = '';
if (['error', 'warning', 'status', 'info'].indexOf(type) > -1) {
if (['error', 'warning', 'status', 'info'].includes(type)) {
svg =
'<div class="messages__icon"><svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">';
}
@ -58,7 +58,7 @@
'<path d="M32,16c0,8.8-7.2,16-16,16S0,24.8,0,16C0,7.2,7.2,0,16,0S32,7.2,32,16z M16.4,5.3c-3.5,0-5.8,1.5-7.5,4.1c-0.2,0.3-0.2,0.8,0.2,1l2.2,1.7c0.3,0.3,0.8,0.2,1.1-0.1c1.2-1.5,1.9-2.3,3.7-2.3c1.3,0,2.9,0.8,2.9,2.1c0,1-0.8,1.5-2.1,2.2c-1.5,0.9-3.5,1.9-3.5,4.6v0.3c0,0.4,0.3,0.8,0.8,0.8h3.6c0.4,0,0.8-0.3,0.8-0.8v-0.1c0-1.8,5.4-1.9,5.4-6.9C23.9,8.1,20.1,5.3,16.4,5.3z M16,21.3c-1.6,0-3,1.3-3,3c0,1.6,1.3,3,3,3s3-1.3,3-3C19,22.6,17.6,21.3,16,21.3z"/>';
}
if (['error', 'warning', 'status', 'info'].indexOf(type) > -1) {
if (['error', 'warning', 'status', 'info'].includes(type)) {
svg += '</svg></div>';
}