Skip to content

Commit

Permalink
Show all authors in citation modal window
Browse files Browse the repository at this point in the history
Fixes #2152
  • Loading branch information
robyngit committed Jul 10, 2023
1 parent 8462948 commit e16d626
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
3 changes: 0 additions & 3 deletions src/js/models/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
48 changes: 41 additions & 7 deletions src/js/views/CitationView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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",
},
},
},

/**
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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 "";

Expand All @@ -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(", & ");
Expand Down
5 changes: 4 additions & 1 deletion src/js/views/citations/CitationModalView.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ define([
* @default "apa"
* @see {@link CitationView#styles}
*/
style: "apa",
style: "apaAllAuthors",

/**
* The events this view will listen for. See
Expand Down Expand Up @@ -191,6 +191,9 @@ define([
}
},

/**
* Insert the citation view into the modal
*/
insertCitation: function () {
const container = this.citationContainer;
if (!container) return;
Expand Down

0 comments on commit e16d626

Please sign in to comment.