Remove jQuery class from the issue author dropdown (#30188)

- Switched from jQuery class functions to plain JavaScript `classList`
- Tested the issue author dropdown functionality and it works as before

Signed-off-by: Yarden Shoham <git@yardenshoham.com>
Co-authored-by: Giteabot <teabot@gitea.io>
(cherry picked from commit 72a5d3faa8b65042a4fc7525d511d8942a47dafe)
This commit is contained in:
Yarden Shoham 2024-03-31 01:14:57 +03:00 committed by Gergely Nagy
parent 936448e11c
commit 25303b2dfe
No known key found for this signature in database

View file

@ -6,6 +6,7 @@ import {confirmModal} from './comp/ConfirmModal.js';
import {showErrorToast} from '../modules/toast.js'; import {showErrorToast} from '../modules/toast.js';
import {createSortable} from '../modules/sortable.js'; import {createSortable} from '../modules/sortable.js';
import {DELETE, POST} from '../modules/fetch.js'; import {DELETE, POST} from '../modules/fetch.js';
import {parseDom} from '../utils.js';
function initRepoIssueListCheckboxes() { function initRepoIssueListCheckboxes() {
const issueSelectAll = document.querySelector('.issue-checkbox-all'); const issueSelectAll = document.querySelector('.issue-checkbox-all');
@ -129,22 +130,27 @@ function initRepoIssueListAuthorDropdown() {
const dropdownTemplates = $searchDropdown.dropdown('setting', 'templates'); const dropdownTemplates = $searchDropdown.dropdown('setting', 'templates');
$searchDropdown.dropdown('internal', 'setup', dropdownSetup); $searchDropdown.dropdown('internal', 'setup', dropdownSetup);
dropdownSetup.menu = function (values) { dropdownSetup.menu = function (values) {
const $menu = $searchDropdown.find('> .menu'); const menu = $searchDropdown.find('> .menu')[0];
$menu.find('> .dynamic-item').remove(); // remove old dynamic items // remove old dynamic items
for (const el of menu.querySelectorAll(':scope > .dynamic-item')) {
el.remove();
}
const newMenuHtml = dropdownTemplates.menu(values, $searchDropdown.dropdown('setting', 'fields'), true /* html */, $searchDropdown.dropdown('setting', 'className')); const newMenuHtml = dropdownTemplates.menu(values, $searchDropdown.dropdown('setting', 'fields'), true /* html */, $searchDropdown.dropdown('setting', 'className'));
if (newMenuHtml) { if (newMenuHtml) {
const $newMenuItems = $(newMenuHtml); const newMenuItems = parseDom(newMenuHtml, 'text/html').querySelectorAll('body > div');
$newMenuItems.addClass('dynamic-item'); for (const newMenuItem of newMenuItems) {
newMenuItem.classList.add('dynamic-item');
}
const div = document.createElement('div'); const div = document.createElement('div');
div.classList.add('divider', 'dynamic-item'); div.classList.add('divider', 'dynamic-item');
$menu[0].append(div, ...$newMenuItems); menu.append(div, ...newMenuItems);
} }
$searchDropdown.dropdown('refresh'); $searchDropdown.dropdown('refresh');
// defer our selection to the next tick, because dropdown will set the selection item after this `menu` function // defer our selection to the next tick, because dropdown will set the selection item after this `menu` function
setTimeout(() => { setTimeout(() => {
$menu.find('.item.active, .item.selected').removeClass('active selected'); menu.querySelector('.item.active, .item.selected')?.classList.remove('active', 'selected');
$menu.find(`.item[data-value="${selectedUserId}"]`).addClass('selected'); menu.querySelector(`.item[data-value="${selectedUserId}"]`)?.classList.add('selected');
}, 0); }, 0);
}; };
} }