Last active
September 9, 2016 23:56
-
-
Save akira-okumura/a595c7e8f97a9216ddb7b2f7e140ab56 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function make_preference_panel() { | |
html = '<strong>Name Style</strong> <form>' + | |
'<input type="radio" name="long_short" onChange="author_list()" id="long" value="long">Use full name ' + | |
'<input type="radio" name="long_short" onChange="author_list()" id="short" value="short" checked="checked">Use initial' + | |
'</form><br>'; | |
html += '<strong>Journal Style</strong> <form>' + | |
'<input type="radio" name="style" onChange="author_list()" id="HTML" value="HTML" checked="checked">HTML ' + | |
'<input type="radio" name="style" onChange="author_list()" id="PoS" value="PoS">PoS ' + | |
'<input type="radio" name="style" onChange="author_list()" id="AIP" value="AIP">AIP' + | |
'</form><br>'; | |
tables = document.getElementsByTagName("table"); | |
author_table = tables[0].getElementsByTagName("tr"); | |
ths = author_table[0].getElementsByTagName("th"); | |
html += '<strong>Categories</strong> <form name="category">'; | |
for (i = 4; i < ths.length - 3; i++) { | |
cat = ths[i].innerHTML; | |
html += '<input type="checkbox" onChange="author_list()" value="' + cat + '">' + cat + ' '; | |
} | |
html += '</form><br>'; | |
document.getElementById("Preference_Panel").innerHTML = html; | |
} | |
function author_list() { | |
tables = document.getElementsByTagName("table"); | |
author_table = tables[0].getElementsByTagName("tr"); | |
affiliation_table = tables[2].getElementsByTagName("tr"); | |
author2affiliation = {}; | |
shortaff2longaff_address = {}; | |
affiliation_indices = []; | |
for (i = 1; i < author_table.length; i++) { | |
tds = author_table[i].getElementsByTagName("td"); | |
fullname = tds[0].innerHTML; | |
shortname = tds[1].innerHTML; | |
affiliations = tds[2].innerHTML; | |
status = tds[3].innerHTML; | |
/* GEPI and LUTH members use the single address */ | |
affiliations = affiliations.replace("GEPI", "Paris"); | |
affiliations = affiliations.replace("LUTH", "Paris"); | |
/* There are some person who don't provides their short names */ | |
if (shortname == "") { | |
sp = fullname.split(", "); | |
shortname = sp[0] + ", " + sp[1][0] + "."; | |
} | |
i_am_on_the_list = false; | |
for (j = 0; j < document.category.elements.length; j++) { | |
if (document.category.elements[j].checked && tds[j + 4].innerHTML != "") { | |
i_am_on_the_list = true; | |
} | |
} | |
if (!i_am_on_the_list) continue; | |
if (document.getElementById("long").checked) { | |
author2affiliation[fullname] = affiliations; | |
} else { | |
author2affiliation[shortname] = affiliations; | |
} | |
} | |
for (i = 1; i < affiliation_table.length; i++) { | |
tds = affiliation_table[i].getElementsByTagName("td"); | |
shortname = tds[0].innerHTML; | |
affiliation = tds[1].innerHTML; | |
address = tds[2].innerHTML; | |
shortaff2longaff_address[shortname] = [affiliation, address]; | |
} | |
sorted_author_keys = []; | |
for(key in author2affiliation) { | |
sorted_author_keys.push(key); | |
} | |
sorted_author_keys.sort(); | |
output = ""; | |
if (document.getElementById("HTML").checked) { | |
journal = "HTML"; | |
} else if (document.getElementById("PoS").checked) { | |
journal = "PoS"; | |
} else if (document.getElementById("AIP").checked) { | |
journal = "AIP"; | |
} | |
if(journal == "PoS"){ | |
output += "\\author{"; | |
} else if(journal == "AIP"){ | |
output += ""; | |
} else if(journal == "HTML"){ | |
output += ""; | |
} | |
for(i = 0; i < sorted_author_keys.length; i++){ | |
name = sorted_author_keys[i]; | |
affs = author2affiliation[name].split(";"); | |
for(j = 0; j < affs.length; j++){ | |
if(affiliation_indices.indexOf(affs[j]) < 0){ | |
affiliation_indices.push(affs[j]); | |
} | |
} | |
last = name.split(", ")[0]; | |
first = name.split(", ")[1]; | |
if (journal == "AIP") { | |
output += "\\author["; | |
for(j = 0; j < affs.length; j++){ | |
idx = affiliation_indices.indexOf(affs[j]); | |
output += "aff" + (idx + 1) + ","; | |
} | |
if(output[output.length - 1] == ","){ | |
/* drop an unnecessary "," */ | |
output = output.slice(0, -1); | |
} | |
output += "]{" + first + "~" + last + "}\n"; | |
} else { | |
if (i != sorted_author_keys.length - 1){ | |
if(journal == "HTML"){ | |
output += first + String.fromCharCode(160) + last; | |
} else { | |
output += first + "~" + last; | |
} | |
} else { | |
if(journal == "HTML"){ | |
output += "and " + first + " " + last; | |
} else { | |
output += "and " + first + "~" + last; | |
} | |
} | |
} | |
if(journal == "PoS"){ | |
output += "$^{"; | |
} else if(journal == "AIP"){ | |
// do nothing | |
} else if(journal == "HTML"){ | |
output += "<sup><i>"; | |
} | |
for(j = 0; j < affs.length; j++){ | |
idx = affiliation_indices.indexOf(affs[j]); | |
if(journal != "AIP"){ | |
output += String.fromCharCode(97 + idx) + ","; | |
} | |
} | |
if(output[output.length - 1] == ","){ | |
/* drop an unnecessary "," */ | |
output = output.slice(0, -1); | |
} | |
if (i != sorted_author_keys.length - 1){ | |
if(journal == "PoS"){ | |
output += "}$, "; | |
} else if(journal == "AIP"){ | |
// do nothing | |
} else if(journal == "HTML"){ | |
output += "</i></sup>, "; | |
} | |
} else { | |
if(journal == "PoS"){ | |
output += "}$"; | |
} else if(journal == "AIP"){ | |
// do nothing | |
} else if(journal == "HTML"){ | |
output += "</i></sup>"; | |
} | |
} | |
} | |
if(journal == "PoS"){ | |
output += "\\\\\n"; | |
} else if(journal == "AIP"){ | |
// do nothing | |
} else if(journal == "HTML"){ | |
output += "<br>"; | |
} | |
for(i = 0; i < affiliation_indices.length; i++){ | |
affiliation = affiliation_indices[i]; | |
if(journal == "PoS"){ | |
output += "\\llap{$^" + String.fromCharCode(97 + i) + "$}"; | |
output += shortaff2longaff_address[affiliation][0] + ", "; | |
output += shortaff2longaff_address[affiliation][1] + "\\\\\n"; | |
} else if(journal == "AIP"){ | |
output += "\\affil[aff" + (i + 1) + "]{"; | |
output += shortaff2longaff_address[affiliation][0] + ", "; | |
output += shortaff2longaff_address[affiliation][1] + "}\n"; | |
} else if(journal == "HTML"){ | |
output += "<sup><i>" + String.fromCharCode(97 + i) + "</i></sup>"; | |
output += shortaff2longaff_address[affiliation][0] + ", "; | |
output += shortaff2longaff_address[affiliation][1] + "<br>"; | |
} | |
} | |
if(journal == "PoS"){ | |
output += "}\n"; | |
} else if(journal == "AIP"){ | |
// do nothing | |
} else if(journal == "HTML"){ | |
output += "<br>"; | |
} | |
if(journal == "HTML"){ | |
document.getElementById("Output").innerHTML = "<p>" + output + "</p>"; | |
} else { | |
output = output.split("ü").join("\\\"{u}"); | |
output = output.split("é").join("\\'{e}"); | |
output = output.split("è").join("\\`{e}"); | |
document.getElementById("Output").innerHTML = "<pre>" + output + "</pre>"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment