Skip to content

Commit

Permalink
Load citation JS only when needed (#29855)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
silverwind and GiteaBot authored Mar 17, 2024
1 parent c20b568 commit 4b1c886
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
4 changes: 4 additions & 0 deletions web_src/css/modules/animations.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
opacity: 0.3;
}

.button.is-loading > * {
opacity: 0;
}

.is-loading::after {
content: "";
position: absolute;
Expand Down
45 changes: 26 additions & 19 deletions web_src/js/features/citation.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,35 @@ export async function initCitationFileCopyContent() {
$citationCopyApa.toggleClass('primary', !isBibtex);
};

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

$citationCopyApa.on('click', () => {
localStorage.setItem('citation-copy-format', 'apa');
updateUi();
});
$citationCopyBibtex.on('click', () => {
localStorage.setItem('citation-copy-format', 'bibtex');
updateUi();
});
try {
try {
await initInputCitationValue($citationCopyApa, $citationCopyBibtex);
} catch (e) {
console.error(`initCitationFileCopyContent error: ${e}`, e);
return;
}
updateUi();

$inputContent.on('click', () => {
$inputContent.trigger('select');
});
$citationCopyApa.on('click', () => {
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');
});
}

0 comments on commit 4b1c886

Please sign in to comment.