Skip to content

Commit 4b1c886

Browse files
silverwindGiteaBot
andauthored
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 <[email protected]>
1 parent c20b568 commit 4b1c886

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

web_src/css/modules/animations.css

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
opacity: 0.3;
1414
}
1515

16+
.button.is-loading > * {
17+
opacity: 0;
18+
}
19+
1620
.is-loading::after {
1721
content: "";
1822
position: absolute;

web_src/js/features/citation.js

+26-19
Original file line numberDiff line numberDiff line change
@@ -40,28 +40,35 @@ export async function initCitationFileCopyContent() {
4040
$citationCopyApa.toggleClass('primary', !isBibtex);
4141
};
4242

43-
try {
44-
await initInputCitationValue($citationCopyApa, $citationCopyBibtex);
45-
} catch (e) {
46-
console.error(`initCitationFileCopyContent error: ${e}`, e);
47-
return;
48-
}
49-
updateUi();
43+
$('#cite-repo-button').on('click', async (e) => {
44+
const dropdownBtn = e.target.closest('.ui.dropdown.button');
45+
dropdownBtn.classList.add('is-loading');
5046

51-
$citationCopyApa.on('click', () => {
52-
localStorage.setItem('citation-copy-format', 'apa');
53-
updateUi();
54-
});
55-
$citationCopyBibtex.on('click', () => {
56-
localStorage.setItem('citation-copy-format', 'bibtex');
57-
updateUi();
58-
});
47+
try {
48+
try {
49+
await initInputCitationValue($citationCopyApa, $citationCopyBibtex);
50+
} catch (e) {
51+
console.error(`initCitationFileCopyContent error: ${e}`, e);
52+
return;
53+
}
54+
updateUi();
5955

60-
$inputContent.on('click', () => {
61-
$inputContent.trigger('select');
62-
});
56+
$citationCopyApa.on('click', () => {
57+
localStorage.setItem('citation-copy-format', 'apa');
58+
updateUi();
59+
});
60+
$citationCopyBibtex.on('click', () => {
61+
localStorage.setItem('citation-copy-format', 'bibtex');
62+
updateUi();
63+
});
64+
65+
$inputContent.on('click', () => {
66+
$inputContent.trigger('select');
67+
});
68+
} finally {
69+
dropdownBtn.classList.remove('is-loading');
70+
}
6371

64-
$('#cite-repo-button').on('click', () => {
6572
$('#cite-repo-modal').modal('show');
6673
});
6774
}

0 commit comments

Comments
 (0)