'+printAuthorAPA6(entry.authors[i])+"";
if(i!==entry.authors.length-1)
{
html += ", ";
}
}
}
else if(entry.authors.length > 7)
{
for(var i=0;i<6;i++)
{
html += ''+printAuthorAPA6(entry.authors[i])+"" +", ";
}
html += ". . . "+''+printAuthorAPA6(entry.authors[entry.authors.length-1])+"";
}
return ""+html+" ";
}
function printBookTitleBookSection(entry)
{
if(!entry.hasOwnProperty("B"))
{
return "";
}
else
{
var title = entry["B"].trim();
return ""+title+" ";
}
}
/** @summary - print the doi
* */
function printConferenceInformation(entry)
{
if(!entry.hasOwnProperty("B"))
{
return "";
}
else
{
var conferenceName = entry["B"];
var html = ""+conferenceName+"";
if(entry.hasOwnProperty("C"))
{
var conferenceLocation = entry["C"];
html+=", "+conferenceLocation+". ";
}
else
{
html+=". ";
}
return ""+html+""
}
}
/** @summary - print the doi
* */
function printDOIAPA6(entry)
{
if(!entry.hasOwnProperty("R"))
{
return "";
}
else
{
var doi = entry["R"];
return ""+doi+"";
}
}
/** @summary -
**/
function printEditorsAPA6(entry)
{
if(!entry.hasOwnProperty("editors"))
{
return "";
}
else
{
if(!entry.hasOwnProperty("authors"))
{
var authors = undefined;
}
else
{
var authors = entry.authors.slice();
}
entry.authors = entry.editors.slice();
var html = printAuthorsAPA6(entry).replace("class=\"author","class=\"editor");
entry.authors = authors;
if(entry["editors"].length===1)
{
html+="(Ed.). ";
}
else if (entry["editors"].length>1)
{
html+="(Eds.). ";
}
return html;
}
}
/** @summary -
**/
function printEditorsConferenceProceedingsAPA6(entry)
{
return printEditorsAPA6(entry).slice(0,-2)+", ";
}
/** @summary -
**/
function printEditorsBookSection(entry)
{
return printEditorsAPA6(entry).slice(0,-2)+", ";
}
/** @summary - the function to print (i.e. generate adequate http-markup) entries according to the
* args parameters provided
* @param args.entries - Arrag of Entry objects (the handle/reference provided will not be modified)
* @param args.filters - Array of Strings with eval filters
* @param args.sortings - Array of sorting informations
**/
function printEntries(args)
{
// to contain the generated html
var html="";
// (0) validate for entries
if(!args.hasOwnProperty("entries"))
{
return "";
}
else
{
// we work on a shallow copy and leave the entries originals untouched
args.entries = args.entries.slice();
}
// (1) filter the entries
if(args.hasOwnProperty("filters"))
{
filterEntries(args);
}
//~ // (2) sort the entries
if(args.hasOwnProperty("sortings"))
{
//console.log("sortEntries");
sortEntries(args);
}
// (3) finally the printing of the entries
for(var i=0; i < args.entries.length ;i++)
{
var entry = args.entries[i];
html +=printEntry(entry);
}
return html;
}
/** @summary - the function to print a single entry (delegates to a specific funciton for the
* respective entry type)
**/
function printEntry(entry)
{
if(entry.hasOwnProperty("type"))
{
switch(entry.type)
{
case "Book":
return "BOOK"+printEntryBook(entry);
break;
case "Book Section":
return "BOOKSECTION"+printEntryBookSection(entry);
break;
case "Conference Proceedings":
case "Conference Paper":
return "CONFERENCE"+printEntryConference(entry);
break;
case "Edited Book":
return "EDITEDBOOK"+printEntryEditedBook(entry);
break;
case "Journal Article":
return "JOURNALARTICLE"+printEntryJournalArticle(entry);
break;
default:
return "GENERIC"+printEntryGeneric(entry);
}
}
else
{
return "GENERIC"+printEntryGeneric(entry);
}
return "";
}
/** @summary -
**/
function printEntryBook(entry)
{
return "" + printAuthorsAPA6(entry) + printYearAPA6(entry) +
printTitleAPA6(entry) + printPublisherInformationBook(entry) + "
";
}
/** @summary -
*
**/
function printEntryBookSection(entry)
{
return "" + printAuthorsAPA6(entry) +
printYearAPA6(entry) + printTitleAPA6(entry) + "In " +
printEditorsBookSection(entry) + printBookTitleBookSection(entry) +
"(pp. "+printPagesAPA6(entry)+"). " +
printPublisherInformationBook(entry) + printDOIAPA6(entry) + "
";
}
//~ %0 Conference Proceedings
//~ %A Authorfirstword, Authorsecondword
//~ %A Bditorfirstword, Bditorsecondword
//~ %D 2008
//~ %T Title
//~ %E Editorfirstword, Editorsecondword
//~ %E Bditorfirstword, Bditorsecondword
//~ %B Conference Name
//~ %C Conference Location
//~ %I Publisher
//~ %V Volume
//~ %P Pages
//~ %8 Date
//~ %! Title
//~ %1 Place Published
//~ %3 Proceedings Title
//~
//~
//~
//~ %0 Conference Paper
//~ %A Authorfirstword, Authorsecondword
//~ %A Buthorfirstword, Buthorsecondword
//~ %D 2009
//~ %T Title
//~ %E Editorfirstword, Editorsecondword
//~ %E Bditorfirstword, Bditorsecondword
//~ %B Conference Name
//~ %C Conference Location
//~ %I Publisher
//~ %V Volume
//~ %P pages
//~ %8 Date
//~ %1 Place Published
//~ %1 Place Published
//~ %I Publisher
// Conference Paper
// Coference Proceeding
//~ Author1Family, A. F., & Author2Family, A. F. (1999b). *Title of Conference Paper.* Paper presented at the Conference Name, New York.
//~ Author1Family, A. F., & Author2Family, A. F. (1999c, 13.December 2003).
//~ *Title of Conference Proceedings.* Paper presented at the Conference Name, New York.
// Author Surname, First Initial. Second Initial. (Year). Conference paper title.
// In Editor First Initial. Editor Surname (Ed.), *Proceedings Book Title* (pp. page range of paper).
// Place of Publication: Publisher.
// Armstrong, D. B., Fogarty, G. J., & Dingsdag, D. (2007). Scales measuring characteristics of small
// business information systems. In W-G. Tan (Ed.), *Proceedings of Research, Relevance and
// Rigour: Coming of age: 18th Australasian Conference on Information Systems* (pp. 163-171).
// Toowoomba, Australia: University of Southern Queensland.
//~ Author Surname, First Initial. Second Initial. (Year). Conference paper title. Paper
//~ presented at the Conference Title, Place, US state/country. Retrieved from URL
//~ Taylor, J. A. (2006). Assessment: a tool for development and engagement in the first
//~ year of university study. Paper presented at the Engaging Students: 9th Pacific Rim
//~ in Higher Education (FYHE) Conference, Griffith, Australia. Retrieved from
//~ http://www.fyhe.com.au/past_papers/2006/Papers/Taylor.pdf
/** @summary -
**/
function printEntryConference(entry)
{
// if there is a Title of the Proceedings, then it is a Proceeding
if(entry.hasOwnProperty("3"))
{
return "" + printAuthorsAPA6(entry) +
printYearAPA6(entry) + printTitleAPA6(entry) + "In " +
printEditorsConferenceProceedingsAPA6(entry) + printTitleConferenceProceedings(entry) +
"(pp. "+printPagesAPA6(entry)+"). " +
printPublisherInformationConferenceProceedings(entry) + printDOIAPA6(entry) + "
";
}
else
{
return "" + printAuthorsAPA6(entry) +
printYearAPA6(entry) + printTitleAPA6(entry) + "Paper presented at the " +
printConferenceInformation(entry) + printPaperURL(entry) + "
";
}
}
/** @summary -
**/
function printEntryEditedBook(entry)
{
return "" + printEditorsAPA6(entry) + printYearAPA6(entry) +
printTitleAPA6(entry) + printPublisherInformationBook(entry) + "
";
}
/** @summary -
**/
function printEntryGeneric(entry)
{
return "" + printAuthorsAPA6(entry) + printYearAPA6(entry) +
printTitleAPA6(entry) + printDOIAPA6(entry) + "
";
}
/** @summary -
* @example desired output:
* AnotherAuthor1Family, A. F., AnotherAuthor2Family, A. F., Miller, C., & Smith, C. (1999).
* Title of the article. *Journal Name*, *1*(2), 22-33. doi: doi:10.1371/journal.pbio.0020449.g001
**/
function printEntryJournalArticle(entry)
{
return "" +printAuthorsAPA6(entry) + printYearAPA6(entry) +
printTitleAPA6(entry) + printJournalInfoAPA6(entry) + printDOIAPA6(entry) + "
";
}
/** @summary - print th jounrals information in APA6 format
* */
function printJournalInfoAPA6(entry)
{
var html="";
// journal name
if(!entry.hasOwnProperty("B"))
{
return "";
}
else
{
var name = entry["B"].trim();
html+=" "+name+"";
// journal volume
if(entry.hasOwnProperty("V"))
{
html+=","
var volume = entry["V"].trim();
html+=" "+volume+"";
// journal issue
if(entry.hasOwnProperty("N"))
{
var issue = entry["N"].trim();
html+="("+issue+")";
}
}
if(entry.hasOwnProperty("P"))
{
html+=", "+printPagesAPA6(entry);
}
// the trailing punctuation
html+=".";
return ""+html+" ";
}
}
/** @summary - print in APA6 format the pages information
* */
function printPagesAPA6(entry)
{
if(!entry.hasOwnProperty("P"))
{
return "";
}
else
{
return""+entry["P"].replace(" ","")+"";
}
}
/** @summary - print the doi
* */
function printPaperURL(entry)
{
if(!entry.hasOwnProperty("U"))
{
return "";
}
else
{
var PaperURL = entry["U"];
return "Retrieved from "+PaperURL+"";
}
}
//~ %C Place Published
//~ %I Publisher
/** @summary - print in APA6 format the pages information
* */
function printPublisherInformationBook(entry)
{
var html="";
if(entry.hasOwnProperty("C"))
{
var place = entry["C"].trim();
html+=""+place+"";
}
if(entry.hasOwnProperty("I"))
{
var publisher = entry["I"].trim();
if(entry.hasOwnProperty("C"))
{
html+=": ";
}
html+=""+publisher+"";
}
if(entry.hasOwnProperty("C") || entry.hasOwnProperty("I"))
{
return ""+html+"";
}
}
//~ %1 Place Published
//~ %I Publisher
/** @summary - print in APA6 format the pages information
* */
function printPublisherInformationConferenceProceedings(entry)
{
var html="";
if(entry.hasOwnProperty("1"))
{
var place = entry["1"].trim();
html+=""+place+"";
}
if(entry.hasOwnProperty("I"))
{
var publisher = entry["I"].trim();
if(entry.hasOwnProperty("1"))
{
html+=": ";
}
html+=""+publisher+"";
}
if(entry.hasOwnProperty("1") || entry.hasOwnProperty("I"))
{
return ""+html+"";
}
}
/** @summary - print the title in APA6 format
* @description - APA6 format puts the title as it is and ends it with a "." (point). If the title
* already has a punctuation the original title's punctuation is kept.
*
* */
function printTitleAPA6(entry)
{
if(!entry.hasOwnProperty("T"))
{
return "";
}
else
{
var title = entry["T"].trim();
// if the title does not have a "."/"!"/"?" already, then add a "."
if(title.slice(-1) !== "?" && title.slice(-1) !== "." && title.slice(-1) !== "!")
{
title+=".";
}
return ""+title+" ";
}
}
function printTitleConferenceProceedings(entry)
{
if(!entry.hasOwnProperty("3"))
{
return "";
}
else
{
var title = entry["3"].trim();
return ""+title+" ";
}
}
/** @summary - print the year in APA6 format
* @description - APA6 the year is print in a format like those
* (1999).
* (2009).
* or
* (n.d.). if no date is known
* for several publications of the same authors an enumaration by alphabetic characters is used
* (1999a).
* (1999b).
* TODO [ ] this feature is not yet implemented
* */
function printYearAPA6(entry)
{
var html=""
if(!entry.hasOwnProperty("D"))
{
html+= "(n.d.).";
}
else
{
html+= "("+entry["D"]+").";
}
return ""+html+" ";
}
/** @summary - sort the entries based on 2-tuples
* */
function sortEntries(args)
{
// (0) validity checking
if(!args.hasOwnProperty("entries"))
{
return false;
}
if(!args.hasOwnProperty("sortings"))
{
return false;
}
// (1) the actual sorting
var sortings=args.sortings;
var entries=args.entries;
//~ var sortings=[['["D"]','asc'], // sort for the year(="D") ascendingly
//~ ['["authors"].join(",")','desc'] // sort for the authors descendingly
//~ ];
entries.sort(function(a,b){
for(var i=0; i < sortings.length ;i++)
{
// console.log("comparison:"+JSON.stringify(sorting)+" a="+JSON.stringify(a)+" b="+JSON.stringify(b));
//console.log("comparison:"+JSON.stringify(sorting)+" a="+JSON.stringify(a)+" b="+JSON.stringify(b));
//~ console.log("comparison:"+JSON.stringify(sorting)+" aComp="+aComp+" bComp="+bComp);
var sorting = sortings[i];
var aComp = eval("a"+sorting[0]);
var bComp = eval("b"+sorting[0]);
if( aComp > bComp )
{
if(sorting[1].toLowerCase()==="asc")
{
return 1;
}
else if(sorting[1].toLowerCase()==="desc")
{
return -1;
}
}
else if(aComp < bComp)
{
if(sorting[1].toLowerCase()==="asc")
{
return -1;
}
else if(sorting[1].toLowerCase()==="desc")
{
return 1;
}
}
}
// returing 0 means that the entries are equal in position
return 0;
});
return entries;
}
//main();