mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-09-30 22:56:05 +00:00
merge commit: refactor init & clearing of panel forms without jQuery (#9062)
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9062 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
This commit is contained in:
commit
f9f50ac382
5 changed files with 62 additions and 39 deletions
|
@ -5,7 +5,7 @@ import {createDropzone} from './dropzone.js';
|
|||
import {showGlobalErrorMessage} from '../bootstrap.js';
|
||||
import {handleGlobalEnterQuickSubmit} from './comp/QuickSubmit.js';
|
||||
import {svg} from '../svg.js';
|
||||
import {hideElem, showElem, toggleElem, initSubmitEventPolyfill, submitEventSubmitter} from '../utils/dom.js';
|
||||
import {hideElem, showElem, toggleElem, resetForms, initSubmitEventPolyfill, submitEventSubmitter} from '../utils/dom.js';
|
||||
import {htmlEscape} from 'escape-goat';
|
||||
import {showTemporaryTooltip} from '../modules/tippy.js';
|
||||
import {confirmModal} from './comp/ConfirmModal.js';
|
||||
|
@ -477,38 +477,48 @@ 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) => {
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$('.show-panel').on('click', function (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')) {
|
||||
toggleElem(sel);
|
||||
} else {
|
||||
showElem(sel);
|
||||
document.addEventListener('click', (e) => {
|
||||
if (e.target.matches('form button.ui.cancel.button')) {
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
$('.hide-panel').on('click', function (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');
|
||||
if (sel) {
|
||||
hideElem($(sel));
|
||||
return;
|
||||
}
|
||||
sel = this.getAttribute('data-panel-closest');
|
||||
if (sel) {
|
||||
hideElem($(this).closest(sel));
|
||||
return;
|
||||
}
|
||||
// should never happen, otherwise there is a bug in code
|
||||
showErrorToast('Nothing to hide');
|
||||
});
|
||||
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 = e.currentTarget.getAttribute('data-panel');
|
||||
if (e.currentTarget.classList.contains('toggle')) {
|
||||
toggleElem(sel);
|
||||
} else {
|
||||
showElem(sel);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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 = e.currentTarget.getAttribute('data-panel');
|
||||
if (sel) {
|
||||
const element = document.querySelector(sel);
|
||||
hideElem(element);
|
||||
resetForms(element);
|
||||
return;
|
||||
}
|
||||
sel = e.currentTarget.getAttribute('data-panel-closest');
|
||||
if (sel) {
|
||||
const element = e.currentTarget.closest(sel);
|
||||
hideElem(element);
|
||||
resetForms(element);
|
||||
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