Skip to content

Commit b535c6c

Browse files
authored
Remove jQuery class from the project page (#30183)
- Switched from jQuery class functions to plain JavaScript `classList` - Tested the edit column modal functionality and it works as before Signed-off-by: Yarden Shoham <[email protected]>
1 parent 66f7d47 commit b535c6c

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

Diff for: web_src/js/features/repo-projects.js

+23-22
Original file line numberDiff line numberDiff line change
@@ -94,47 +94,46 @@ async function initRepoProjectSortable() {
9494
}
9595

9696
export function initRepoProject() {
97-
if (!$('.repository.projects').length) {
97+
if (!document.querySelector('.repository.projects')) {
9898
return;
9999
}
100100

101101
const _promise = initRepoProjectSortable();
102102

103-
$('.edit-project-column-modal').each(function () {
104-
const $projectHeader = $(this).closest('.project-column-header');
105-
const $projectTitleLabel = $projectHeader.find('.project-column-title');
106-
const $projectTitleInput = $(this).find('.project-column-title-input');
107-
const $projectColorInput = $(this).find('#new_project_column_color');
108-
const $boardColumn = $(this).closest('.project-column');
103+
for (const modal of document.getElementsByClassName('edit-project-column-modal')) {
104+
const projectHeader = modal.closest('.project-column-header');
105+
const projectTitleLabel = projectHeader?.querySelector('.project-column-title');
106+
const projectTitleInput = modal.querySelector('.project-column-title-input');
107+
const projectColorInput = modal.querySelector('#new_project_column_color');
108+
const boardColumn = modal.closest('.project-column');
109+
const bgColor = boardColumn?.style.backgroundColor;
109110

110-
const bgColor = $boardColumn[0].style.backgroundColor;
111111
if (bgColor) {
112-
setLabelColor($projectHeader, rgbToHex(bgColor));
112+
setLabelColor(projectHeader, rgbToHex(bgColor));
113113
}
114114

115-
$(this).find('.edit-project-column-button').on('click', async function (e) {
115+
modal.querySelector('.edit-project-column-button')?.addEventListener('click', async function (e) {
116116
e.preventDefault();
117-
118117
try {
119-
await PUT($(this).data('url'), {
118+
await PUT(this.getAttribute('data-url'), {
120119
data: {
121-
title: $projectTitleInput.val(),
122-
color: $projectColorInput.val(),
120+
title: projectTitleInput?.value,
121+
color: projectColorInput?.value,
123122
},
124123
});
125124
} catch (error) {
126125
console.error(error);
127126
} finally {
128-
$projectTitleLabel.text($projectTitleInput.val());
129-
$projectTitleInput.closest('form').removeClass('dirty');
130-
if ($projectColorInput.val()) {
131-
setLabelColor($projectHeader, $projectColorInput.val());
127+
projectTitleLabel.textContent = projectTitleInput?.value;
128+
projectTitleInput.closest('form')?.classList.remove('dirty');
129+
if (projectColorInput?.value) {
130+
setLabelColor(projectHeader, projectColorInput.value);
132131
}
133-
$boardColumn[0].style = `background: ${$projectColorInput.val()} !important`;
132+
boardColumn.style = `background: ${projectColorInput.value} !important`;
134133
$('.ui.modal').modal('hide');
135134
}
136135
});
137-
});
136+
}
138137

139138
$('.default-project-column-modal').each(function () {
140139
const $boardColumn = $(this).closest('.project-column');
@@ -187,9 +186,11 @@ export function initRepoProject() {
187186
function setLabelColor(label, color) {
188187
const {r, g, b} = tinycolor(color).toRgb();
189188
if (useLightTextOnBackground(r, g, b)) {
190-
label.removeClass('dark-label').addClass('light-label');
189+
label.classList.remove('dark-label');
190+
label.classList.add('light-label');
191191
} else {
192-
label.removeClass('light-label').addClass('dark-label');
192+
label.classList.remove('light-label');
193+
label.classList.add('dark-label');
193194
}
194195
}
195196

0 commit comments

Comments
 (0)