Ticket #1859: coins-ordering.patch

File coins-ordering.patch, 2.1 KB (added by ajlyon, 5 years ago)
  • chrome/content/zotero/xpcom/openurl.js

     
    358358                                if(complexAu.length && !lastCreator.lastName && !lastCreator.institutional) { 
    359359                                        lastCreator.lastName = value; 
    360360                                } else { 
    361                                         complexAu.push({lastName:value, creatorType:(key == "rft.aulast" ? "author" : "inventor")}); 
     361                                        complexAu.push({lastName:value, creatorType:(key == "rft.aulast" ? "author" : "inventor"), offset:item.creators.length}); 
    362362                                } 
    363363                        } else if(key == "rft.aufirst" || key == "rft.invfirst") { 
    364364                                var lastCreator = complexAu[complexAu.length-1]; 
    365365                                if(complexAu.length && !lastCreator.firstName && !lastCreator.institutional) { 
    366366                                        lastCreator.firstName = value; 
    367367                                } else { 
    368                                         complexAu.push({firstName:value, creatorType:(key == "rft.aufirst" ? "author" : "inventor")}); 
     368                                        complexAu.push({firstName:value, creatorType:(key == "rft.aufirst" ? "author" : "inventor"), offset:item.creators.length}); 
    369369                                } 
    370370                        } else if(key == "rft.au" || key == "rft.creator" || key == "rft.contributor" || key == "rft.inventor") { 
    371371                                if(key == "rft.contributor") { 
     
    439439                                } 
    440440                        } 
    441441                } 
     442 
     443                // To maintain author ordering when complex and simple authors are combined, 
     444                // we remember where they were and the correct offsets 
     445                var inserted = 0; 
    442446                 
    443447                // combine two lists of authors, eliminating duplicates 
    444448                for(var i=0; i<complexAu.length; i++) { 
    445449                        var pushMe = true; 
     450                        var offset = complexAu[i].offset; 
     451                        delete complexAu[i].offset; 
    446452                        for(var j=0; j<item.creators.length; j++) { 
    447453                                // if there's a plain author that is close to this author (the 
    448454                                // same last name, and the same first name up to a point), keep 
     
    455461                                        break; 
    456462                                } 
    457463                        } 
    458                         if(pushMe) item.creators.push(complexAu[i]); 
     464                        // Splice in the complex creator at the correct location, 
     465                        // accounting for previous insertions 
     466                        if(pushMe) { 
     467                                item.creators = item.creators.splice(offset + inserted, 0, complexAu[i]); 
     468                                inserted++; 
     469                        } 
    459470                } 
    460471                 
    461472                return item;