From bfb22a58c417f157abddf2114f3ab904084a11cb Mon Sep 17 00:00:00 2001 From: silverwind Date: Sun, 17 Mar 2024 00:25:24 +0100 Subject: [PATCH 1/2] Load citation JS only when needed --- web_src/css/modules/animations.css | 4 +++ web_src/js/features/citation.js | 45 +++++++++++++++++------------- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/web_src/css/modules/animations.css b/web_src/css/modules/animations.css index d5ddc772f6cc5..5bfc090773c2d 100644 --- a/web_src/css/modules/animations.css +++ b/web_src/css/modules/animations.css @@ -13,6 +13,10 @@ opacity: 0.3; } +.button.is-loading > * { + opacity: 0; +} + .is-loading::after { content: ""; position: absolute; diff --git a/web_src/js/features/citation.js b/web_src/js/features/citation.js index 61f378f0f22b9..3a1b3d9b616fa 100644 --- a/web_src/js/features/citation.js +++ b/web_src/js/features/citation.js @@ -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 () => { + const moreBtn = document.getElementById('more-btn'); + moreBtn.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 { + moreBtn.classList.remove('is-loading'); + } - $('#cite-repo-button').on('click', () => { $('#cite-repo-modal').modal('show'); }); } From 19d190822a8bbea087afb064a14db1adf5484e41 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sun, 17 Mar 2024 10:04:41 +0100 Subject: [PATCH 2/2] use different selector --- web_src/js/features/citation.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/web_src/js/features/citation.js b/web_src/js/features/citation.js index 3a1b3d9b616fa..49992b225fdda 100644 --- a/web_src/js/features/citation.js +++ b/web_src/js/features/citation.js @@ -40,9 +40,9 @@ export async function initCitationFileCopyContent() { $citationCopyApa.toggleClass('primary', !isBibtex); }; - $('#cite-repo-button').on('click', async () => { - const moreBtn = document.getElementById('more-btn'); - moreBtn.classList.add('is-loading'); + $('#cite-repo-button').on('click', async (e) => { + const dropdownBtn = e.target.closest('.ui.dropdown.button'); + dropdownBtn.classList.add('is-loading'); try { try { @@ -66,7 +66,7 @@ export async function initCitationFileCopyContent() { $inputContent.trigger('select'); }); } finally { - moreBtn.classList.remove('is-loading'); + dropdownBtn.classList.remove('is-loading'); } $('#cite-repo-modal').modal('show');