| 1205 | | var previousCitation = (previousIndex == -1 ? false : this.citationsByIndex[previousIndex]); |
| | 1209 | var previousCitation = (previousIndex == -1 ? false : this.citationsByIndex[previousIndex]); |
| | 1210 | // if one source is the same as the last, use ibid |
| | 1211 | // |
| | 1212 | // Case 1: source in previous citation |
| | 1213 | // (1) Threshold conditions |
| | 1214 | // (a) there must be a previous citation with one item |
| | 1215 | // (b) this item must be the first in this citation |
| | 1216 | // (c) the previous citation must contain a reference to the same item ... |
| | 1217 | // Case 2: immediately preceding source in this citation |
| | 1218 | // (1) Threshold conditions |
| | 1219 | // (a) there must be an imediately preceding reference to the |
| | 1220 | // same item in this citation |
| | 1221 | // Evaluation |
| | 1222 | // (a) if the previous citation had no locator and this citation |
| | 1223 | // has one, use ibid+pages |
| | 1224 | // (b) if the previous citation had no locator and this citation |
| | 1225 | // also has none, use ibid |
| | 1226 | // (c) if the previous citation had a locator (page number, etc.) |
| | 1227 | // and this citation has a locator that is identical, use ibid |
| | 1228 | // (d) if the previous citation had a locator, and this citation |
| | 1229 | // has one that differs, use ibid+pages |
| | 1230 | // (e) if the previous citation had a locator and this citation |
| | 1231 | // has none, use subsequent |
| | 1232 | // (f) if the current and previous citations are not the same, |
| | 1233 | // set as FIRST or SUBSEQUENT, as appropriate. |
| | 1234 | // |
| | 1235 | // For Case 1 |
| | 1236 | var curr = citation.citationItems[0]; |
| | 1237 | curr.thisRef = citation.properties.index+1; |
| | 1238 | if( |
| | 1239 | previousCitation |
| | 1240 | && previousCitation.citationItems.length == 1 |
| | 1241 | && citation.citationItems[0].itemID == previousCitation.citationItems[0].itemID ) { |
| | 1242 | var prev = previousCitation.citationItems[0]; |
| | 1243 | var newPosition = this.checkIbidOrSubsequent(prev, curr, citation); |
| | 1244 | } else { |
| | 1245 | // check outside this note if necessary |
| | 1246 | var newPosition = this.checkFirstOrSubsequent(curr, citation ); |
| | 1247 | } |
| | 1248 | this.updateCitePosition (curr, newPosition, citation, update); |
| | 1249 | citation.citationItems[0].position = newPosition; |
| | 1250 | this.checkCiteContext (citation.citationItems[0], newPosition); |
| | 1251 | // |
| | 1252 | // For Case 2 |
| | 1253 | // step through remaining cites in this citation |
| | 1254 | for ( i = 1; i < citation.citationItems.length; i++) { |
| | 1255 | ////////////////////positionIndex++; |
| | 1256 | // step through possible preceding cites within same note, from back to front |
| | 1257 | var curr = citation.citationItems[i]; |
| | 1258 | curr.thisRef = citation.properties.index+1; |
| | 1259 | var newPosition = undefined; |
| | 1260 | var prev = citation.citationItems[i-1]; |
| | 1261 | if ( curr.itemID == prev.itemID ) { |
| | 1262 | // check immediately preceding cite in this note |
| | 1263 | newPosition = this.checkIbidOrSubsequent(prev, curr, citation); |
| | 1264 | } else { |
| | 1265 | // check other preceding cites |
| | 1266 | newPosition = this.checkFirstOrSubsequent(curr, citation ); |
| | 1267 | } |
| | 1268 | this.updateCitePosition (curr, newPosition, citation, true); |
| | 1269 | citation.citationItems[i].position = newPosition; |
| | 1270 | this.checkCiteContext (citation.citationItems[i], newPosition); |
| | 1271 | } |
| | 1272 | } |
| | 1273 | |
| | 1274 | /* |
| | 1275 | * evaluates position of qualifying cites |
| | 1276 | */ |
| | 1277 | |
| | 1278 | Zotero.Integration.Session.prototype.checkIbidOrSubsequent = function(prev, curr, citation) { |
| | 1279 | var newPosition; |
| 1207 | | // if only one source, and it's the same as the last, use ibid |
| 1208 | | if( // there must be a previous citation with one item, and this citation |
| 1209 | | // may only have one item |
| 1210 | | previousCitation && citation.citationItems.length == 1 |
| 1211 | | && previousCitation.citationItems.length == 1 |
| 1212 | | // the previous citation must have been a citation of the same item |
| 1213 | | && citation.citationItems[0].item == previousCitation.citationItems[0].item |
| 1214 | | // and if the previous citation had a locator (page number, etc.) |
| 1215 | | // then this citation must have a locator, or else we should do the |
| 1216 | | // full citation (see Chicago Manual of Style) |
| 1217 | | && (!previousCitation.citationItems[0].locator || citation.citationItems[0].locator)) { |
| 1218 | | // use ibid, but check whether to use ibid+pages |
| 1219 | | var newPosition = (citation.citationItems[0].locator == previousCitation.citationItems[0].locator |
| 1220 | | && citation.citationItems[0].locatorType == previousCitation.citationItems[0].locatorType |
| 1221 | | ? Zotero.CSL.POSITION_IBID : Zotero.CSL.POSITION_IBID_WITH_LOCATOR); |
| 1222 | | // update if desired |
| 1223 | | if(update && (citation.citationItems[0].position || newPosition) && citation.citationItems[0].position != newPosition) { |
| 1224 | | this.updateIndices[citation.properties.index] = true; |
| | 1281 | curr.distanceToLastRef = citation.properties.index+1 - this.lastRef[curr.itemID]; |
| | 1282 | curr.firstRef = this.firstRef[curr.itemID]; |
| | 1283 | this.lastRef[curr.itemID] = citation.properties.index+1; |
| | 1284 | if (!prev.locator) { |
| | 1285 | if (curr.locator) { |
| | 1286 | newPosition = Zotero.CSL.POSITION_IBID_WITH_LOCATOR; |
| | 1287 | } else { |
| | 1288 | newPosition = Zotero.CSL.POSITION_IBID; |
| 1226 | | citation.citationItems[0].position = newPosition; |
| 1227 | | } else { |
| 1228 | | // loop through to see which are first citations |
| 1229 | | for(var i=0; i<citation.citationItems.length; i++) { |
| 1230 | | var citationItem = citation.citationItems[i]; |
| 1231 | | var newPosition = (!this.citationsByItemID[citationItem.itemID] |
| 1232 | | || this.citationsByItemID[citationItem.itemID][0].properties.index >= citation.properties.index |
| 1233 | | ? Zotero.CSL.POSITION_FIRST : Zotero.CSL.POSITION_SUBSEQUENT); |
| 1234 | | |
| 1235 | | // update if desired |
| 1236 | | if(update && (citation.citationItems[i].position || newPosition) && citation.citationItems[i].position != newPosition) { |
| 1237 | | this.updateIndices[citation.properties.index] = true; |
| 1238 | | } |
| 1239 | | citation.citationItems[i].position = newPosition; |
| | 1290 | } else { |
| | 1291 | if (prev.locator == curr.locator) { |
| | 1292 | newPosition = Zotero.CSL.POSITION_IBID; |
| | 1293 | } else if (curr.locator) { |
| | 1294 | newPosition = Zotero.CSL.POSITION_IBID_WITH_LOCATOR; |
| | 1295 | } else { |
| | 1296 | newPosition = Zotero.CSL.POSITION_SUBSEQUENT; |
| | 1303 | * checks whether a cite is a first or subsequent reference |
| | 1304 | */ |
| | 1305 | Zotero.Integration.Session.prototype.checkFirstOrSubsequent = function(curr, citation ) { |
| | 1306 | var newPosition; |
| | 1307 | |
| | 1308 | if (!this.citationsByItemID[curr.itemID]) { |
| | 1309 | curr.distanceToLastRef = 0; |
| | 1310 | curr.firstRef = citation.properties.index+1; |
| | 1311 | this.firstRef[curr.itemID] = citation.properties.index+1; |
| | 1312 | this.lastRef[curr.itemID] = citation.properties.index+1; |
| | 1313 | newPosition = Zotero.CSL.POSITION_FIRST; |
| | 1314 | } else if (this.citationsByItemID[curr.itemID][0].properties.index >= citation.properties.index) { |
| | 1315 | curr.distanceToLastRef = 0; |
| | 1316 | curr.firstRef = citation.properties.index+1; |
| | 1317 | this.firstRef[curr.itemID] = citation.properties.index+1; |
| | 1318 | this.lastRef[curr.itemID] = citation.properties.index+1; |
| | 1319 | newPosition = Zotero.CSL.POSITION_FIRST; |
| | 1320 | } else { |
| | 1321 | curr.distanceToLastRef = citation.properties.index+1 - this.lastRef[curr.itemID]; |
| | 1322 | curr.firstRef = this.firstRef[curr.itemID]; |
| | 1323 | this.lastRef[curr.itemID] = citation.properties.index+1; |
| | 1324 | newPosition = Zotero.CSL.POSITION_SUBSEQUENT; |
| | 1325 | } |
| | 1326 | return newPosition; |
| | 1327 | } |
| | 1328 | |
| | 1329 | /* |
| | 1330 | * checks if cite has a prefix with terminal punctuation |
| | 1331 | */ |
| | 1332 | Zotero.Integration.Session.prototype.checkCiteContext = function(citationItem, newPosition) { |
| | 1333 | if (citationItem.prefix && citationItem.prefix.match(/.*[:;.?!][\s\"\"\'\']*$/)) { |
| | 1334 | citationItem.prefixPunctuation = true; |
| | 1335 | } else { |
| | 1336 | citationItem.prefixPunctuation = false; |
| | 1337 | } |
| | 1338 | } |
| | 1339 | |
| | 1340 | /* |
| | 1341 | * updates indexes |
| | 1342 | * |
| | 1343 | */ |
| | 1344 | Zotero.Integration.Session.prototype.updateCitePosition = function (curr, newPosition, citation, update) { |
| | 1345 | if(update && (curr.position || newPosition) && curr.position != newPosition) { |
| | 1346 | this.updateIndices[citation.properties.index] = true; |
| | 1347 | } |
| | 1348 | } |
| | 1349 | |
| | 1350 | /* |