Load citation JS only when needed (#29855)

Previously, the citation js would load every time when opening a citable
repo. Now it only loads when the user clicks the button for it. The
loading state is representend with a spinner on the button:

<img width="83" alt="Screenshot 2024-03-17 at 00 25 13"
src="https://github.com/go-gitea/gitea/assets/115237/29649089-13f3-4974-ab81-e12c0f8e651f">

Diff ist best viewed with whitespace hidden.

---------

Co-authored-by: Giteabot <teabot@gitea.io>
(cherry picked from commit 4b1c88628a6856e533ff10d346ca5bd73ce952b3)
This commit is contained in:
silverwind 2024-03-17 11:04:59 +01:00 committed by Earl Warren
parent f4ed953b1b
commit f2fc2dcfc9
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: 0579CB2928A78A00
2 changed files with 30 additions and 19 deletions

View file

@ -13,6 +13,10 @@
opacity: 0.3;
}
.button.is-loading > * {
opacity: 0;
}
.is-loading::after {
content: "";
position: absolute;

View file

@ -40,6 +40,11 @@ export async function initCitationFileCopyContent() {
$citationCopyApa.toggleClass('primary', !isBibtex);
};
$('#cite-repo-button').on('click', async (e) => {
const dropdownBtn = e.target.closest('.ui.dropdown.button');
dropdownBtn.classList.add('is-loading');
try {
try {
await initInputCitationValue($citationCopyApa, $citationCopyBibtex);
} catch (e) {
@ -60,8 +65,10 @@ export async function initCitationFileCopyContent() {
$inputContent.on('click', () => {
$inputContent.trigger('select');
});
} finally {
dropdownBtn.classList.remove('is-loading');
}
$('#cite-repo-button').on('click', () => {
$('#cite-repo-modal').modal('show');
});
}