Ticket #1262: zs15_fbennett_2008-12-17.patch

File zs15_fbennett_2008-12-17.patch, 7.5 KB (added by fbennett, 8 years ago)

Patch file incorporating four changes (one bug fix and three enhancements)

  • content/zotero/xpcom/csl.js

    diff -r -u chrome.orig/content/zotero/xpcom/csl.js chrome/content/zotero/xpcom/csl.js
    old new  
    2121*/ 
    2222 
    2323/* 
     24 * PATCHES: fbennett 
     25 * 
     26 * This version of cls.js reflects the following four modifications: 
     27 * 
     28 * (1) Fix bug in handling of label pluralizations with et al.: 
     29 *       Currently, the pluralization of labels used with names is 
     30 *     determined by the number of names in the formatted string. 
     31 *     For styles that call for showing only one name with et al., 
     32 *     this causes a singular label to be used in this case 
     33 *     (i.e. "John Doe et al. ed." rather than "John Doe et al. eds."). 
     34 * 
     35 *     The fbennett (1) change below addresses this issue. 
     36 * 
     37 * (2) Make the is-numeric test available with note/extra and locator 
     38 *     fields: 
     39 *       The Extra field can be used to overcome limitations in a 
     40 *     style, for use cases the are not covered by the current schema 
     41 *     (such as the handling of an original and a modern publication  
     42 *     date for a resource).  The locator field is likely to come 
     43 *     under pressure for special pinpoint forms of a citation in 
     44 *     footnote styles. 
     45 * 
     46 *     The changes labeled fbennett (2) below improve the utility of 
     47 *     these fields by extending the is-numeric expression to cover  
     48 *     them. 
     49 * 
     50 * (3) New is-phrase test: 
     51 *       This test returns true if there is a space character in the 
     52 *     target field (i.e. if it contains more than one word).  This 
     53 *     opens a path for the exceptional handling of fields which  
     54 *     normally contain a single word or number, and take (the edition field is  
     55 *     the obvious example).  This will be needed for hands-free  
     56 *     processing of the Bluebook style. 
     57 * 
     58 *     The changes labled fbennett (3) below provide this test. 
     59 * 
     60 * (4) New lastchar-num test: 
     61 *       In the Bluebook style, the separator between a book title and 
     62 *     a page number changes from " " to ", at " where the title ends 
     63 *     in a number (and the division between title and page number is 
     64 *     therefore unclear).  This test makes it possible to cope with 
     65 *     this case, at the cost of three lines of new code in csl.js. 
     66 *      
     67 *     The changes labeled fbennett (4) below provide this test. 
     68 */ 
     69 
     70/* 
    2471 * CSL: a class for creating bibliographies from CSL files 
    2572 * this is abstracted as a separate class for the benefit of anyone who doesn't 
    2673 * want to use the Scholar data model, but does want to use CSL in JavaScript 
     
    99146Zotero.CSL._firstNameRegexp = /^[^\s]*/; 
    100147Zotero.CSL._textCharRegexp = /[a-zA-Z0-9]/; 
    101148Zotero.CSL._numberRegexp = /\d+/; 
     149/* 
     150 * fbennett (3): adding regexp for detecting spaces in string 
     151 */ 
     152Zotero.CSL._spaceRegexp = /\s/; 
     153/*  
     154 * fbennett: end 
     155 */ 
     156/* fbennett (4): adding regexp for detecting digit as last character in 
     157 * field 
     158 */ 
     159Zotero.CSL._lastcharnumRegexp = /[0-9]$/; 
     160/*  
     161 * fbennett: end 
     162 */ 
    102163Zotero.CSL.prototype.formatCitation = function(citation, format) { 
    103164        default xml namespace = "http://purl.org/net/xbiblio/csl"; with({}); 
    104165         
     
    694755                                                } 
    695756                                        } else if(formattedString.format != "Sort" &&  
    696757                                                        name == "label" && variables[j] != "author") { 
    697                                                 newString.append(this._getTerm(variables[j], (maxCreators != 1), child["@form"].toString(), child["@include-period"] == "true"), child); 
     758/* 
     759 * fbennett (1): Force names with et al. to plural 
     760 */ 
     761                                               newString.append(this._getTerm(variables[j], (maxCreators != 1 || useEtAl), child["@form"].toString(), child["@include-period"] == "true"), child); 
     762/* 
     763 * fbennett: end 
     764 */ 
    698765                                        } 
    699766                                } 
    700767                                success = true; 
     
    803870                                for(var j=0; j<variables.length; j++) { 
    804871                                        if(ignore[0][variables[j]]) continue; 
    805872                                         
    806                                         var text = item.getNumericVariable(variables[j], form); 
     873/*  
     874 * fbennett (2): pass citationItem through to provide locator field data to function 
     875 */ 
     876                                        var text = item.getNumericVariable(variables[j], citationItem, form); 
     877/*  
     878 * fbennett: end 
     879 */ 
    807880                                        if(text) { 
    808881                                                newString.append(text); 
    809882                                                success = true; 
     
    10361109                                         
    10371110                                        // inspect variables 
    10381111                                        var done = false; 
    1039                                         var attributes = ["variable", "is-date", "is-numeric", "is-plural", "type", "disambiguate", "locator", "position"]; 
     1112/* 
     1113 * fbennett (3) (4): add is-phrase and lastnum-char to attributes list 
     1114 */ 
     1115                                        var attributes = ["variable", "is-date", "is-numeric", "is-plural", "type", "disambiguate", "locator", "position", "is-phrase", "lastchar-num"]; 
     1116/* 
     1117 * fbennett: end 
     1118 */ 
    10401119                                        for(var k=0; !done && k<attributes.length; k++) { 
    10411120                                                var attribute = attributes[k]; 
    10421121                                                 
     
    10611140                                                                                if (exists) exists = !!exists.length; 
    10621141                                                                        } 
    10631142                                                                } else if (attribute == "is-numeric") { 
    1064                                                                         exists = item.getNumericVariable(variables[j]); 
     1143/* 
     1144 * fbennett (2): pass through citationItem to provide locator field data to function 
     1145 */ 
     1146                                                                                exists = item.getNumericVariable(variables[j], citationItem); 
     1147/* 
     1148 * fbennett: end 
     1149 */ 
    10651150                                                                } else if (attribute == "is-date") { // XXX - this needs improving 
    10661151                                                                        if (Zotero.CSL._dateVariables[variables[j]]) { 
    10671152                                                                                exists = !!item.getDate(variables[j]); 
     
    10871172                                                                        exists = citationItem && citationItem.locator && 
    10881173                                                                                (citationItem.locatorType == variables[j] 
    10891174                                                                                || (!citationItem.locatorType && variables[j] == "page")); 
     1175/* 
     1176 * fbennett (3): adding is-phrase condition 
     1177 */ 
     1178                                                                } else if (attribute == "is-phrase") { 
     1179                                                                        exists = item.getVariable(variables[j]).match(Zotero.CSL._spaceRegexp); 
     1180/* 
     1181 * fbennett: end 
     1182 */ 
     1183/* 
     1184 * fbennett (4): adding lastum-char condition 
     1185 */ 
     1186                                                                } else if (attribute == "lastchar-num") { 
     1187                                                                        exists = item.getVariable(variables[j]).match(Zotero.CSL._lastcharnumRegexp); 
     1188/* 
     1189 * fbennett: end 
     1190 */ 
    10901191                                                                } else {        // attribute == "position" 
    10911192                                                                        if(variables[j] == "first") { 
    10921193                                                                                exists = !citationItem 
     
    18821983        "issue":"issue", 
    18831984        "number-of-volumes":"numberOfVolumes", 
    18841985        "edition":"edition", 
    1885         "number":"number" 
     1986/* 
     1987 * fbennett (2): adding note and locator fields to number field map 
     1988 */ 
     1989        "number":"number", 
     1990        "note":"extra", 
     1991        "locator":"locator" 
     1992/* 
     1993 * fbennett: end 
     1994 */ 
    18861995} 
    18871996/* 
    18881997 * Gets a numeric object for a specific type. <number variable="edition" form="roman"/> 
    18891998 */ 
    1890 Zotero.CSL.Item.prototype.getNumericVariable = function(variable, form) { 
    1891  
     1999/* 
     2000 * fbennett (2): adding citationItem argument to function to gain access to locator field data 
     2001 */  
     2002Zotero.CSL.Item.prototype.getNumericVariable = function(variable, citationItem, form) { 
     2003/* 
     2004 * fbennett: end 
     2005 */ 
    18922006        if(!Zotero.CSL.Item._zoteroNumberFieldMap[variable]) return ""; 
    18932007         
    18942008        var zoteroFields = []; 
     
    19032017         
    19042018        var matches; 
    19052019        for each(var zoteroField in zoteroFields) { 
    1906                 var value = this.zoteroItem.getField(zoteroField, false, true); 
     2020/* 
     2021 * fbennett (2): adding special handling for locator field 
     2022 */ 
     2023                if(zoteroField == "locator") { 
     2024                        var value = citationItem.locator; 
     2025                } else { 
     2026                        var value = this.zoteroItem.getField(zoteroField, false, true); 
     2027                } 
     2028/* 
     2029 * fbennett: end 
     2030 */ 
    19072031                var matches; 
    19082032                if(value != "" && (matches = value.toString().match(Zotero.CSL._numberRegexp)) ) { 
    19092033                        value = matches[0];