Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't show unnecessary citation JS error on UI #28433

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions web_src/js/features/citation.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import $ from 'jquery';

const {pageData} = window.config;

const initInputCitationValue = async ($citationCopyApa, $citationCopyBibtex) => {
async function initInputCitationValue($citationCopyApa, $citationCopyBibtex) {
const [{Cite, plugins}] = await Promise.all([
import(/* webpackChunkName: "citation-js-core" */'@citation-js/core'),
import(/* webpackChunkName: "citation-js-formats" */'@citation-js/plugin-software-formats'),
Expand All @@ -19,9 +19,9 @@ const initInputCitationValue = async ($citationCopyApa, $citationCopyBibtex) =>
const bibtexOutput = citationFormatter.format('bibtex', {lang});
$citationCopyBibtex.attr('data-text', bibtexOutput);
$citationCopyApa.attr('data-text', apaOutput);
};
}
silverwind marked this conversation as resolved.
Show resolved Hide resolved

export function initCitationFileCopyContent() {
export async function initCitationFileCopyContent() {
const defaultCitationFormat = 'apa'; // apa or bibtex

if (!pageData.citationFileContent) return;
Expand All @@ -39,7 +39,14 @@ export function initCitationFileCopyContent() {
$citationCopyBibtex.toggleClass('primary', isBibtex);
$citationCopyApa.toggleClass('primary', !isBibtex);
};
initInputCitationValue($citationCopyApa, $citationCopyBibtex).then(updateUi);

try {
await initInputCitationValue($citationCopyApa, $citationCopyBibtex);
} catch (e) {
console.error(`initCitationFileCopyContent error: ${e}`, e);
return;
}
updateUi();

$citationCopyApa.on('click', () => {
localStorage.setItem('citation-copy-format', 'apa');
Expand Down