Ticket #1262: zs15_fbennett_2008-12-18-2.patch

File zs15_fbennett_2008-12-18-2.patch, 3.6 KB (added by fbennett, 8 years ago)

Extend is-numeric test to cover note/extra fields and user-entered locator string

  • content/zotero/xpcom/csl.js

    diff -r -u chrome.orig/content/zotero/xpcom/csl.js chrome/content/zotero/xpcom/csl.js
    old new  
    2020    ***** END LICENSE BLOCK ***** 
    2121*/ 
    2222 
     23 /* 
     24 * PATCHES: fbennett 
     25 * 
     26 * This version of cls.js reflects the following modification: 
     27 * 
     28 * (2) Make the is-numeric test available with note/extra and locator 
     29 *     fields: 
     30 *       The Extra field can be used to overcome limitations in a 
     31 *     style, for use cases the are not covered by the current schema 
     32 *     (such as the handling of an original and a modern publication  
     33 *     date for a resource).  The locator field is likely to come 
     34 *     under pressure for special pinpoint forms of a citation in 
     35 *     footnote styles. 
     36 * 
     37 *     The changes labeled fbennett (2) below improve the utility of 
     38 *     these fields by extending the is-numeric expression to cover  
     39 *     them. 
     40 */ 
     41 
     42 
    2343/* 
    2444 * CSL: a class for creating bibliographies from CSL files 
    2545 * this is abstracted as a separate class for the benefit of anyone who doesn't 
     
    803823                                for(var j=0; j<variables.length; j++) { 
    804824                                        if(ignore[0][variables[j]]) continue; 
    805825                                         
    806                                         var text = item.getNumericVariable(variables[j], form); 
     826/*  
     827 * fbennett (2): pass citationItem through to provide locator field data to function 
     828 */ 
     829                                        var text = item.getNumericVariable(variables[j], citationItem, form); 
     830/*  
     831 * fbennett: end 
     832 */ 
    807833                                        if(text) { 
    808834                                                newString.append(text); 
    809835                                                success = true; 
     
    10611087                                                                                if (exists) exists = !!exists.length; 
    10621088                                                                        } 
    10631089                                                                } else if (attribute == "is-numeric") { 
    1064                                                                         exists = item.getNumericVariable(variables[j]); 
     1090/* 
     1091 * fbennett (2): pass through citationItem to provide locator field data to function 
     1092 */ 
     1093                                                                                exists = item.getNumericVariable(variables[j], citationItem); 
     1094/* 
     1095 * fbennett: end 
     1096 */ 
    10651097                                                                } else if (attribute == "is-date") { // XXX - this needs improving 
    10661098                                                                        if (Zotero.CSL._dateVariables[variables[j]]) { 
    10671099                                                                                exists = !!item.getDate(variables[j]); 
     
    18821914        "issue":"issue", 
    18831915        "number-of-volumes":"numberOfVolumes", 
    18841916        "edition":"edition", 
    1885         "number":"number" 
     1917/* 
     1918 * fbennett (2): adding note and locator fields to number field map 
     1919 */ 
     1920        "number":"number", 
     1921        "note":"extra", 
     1922        "locator":"locator" 
     1923/* 
     1924 * fbennett: end 
     1925 */ 
    18861926} 
    18871927/* 
    18881928 * Gets a numeric object for a specific type. <number variable="edition" form="roman"/> 
    18891929 */ 
    1890 Zotero.CSL.Item.prototype.getNumericVariable = function(variable, form) { 
    1891  
     1930/* 
     1931 * fbennett (2): adding citationItem argument to function to gain access to locator field data 
     1932 */  
     1933Zotero.CSL.Item.prototype.getNumericVariable = function(variable, citationItem, form) { 
     1934/* 
     1935 * fbennett: end 
     1936 */ 
    18921937        if(!Zotero.CSL.Item._zoteroNumberFieldMap[variable]) return ""; 
    18931938         
    18941939        var zoteroFields = []; 
     
    19031948         
    19041949        var matches; 
    19051950        for each(var zoteroField in zoteroFields) { 
    1906                 var value = this.zoteroItem.getField(zoteroField, false, true); 
     1951/* 
     1952 * fbennett (2): adding special handling for locator field 
     1953 */ 
     1954                if(zoteroField == "locator") { 
     1955                        var value = citationItem.locator; 
     1956                } else { 
     1957                        var value = this.zoteroItem.getField(zoteroField, false, true); 
     1958                } 
     1959/* 
     1960 * fbennett: end 
     1961 */ 
    19071962                var matches; 
    19081963                if(value != "" && (matches = value.toString().match(Zotero.CSL._numberRegexp)) ) { 
    19091964                        value = matches[0];