Hello,
I'm a newbie in javascript and I'm using the Adam Crymble's tutorial
to write a translator for "Doctrinal" (
http://www.doctrinal.fr/
doctrinal/ - password needed unfortunately, I can access it only from
my University)
I need to reformat author names: I have to check if there is one
author and to reverse the order last name/first name.
My script is ok for single author. However I don't find the solution
for multiple author.
The syntax seems ok but I might been mistaken on the regexp...
Authors are separated by a <br> and first name/last name by a comma
and a white space (", ").
Thank you so much if you can have a look on my code: it is so
frustrating after hours.
if (itemTypes["Auteur(s)"]) {
var author = itemTypes["Auteur(s)"];
if (author.match(/\s{2}/)) {
var authors = author.split(/\s{2}/);
for (j = authors.length-1; j>-1; j--) {
var words = new Array();
words[j] = authors[j].split(", ");
var authorFixed = '';
for (i = words[j].length-1; i > -1; i--) {
authorFixed = authorFixed + words[i] + ' ';
}
for (var i in authors) {
newItem.creators.push(Zotero.Utilities.cleanAuthor(authorFixed
[i], 'author'));
}
}
} else {
var authorName = itemTypes["Auteur(s)"];
var words = authorName.split(", ");
var authorFixed = '';
for (i = words.length-1; i > -1; i--) {
authorFixed = authorFixed + words[i] + ' ';
}
newItem.creators.push(Zotero.Utilities.cleanAuthor(authorFixed,
'author'));
}