mirror of https://github.com/go-gitea/gitea.git
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>
This commit is contained in:
parent
c20b56815d
commit
4b1c88628a
|
@ -13,6 +13,10 @@
|
||||||
opacity: 0.3;
|
opacity: 0.3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.button.is-loading > * {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.is-loading::after {
|
.is-loading::after {
|
||||||
content: "";
|
content: "";
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
|
|
@ -40,28 +40,35 @@ export async function initCitationFileCopyContent() {
|
||||||
$citationCopyApa.toggleClass('primary', !isBibtex);
|
$citationCopyApa.toggleClass('primary', !isBibtex);
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
$('#cite-repo-button').on('click', async (e) => {
|
||||||
await initInputCitationValue($citationCopyApa, $citationCopyBibtex);
|
const dropdownBtn = e.target.closest('.ui.dropdown.button');
|
||||||
} catch (e) {
|
dropdownBtn.classList.add('is-loading');
|
||||||
console.error(`initCitationFileCopyContent error: ${e}`, e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
updateUi();
|
|
||||||
|
|
||||||
$citationCopyApa.on('click', () => {
|
try {
|
||||||
localStorage.setItem('citation-copy-format', 'apa');
|
try {
|
||||||
updateUi();
|
await initInputCitationValue($citationCopyApa, $citationCopyBibtex);
|
||||||
});
|
} catch (e) {
|
||||||
$citationCopyBibtex.on('click', () => {
|
console.error(`initCitationFileCopyContent error: ${e}`, e);
|
||||||
localStorage.setItem('citation-copy-format', 'bibtex');
|
return;
|
||||||
updateUi();
|
}
|
||||||
});
|
updateUi();
|
||||||
|
|
||||||
$inputContent.on('click', () => {
|
$citationCopyApa.on('click', () => {
|
||||||
$inputContent.trigger('select');
|
localStorage.setItem('citation-copy-format', 'apa');
|
||||||
});
|
updateUi();
|
||||||
|
});
|
||||||
|
$citationCopyBibtex.on('click', () => {
|
||||||
|
localStorage.setItem('citation-copy-format', 'bibtex');
|
||||||
|
updateUi();
|
||||||
|
});
|
||||||
|
|
||||||
|
$inputContent.on('click', () => {
|
||||||
|
$inputContent.trigger('select');
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
dropdownBtn.classList.remove('is-loading');
|
||||||
|
}
|
||||||
|
|
||||||
$('#cite-repo-button').on('click', () => {
|
|
||||||
$('#cite-repo-modal').modal('show');
|
$('#cite-repo-modal').modal('show');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue