mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-09-30 06:35:59 +00:00
chore: Refactor global buttons init
This commit rewrites `initGlobalButtons()` to remove jQuery usage.
This commit is contained in:
parent
9162c82150
commit
654c02a8dd
1 changed files with 35 additions and 29 deletions
|
@ -481,38 +481,44 @@ export function initGlobalButtons() {
|
|||
// There are many "cancel button" elements in modal dialogs, Fomantic UI expects they are button-like elements but never submit a form.
|
||||
// However, Gitea misuses the modal dialog and put the cancel buttons inside forms, so we must prevent the form submission.
|
||||
// There are a few cancel buttons in non-modal forms, and there are some dynamically created forms (eg: the "Edit Issue Content")
|
||||
$(document).on('click', 'form button.ui.cancel.button', (e) => {
|
||||
document.addEventListener('click', (e) => {
|
||||
if (e.target.matches('form button.ui.cancel.button')) {
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
$('.show-panel').on('click', function (e) {
|
||||
for (const showPanelButton of document.querySelectorAll('.show-panel')) {
|
||||
showPanelButton.addEventListener('click', (e) => {
|
||||
// a '.show-panel' element can show a panel, by `data-panel="selector"`
|
||||
// if it has "toggle" class, it toggles the panel
|
||||
e.preventDefault();
|
||||
const sel = this.getAttribute('data-panel');
|
||||
if (this.classList.contains('toggle')) {
|
||||
const sel = e.currentTarget.getAttribute('data-panel');
|
||||
if (e.currentTarget.classList.contains('toggle')) {
|
||||
toggleElem(sel);
|
||||
} else {
|
||||
showElem(sel);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$('.hide-panel').on('click', function (e) {
|
||||
for (const hidePanelButton of document.querySelectorAll('.hide-panel')) {
|
||||
hidePanelButton.addEventListener('click', (e) => {
|
||||
// a `.hide-panel` element can hide a panel, by `data-panel="selector"` or `data-panel-closest="selector"`
|
||||
e.preventDefault();
|
||||
let sel = this.getAttribute('data-panel');
|
||||
let sel = e.currentTarget.getAttribute('data-panel');
|
||||
if (sel) {
|
||||
hideElem($(sel));
|
||||
hideElem(sel);
|
||||
return;
|
||||
}
|
||||
sel = this.getAttribute('data-panel-closest');
|
||||
sel = e.currentTarget.getAttribute('data-panel-closest');
|
||||
if (sel) {
|
||||
hideElem($(this).closest(sel));
|
||||
hideElem(e.currentTarget.closest(sel));
|
||||
return;
|
||||
}
|
||||
// should never happen, otherwise there is a bug in code
|
||||
showErrorToast('Nothing to hide');
|
||||
});
|
||||
}
|
||||
|
||||
initGlobalShowModal();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue