From e16d626516718fc236bd02ef02b028aa8b38cbc1 Mon Sep 17 00:00:00 2001 From: Robyn Thiessen-Bock Date: Mon, 10 Jul 2023 12:41:17 -0400 Subject: [PATCH] Show all authors in citation modal window Fixes #2152 --- src/js/models/Search.js | 3 -- src/js/views/CitationView.js | 48 ++++++++++++++++++--- src/js/views/citations/CitationModalView.js | 5 ++- 3 files changed, 45 insertions(+), 11 deletions(-) diff --git a/src/js/models/Search.js b/src/js/models/Search.js index d70f88aec..86dcf18ff 100644 --- a/src/js/models/Search.js +++ b/src/js/models/Search.js @@ -960,11 +960,8 @@ define(["jquery", "underscore", "backbone", "models/SolrResult", "collections/Fi term = term.replace(/%2F/g, "%5C%2F"); if (escapeSquareBrackets) { - console.log("Escaping square brackets in term: ", term); term = term.replace(/%5B/g, "%5C%5B"); term = term.replace(/%5D/g, "%5C%5D"); - } else { - console.log("Not escaping square brackets in term: ", term); } return term; diff --git a/src/js/views/CitationView.js b/src/js/views/CitationView.js index 7c620c6dc..672458045 100644 --- a/src/js/views/CitationView.js +++ b/src/js/views/CitationView.js @@ -111,8 +111,7 @@ define([ */ /** - * The format and layout options that are available for this view. The - * `default` option is used when no format is specified in the options. + * The format and layout options that are available for this view. * @type {Object} * @property {CitationView#StyleDefinition} styleName - Each property in * the styles object maps a style name to a StyleOption object. @@ -131,6 +130,18 @@ define([ render: "renderAPAInText", }, }, + apaAllAuthors: { + full: { + template: _.template(APATemplate), + archivedTemplate: _.template(ArchivedTemplate), + render: "renderAPAAllAuthors", + }, + inText: { + template: _.template(APAInTextTemplate), + archivedTemplate: _.template(InTextArchivedTemplate), + render: "renderAPAInText", + }, + }, }, /** @@ -379,11 +390,16 @@ define([ * @param {Object} options - The options to pass to the template. * @param {function} template - The template associated with this style, * or it's archive template if the object is archived and not indexed. + * @param {number} [maxAuthors=20] - The maximum number of authors to + * display. If there are more than this number of authors, then the + * remaining authors will be replaced with an ellipsis. The default is 20 + * since that is the maximum that APA allows. Set to a falsy value to + * display all authors. * @since 2.23.0 */ - renderAPA: function (options, template) { + renderAPA: function (options, template, maxAuthors=20) { // Format the authors for display - options.origin = this.CSLNamesToAPA(options.originArray); + options.origin = this.CSLNamesToAPA(options.originArray, maxAuthors); this.el.innerHTML = template(options); // If there are citationMetadata, as well as an element in the current // template where they should be inserted, then show them inline. @@ -404,6 +420,17 @@ define([ this.el.innerHTML = template(options); }, + /** + * Render a complete APA style citation with all authors listed. + * @param {Object} options - The options to pass to the template. + * @param {function} template - The template associated with this style, + * or it's archive template if the object is archived and not indexed. + * @since x.x.x + */ + renderAPAAllAuthors: function (options, template) { + this.renderAPA(options, template, false); + }, + /** * Render the list of in-text citations that cite the main citation. This * function will find the element in the template that is designated as @@ -481,10 +508,15 @@ define([ * string for display in an APA citation. * @param {object[]} authors - An array of CSL JSON name objects * @returns {string} The formatted author string or an empty string if - * there are no authors + * there are no authors + * @param {number} [maxAuthors=20] - The maximum number of authors to + * display. If there are more than this number of authors, then the + * remaining authors will be replaced with an ellipsis. The default is 20 + * since that is the maximum that APA allows. Set to a falsy value to + * display all authors. * @since 2.23.0 */ - CSLNamesToAPA: function (authors) { + CSLNamesToAPA: function (authors, maxAuthors=20) { // Format authors as a proper APA style citation: if (!authors) return ""; @@ -496,9 +528,11 @@ define([ authors = authors.map(this.CSLNameToFullNameStr); const numAuthors = authors.length; - const maxAuthors = 20; const lastAuthor = authors[numAuthors - 1]; + // Set maxAuthors to the number of authors if it is a falsy value. + maxAuthors = maxAuthors || numAuthors; + if (numAuthors === 1) return authors[0]; // Two authors: Separate author names with a comma. Use the ampersand. if (numAuthors === 2) return authors.join(", & "); diff --git a/src/js/views/citations/CitationModalView.js b/src/js/views/citations/CitationModalView.js index cea3dfb9a..a223a4900 100644 --- a/src/js/views/citations/CitationModalView.js +++ b/src/js/views/citations/CitationModalView.js @@ -54,7 +54,7 @@ define([ * @default "apa" * @see {@link CitationView#styles} */ - style: "apa", + style: "apaAllAuthors", /** * The events this view will listen for. See @@ -191,6 +191,9 @@ define([ } }, + /** + * Insert the citation view into the modal + */ insertCitation: function () { const container = this.citationContainer; if (!container) return;