fix issues with spontaneous rearrangement of multi-item citations

This commit is contained in:
Simon Kornblith 2008-03-24 15:20:57 +00:00
parent 6dc762df29
commit 1188978174

View File

@ -1444,7 +1444,7 @@ Zotero.CSL.prototype._compareItem = function(a, b, context, cache) {
}
}
// sort by index
// sort by index in document
var aIndex = a.getProperty("index");
var bIndex = b.getProperty("index");
if(aIndex !== "" && (bIndex === "" || aIndex < bIndex)) {
@ -1453,6 +1453,15 @@ Zotero.CSL.prototype._compareItem = function(a, b, context, cache) {
return 1;
}
// sort by old index (to make this a stable sort)
var aOldIndex = a.getProperty("oldIndex");
var bOldIndex = b.getProperty("oldIndex");
if(aOldIndex < bOldIndex) {
return -1;
} else if(aOldIndex != bOldIndex) {
return 1;
}
return 0;
}
@ -1464,6 +1473,10 @@ Zotero.CSL.prototype.cachedSort = function(items, context, field) {
var me = this;
var cache = new Object();
for(var i=0; i<items.length; i++) {
items[i].setProperty("oldIndex", i);
}
if(field) {
var newItems = items.sort(function(a, b) {
return me._compareItem(a[field], b[field], context, cache);