Backport #28433 by wxiaoguang Fix #28226 Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
96d3fcf179
commit
5e2bae7716
1 changed files with 11 additions and 4 deletions
|
@ -2,7 +2,7 @@ import $ from 'jquery';
|
||||||
|
|
||||||
const {pageData} = window.config;
|
const {pageData} = window.config;
|
||||||
|
|
||||||
const initInputCitationValue = async ($citationCopyApa, $citationCopyBibtex) => {
|
async function initInputCitationValue($citationCopyApa, $citationCopyBibtex) {
|
||||||
const [{Cite, plugins}] = await Promise.all([
|
const [{Cite, plugins}] = await Promise.all([
|
||||||
import(/* webpackChunkName: "citation-js-core" */'@citation-js/core'),
|
import(/* webpackChunkName: "citation-js-core" */'@citation-js/core'),
|
||||||
import(/* webpackChunkName: "citation-js-formats" */'@citation-js/plugin-software-formats'),
|
import(/* webpackChunkName: "citation-js-formats" */'@citation-js/plugin-software-formats'),
|
||||||
|
@ -19,9 +19,9 @@ const initInputCitationValue = async ($citationCopyApa, $citationCopyBibtex) =>
|
||||||
const bibtexOutput = citationFormatter.format('bibtex', {lang});
|
const bibtexOutput = citationFormatter.format('bibtex', {lang});
|
||||||
$citationCopyBibtex.attr('data-text', bibtexOutput);
|
$citationCopyBibtex.attr('data-text', bibtexOutput);
|
||||||
$citationCopyApa.attr('data-text', apaOutput);
|
$citationCopyApa.attr('data-text', apaOutput);
|
||||||
};
|
}
|
||||||
|
|
||||||
export function initCitationFileCopyContent() {
|
export async function initCitationFileCopyContent() {
|
||||||
const defaultCitationFormat = 'apa'; // apa or bibtex
|
const defaultCitationFormat = 'apa'; // apa or bibtex
|
||||||
|
|
||||||
if (!pageData.citationFileContent) return;
|
if (!pageData.citationFileContent) return;
|
||||||
|
@ -39,7 +39,14 @@ export function initCitationFileCopyContent() {
|
||||||
$citationCopyBibtex.toggleClass('primary', isBibtex);
|
$citationCopyBibtex.toggleClass('primary', isBibtex);
|
||||||
$citationCopyApa.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', () => {
|
$citationCopyApa.on('click', () => {
|
||||||
localStorage.setItem('citation-copy-format', 'apa');
|
localStorage.setItem('citation-copy-format', 'apa');
|
||||||
|
|
Loading…
Add table
Reference in a new issue