Upgrade citeproc-js to version 1.0.350

This commit is contained in:
Frank Bennett 2012-06-29 06:18:31 +09:00 committed by Simon Kornblith
parent a882818082
commit 4901c9db0b

View file

@ -57,7 +57,7 @@ if (!Array.indexOf) {
}; };
} }
var CSL = { var CSL = {
PROCESSOR_VERSION: "1.0.349", PROCESSOR_VERSION: "1.0.350",
STATUTE_SUBDIV_GROUPED_REGEX: /((?:^| )(?:art|ch|Ch|subch|p|pp|para|subpara|pt|r|sec|subsec|Sec|sch|tit)\.)/g, STATUTE_SUBDIV_GROUPED_REGEX: /((?:^| )(?:art|ch|Ch|subch|p|pp|para|subpara|pt|r|sec|subsec|Sec|sch|tit)\.)/g,
STATUTE_SUBDIV_PLAIN_REGEX: /(?:(?:^| )(?:art|ch|Ch|subch|p|pp|para|subpara|pt|r|sec|subsec|Sec|sch|tit)\.)/, STATUTE_SUBDIV_PLAIN_REGEX: /(?:(?:^| )(?:art|ch|Ch|subch|p|pp|para|subpara|pt|r|sec|subsec|Sec|sch|tit)\.)/,
STATUTE_SUBDIV_STRINGS: { STATUTE_SUBDIV_STRINGS: {
@ -2919,6 +2919,29 @@ CSL.Engine.prototype.setLangPrefsForCites = function (params) {
} }
}; };
CSL.Engine.prototype.setLangPrefsForCiteAffixes = function (affixList) { CSL.Engine.prototype.setLangPrefsForCiteAffixes = function (affixList) {
if (affixList && affixList.length === 30) {
var affixes = this.opt.citeAffixes;
var count = 0;
var settings = ["persons", "institutions", "titles", "publishers", "places"];
var forms = ["orig", "translit", "translat"];
for (var i = 0, ilen = settings.length; i < ilen; i += 1) {
for (var j = 0, jlen = forms.length; j < jlen; j += 1) {
var value = affixList[count];
if (!value) {
value = "";
}
affixes[settings[i]]["locale-" + forms[j]].prefix = value;
count += 1;
var value = affixList[count];
if (!value) {
value = "";
}
affixes[settings[i]]["locale-" + forms[j]].suffix = value;
count += 1;
}
}
this.opt.citeAffixes = affixes;
}
}; };
CSL.Engine.prototype.setAutoVietnameseNamesOption = function (arg) { CSL.Engine.prototype.setAutoVietnameseNamesOption = function (arg) {
if (arg) { if (arg) {
@ -2952,6 +2975,78 @@ CSL.Engine.Opt = function () {
this["locale-sort"] = []; this["locale-sort"] = [];
this["locale-translit"] = []; this["locale-translit"] = [];
this["locale-translat"] = []; this["locale-translat"] = [];
this.citeAffixes = {
persons:{
"locale-orig":{
prefix:"",
suffix:""
},
"locale-translit":{
prefix:"",
suffix:""
},
"locale-translat":{
prefix:"",
suffix:""
}
},
institutions:{
"locale-orig":{
prefix:"",
suffix:""
},
"locale-translit":{
prefix:"",
suffix:""
},
"locale-translat":{
prefix:"",
suffix:""
}
},
titles:{
"locale-orig":{
prefix:"",
suffix:""
},
"locale-translit":{
prefix:"",
suffix:""
},
"locale-translat":{
prefix:"",
suffix:""
}
},
publishers:{
"locale-orig":{
prefix:"",
suffix:""
},
"locale-translit":{
prefix:"",
suffix:""
},
"locale-translat":{
prefix:"",
suffix:""
}
},
places:{
"locale-orig":{
prefix:"",
suffix:""
},
"locale-translit":{
prefix:"",
suffix:""
},
"locale-translat":{
prefix:"",
suffix:""
}
}
};
this["default-locale"] = []; this["default-locale"] = [];
this["noun-genders"] = {}; this["noun-genders"] = {};
this.update_mode = CSL.NONE; this.update_mode = CSL.NONE;
@ -6573,26 +6668,26 @@ CSL.NameOutput.prototype.renderInstitutionNames = function () {
long_style = this._getLongStyle(primary, v, j); long_style = this._getLongStyle(primary, v, j);
short_style = this._getShortStyle(); short_style = this._getShortStyle();
institution_short = this._renderOneInstitutionPart(primary["short"], short_style); institution_short = this._renderOneInstitutionPart(primary["short"], short_style);
institution_long = this._composeOneInstitutionPart([primary, secondary, tertiary], long_style); institution_long = this._composeOneInstitutionPart([primary, secondary, tertiary], slot, long_style);
institution = [institution_short, institution_long]; institution = [institution_short, institution_long];
break; break;
case "long-short": case "long-short":
long_style = this._getLongStyle(primary, v, j); long_style = this._getLongStyle(primary, v, j);
short_style = this._getShortStyle(); short_style = this._getShortStyle();
institution_short = this._renderOneInstitutionPart(primary["short"], short_style); institution_short = this._renderOneInstitutionPart(primary["short"], short_style);
institution_long = this._composeOneInstitutionPart([primary, secondary, tertiary], long_style, true); institution_long = this._composeOneInstitutionPart([primary, secondary, tertiary], slot, long_style, true);
institution = [institution_long, institution_short]; institution = [institution_long, institution_short];
break; break;
default: default:
long_style = this._getLongStyle(primary, v, j); long_style = this._getLongStyle(primary, v, j);
institution = [this._composeOneInstitutionPart([primary, secondary, tertiary], long_style)]; institution = [this._composeOneInstitutionPart([primary, secondary, tertiary], slot, long_style)];
break; break;
} }
this.institutions[v][j] = this._join(institution, ""); this.institutions[v][j] = this._join(institution, "");
} }
} }
}; };
CSL.NameOutput.prototype._composeOneInstitutionPart = function (names, style) { CSL.NameOutput.prototype._composeOneInstitutionPart = function (names, slot, style) {
var primary = false, secondary = false, tertiary = false; var primary = false, secondary = false, tertiary = false;
if (names[0]) { if (names[0]) {
primary = this._renderOneInstitutionPart(names[0]["long"], style); primary = this._renderOneInstitutionPart(names[0]["long"], style);
@ -6605,15 +6700,28 @@ CSL.NameOutput.prototype._composeOneInstitutionPart = function (names, style) {
} }
var institutionblob; var institutionblob;
if (secondary || tertiary) { if (secondary || tertiary) {
var multiblob = this._join([secondary, tertiary], ", "); this.state.output.openLevel("empty");
var group_tok = new CSL.Token(); this.state.output.append(primary);
group_tok.strings.prefix = " ["; secondary_tok = CSL.Util.cloneToken(style);
group_tok.strings.suffix = "]"; if (slot.secondary) {
this.state.output.openLevel(group_tok); secondary_tok.strings.prefix = this.state.opt.citeAffixes.institutions[slot.secondary].prefix;
this.state.output.append(multiblob); secondary_tok.strings.suffix = this.state.opt.citeAffixes.institutions[slot.secondary].suffix;
if (!secondary_tok.strings.prefix) {
secondary_tok.strings.prefix = " ";
}
}
this.state.output.append(secondary, secondary_tok);
tertiary_tok = CSL.Util.cloneToken(style);
if (slot.tertiary) {
tertiary_tok.strings.prefix = this.state.opt.citeAffixes.institutions[slot.tertiary].prefix;
tertiary_tok.strings.suffix = this.state.opt.citeAffixes.institutions[slot.tertiary].suffix;
if (!tertiary_tok.strings.prefix) {
tertiary_tok.strings.prefix = " ";
}
}
this.state.output.append(tertiary, tertiary_tok);
this.state.output.closeLevel(); this.state.output.closeLevel();
multiblob = this.state.output.pop(); institutionblob = this.state.output.pop();
institutionblob = this._join([primary, multiblob], "");
} else { } else {
institutionblob = primary; institutionblob = primary;
} }
@ -6695,15 +6803,28 @@ CSL.NameOutput.prototype._renderPersonalNames = function (values, pos) {
} }
var personblob; var personblob;
if (secondary || tertiary) { if (secondary || tertiary) {
var multiblob = this._join([secondary, tertiary], ", "); this.state.output.openLevel("empty");
var group_tok = new CSL.Token(); this.state.output.append(primary);
group_tok.strings.prefix = " ["; secondary_tok = new CSL.Token();
group_tok.strings.suffix = "]"; if (slot.secondary) {
this.state.output.openLevel(group_tok); secondary_tok.strings.prefix = this.state.opt.citeAffixes.persons[slot.secondary].prefix;
this.state.output.append(multiblob); secondary_tok.strings.suffix = this.state.opt.citeAffixes.persons[slot.secondary].suffix;
if (!secondary_tok.strings.prefix) {
secondary_tok.strings.prefix = " ";
}
}
this.state.output.append(secondary, secondary_tok);
tertiary_tok = new CSL.Token();
if (slot.tertiary) {
tertiary_tok.strings.prefix = this.state.opt.citeAffixes.persons[slot.tertiary].prefix;
tertiary_tok.strings.suffix = this.state.opt.citeAffixes.persons[slot.tertiary].suffix;
if (!tertiary_tok.strings.prefix) {
tertiary_tok.strings.prefix = " ";
}
}
this.state.output.append(tertiary, tertiary_tok);
this.state.output.closeLevel(); this.state.output.closeLevel();
multiblob = this.state.output.pop(); personblob = this.state.output.pop();
personblob = this._join([primary, multiblob], "");
} else { } else {
personblob = primary; personblob = primary;
} }
@ -9402,16 +9523,16 @@ CSL.Transform = function (state) {
if (localesets) { if (localesets) {
var slotnames = ["primary", "secondary", "tertiary"]; var slotnames = ["primary", "secondary", "tertiary"];
for (var i = 0, ilen = slotnames.length; i < ilen; i += 1) { for (var i = 0, ilen = slotnames.length; i < ilen; i += 1) {
if (localesets.length - 1 < i) { if (localesets.length - 1 < i) {
break; break;
}
if (localesets[i]) {
slot[slotnames[i]] = 'locale-' + localesets[i];
} }
} if (localesets[i]) {
} else { slot[slotnames[i]] = 'locale-' + localesets[i];
slot.primary = 'locale-translat'; }
} }
} else {
slot.primary = 'locale-orig';
}
} }
if ((state.tmp.area !== "bibliography" if ((state.tmp.area !== "bibliography"
&& !(state.tmp.area === "citation" && !(state.tmp.area === "citation"
@ -9457,20 +9578,38 @@ CSL.Transform = function (state) {
tertiary = CSL.demoteNoiseWords(state, tertiary); tertiary = CSL.demoteNoiseWords(state, tertiary);
} }
if (secondary || tertiary) { if (secondary || tertiary) {
state.output.openLevel("empty");
primary_tok = CSL.Util.cloneToken(this); primary_tok = CSL.Util.cloneToken(this);
primary_tok.strings.suffix = ""; primary_tok.strings.suffix = "";
state.output.append(primary, primary_tok); state.output.append(primary, primary_tok);
group_tok = new CSL.Token(); if (secondary) {
group_tok.strings.prefix = " ["; secondary_tok = CSL.Util.cloneToken(primary_tok);
group_tok.strings.delimiter = ", "; secondary_tok.strings.prefix = state.opt.citeAffixes[langPrefs][slot.secondary].prefix;
group_tok.strings.suffix = "]" + this.strings.suffix; secondary_tok.strings.suffix = state.opt.citeAffixes[langPrefs][slot.secondary].suffix;
state.output.openLevel(group_tok); if (!secondary_tok.strings.prefix) {
if (secondary) { secondary_tok.strings.prefix = " ";
state.output.append(secondary); }
} for (var i = secondary_tok.decorations.length - 1; i > -1; i += -1) {
if (tertiary) { if (secondary_tok.decorations[i][0] === '@quotes') {
state.output.append(tertiary); secondary_tok.decorations = secondary_tok.decorations.slice(0, i).concat(secondary_tok.decorations.slice(i + 1))
} }
}
state.output.append(secondary, secondary_tok);
}
if (tertiary) {
tertiary_tok = CSL.Util.cloneToken(primary_tok);
tertiary_tok.strings.prefix = state.opt.citeAffixes[langPrefs][slot.tertiary].prefix;
tertiary_tok.strings.suffix = state.opt.citeAffixes[langPrefs][slot.tertiary].suffix;
if (!tertiary_tok.strings.prefix) {
tertiary_tok.strings.prefix = " ";
}
for (var i = tertiary_tok.decorations.length - 1; i > -1; i += -1) {
if (tertiary_tok.decorations[i][0] === '@quotes') {
tertiary_tok.decorations = tertiary_tok.decorations.slice(0, i).concat(tertiary_tok.decorations.slice(i + 1))
}
}
state.output.append(tertiary, tertiary_tok);
}
state.output.closeLevel(); state.output.closeLevel();
} else { } else {
state.output.append(primary, this); state.output.append(primary, this);