refactor: clean up legacy templates and js (#39808)

* Remove unused `"root"` data attributes from templates
* Use our "confirmModal" as much as possible (partially for #39643)
* Use "data-global-init" to refactor a lot of legacy code
* Refactor and clearify initRepoIssueCommentDelete's behavior to help #36862
* Remove dead code `common-organization.ts`
This commit is contained in:
wxiaoguang authored and GitHub committed 2026-10-16 20:02:11 +08:00
1 parent a25d1d77eb
commit 2fe74d3cdd
17 files changed
+89 -101

No files matched your search

+13 -19
View File
@@ -1,19 +1,13 @@
import {toggleElem} from '../../utils/dom.ts';
import {queryElems, toggleElem} from '../../utils/dom.ts';
import {showFomanticModal} from '../../modules/fomantic/modal.ts';
import {submitFormFetchAction} from '../../modules/fetch-action.ts';
import {registerGlobalInitFunc} from '../../modules/observer.ts';
function nameHasScope(name: string): boolean {
return /.*[^/]\/[^/].*/.test(name);
}
export function initCompLabelEdit(pageSelector: string) {
const pageContent = document.querySelector<HTMLElement>(pageSelector);
if (!pageContent) return;
// for guest view, the modal is not available, the "labels" are read-only
const elModal = pageContent.querySelector<HTMLElement>('#issue-label-edit-modal');
if (!elModal) return;
function initLabelEditModal(elModal: HTMLElement) {
const elLabelId = elModal.querySelector<HTMLInputElement>('input[name="id"]')!;
const elNameInput = elModal.querySelector<HTMLInputElement>('.label-name-input')!;
const elExclusiveField = elModal.querySelector('.label-exclusive-input-field')!;
@@ -79,15 +73,15 @@ export function initCompLabelEdit(pageSelector: string) {
elModal.addEventListener('input', () => syncModalUi());
// theoretically, if the modal exists, the "new label" button should also exist, just in case it doesn't, use "?."
const elNewLabel = pageContent.querySelector<HTMLElement>('.ui.button.new-label');
elNewLabel?.addEventListener('click', () => showLabelEditModal(elNewLabel));
const elNewLabel = document.querySelector<HTMLElement>('.ui.button.new-label')!;
elNewLabel.addEventListener('click', () => showLabelEditModal(elNewLabel));
const elEditLabelButtons = pageContent.querySelectorAll<HTMLElement>('.edit-label-button');
for (const btn of elEditLabelButtons) {
btn.addEventListener('click', (e) => {
e.preventDefault();
showLabelEditModal(btn);
});
}
queryElems(document, '.edit-label-button', (btn) => btn.addEventListener('click', (e) => {
e.preventDefault();
showLabelEditModal(btn);
}));
}
export function initCompLabelEdit() {
registerGlobalInitFunc('initLabelEditModal', initLabelEditModal);
}