Ticket #1278: 10-volume-pinpoints.patch

File 10-volume-pinpoints.patch, 14.2 KB (added by fbennett, 8 years ago)
  • chrome/content/zotero/addCitationDialog.js

    diff -r -u zotero-trunk.orig/chrome/content/zotero/addCitationDialog.js zotero-trunk/chrome/content/zotero/addCitationDialog.js
    old new  
    2626                "suffix":"value", 
    2727                "locatorType":"selectedIndex", 
    2828                "locator":"value", 
    29                 "suppressAuthor":"checked" 
     29                "suppressAuthor":"checked", 
     30                "volume-selector":"value", 
     31                "volume":"value", 
     32                "issued":"value", 
     33                "edition":"value" 
    3034        }; 
    3135         
    3236        var _itemData = new Object(); 
     
    5256        this.confirmRegenerate = confirmRegenerate; 
    5357        this.accept = accept; 
    5458        this.cancel = cancel; 
    55          
     59        /* 
     60         * Volume number setting 
     61         * 
     62         * ------------ 
     63         * What it does 
     64         * ------------ 
     65         * 
     66         * Some styles (well, Bluebook, anyway) require that the 
     67         * volume number be supplied for multi-volume works by a 
     68         * single author -- in back-references.  This means that a 
     69         * single bibliographic entry must be made to work with 
     70         * multiple volumes, treating the whole set as a single work. 
     71         *  
     72         * This patch modifies Zotero to supply a volume selection 
     73         * widget to the client UI when there is an appropriate value 
     74         * in the numberOfVolumes field, and the work cited is not a 
     75         * specific chapter, dictionary entry, or encyclopedia entry. 
     76         * 
     77         * The value in numberOfVolumes may be an integer or a 
     78         * comma-delimited string.  In the former case, a list of 
     79         * volume numbers ranging up from one is presented in the 
     80         * widget.  In the latter case, the literal elements are 
     81         * presented. 
     82         * 
     83         * Selections are persistent, both while editing and after 
     84         * rendering of the citation.  The value will feed through to 
     85         * CSL stylesheets in the normal way, through both text and 
     86         * number declarations. 
     87         * 
     88         * --------------- 
     89         * Functions added 
     90         * --------------- 
     91         * 
     92         * volumeNumberInit() hides the volume number widget in 
     93         * initial popup view. 
     94         * 
     95         * volumeNumber() enables the volume number widget with 
     96         * appropriate values. 
     97         * 
     98         * ------------------- 
     99         * Functions exploited 
     100         * ------------------- 
     101         * 
     102         * load() in the single condition resets screen when editing 
     103         * singles.  (citation is active, so should reset in this 
     104         * case). 
     105         *  
     106         * load() in the multiple condition resets screen when editing 
     107         * multiples.  (should take no action, because nothing is 
     108         * active on initial display). 
     109         * 
     110         * listItemSelected() resets screen upon selection in 
     111         * right-side multiples box. 
     112         * 
     113         * treeItemSelected() resets screen on selection in the 
     114         * left-side box. 
     115         * 
     116         * ---- 
     117         * Bugs 
     118         * ---- 
     119         * 
     120         * This is a generally horrible hack. 
     121         */ 
     122 
     123        function volumeNumberInit() { 
     124            document.getElementById("volume-selector").setAttribute("hidden",true); 
     125            document.getElementById("volume-popup").setAttribute("hidden",true); 
     126            document.getElementById("volume-label").setAttribute("hidden",true); 
     127        } 
     128 
     129        function volumeNumber(itemID,pos) { 
     130             
     131            var itemDataID = (pos ? itemID+"::"+pos : itemID); 
     132 
     133            if (itemID) { 
     134                var item = Zotero.Items.get(itemID); 
     135                if(item) { 
     136 
     137                    var volume_title = item.getField("title"); 
     138                    var volume_numberof = item.getField("numberOfVolumes"); 
     139                    var volume_blockers = ["bookTitle","encyclopediaTitle","dictionaryTitle"]; 
     140                    var volume_block = true; 
     141                    if(volume_title && volume_numberof) { 
     142                        volume_block = false; 
     143                        for (i in volume_blockers) { 
     144                            var blocker = volume_blockers[i]; 
     145                            if(item.getField(blocker)) { 
     146                                volume_block = true; 
     147                                break; 
     148                            } 
     149                        } 
     150                    } 
     151                    var volume_range = []; 
     152                    var volume_labels = []; 
     153                    if(!volume_block && volume_numberof) { 
     154                        var numberof = volume_numberof.toString(); 
     155                        if (numberof.match(/^\d+$/)) { 
     156                            for (i = 1; i <= parseInt(numberof); i++) { 
     157                                volume_range.push(i.toString()); 
     158                                volume_labels.push(i.toString()); 
     159                            } 
     160                        } else if (numberof.match(/,/)) { 
     161                            volume_range = numberof.replace(/, ?/g, "|").split("|"); 
     162                            for (i in volume_range) { 
     163                                volume_labels.push(volume_range[i].replace(/\/.*$/, "")); 
     164                                    } 
     165                        } else { 
     166                            volume_block = true; 
     167                        } 
     168                    } 
     169             
     170                    var menu_volume = document.getElementById("volume-selector"); 
     171                    var popup_volume = document.getElementById("volume-popup"); 
     172                    var label_volume = document.getElementById("volume-label"); 
     173                    label_volume.setAttribute("hidden",volume_block); 
     174                    popup_volume.setAttribute("hidden",volume_block); 
     175                    menu_volume.setAttribute("hidden",volume_block); 
     176                     
     177                    while(popup_volume.firstChild) { 
     178                        popup_volume.removeChild(popup_volume.firstChild); 
     179                    } 
     180                    var i = 0; 
     181                    var _volumeIndexArray = {}; 
     182                    for (var value in volume_range) { 
     183                        var volume = volume_range[value]; 
     184                        var label = volume_labels[value]; 
     185                        var child = document.createElement("menuitem"); 
     186                        child.setAttribute("value", volume); 
     187                        child.setAttribute("label", label); 
     188                        popup_volume.appendChild(child); 
     189                        _volumeIndexArray[volume] = i; 
     190                        i++; 
     191                    } 
     192 
     193                    if(_itemData && _itemData[itemDataID] && _itemData[itemDataID]["volume-selector"]) { 
     194                                var index = _volumeIndexArray[_itemData[itemDataID]["volume-selector"]]; 
     195                    } else { 
     196                                var index = 0; 
     197                    } 
     198                    menu_volume.selectedIndex = index; 
     199 
     200                } 
     201            } 
     202        } 
     203                 
    56204        /* 
    57205         * To generate unique keys for items in multi-cite list 
    58206         */ 
     
    64212         * initialize add citation dialog 
    65213         */ 
    66214        function load() { 
     215                volumeNumberInit(); 
    67216                document.getElementById("multiple-sources-button").label = Zotero.getString("citation.multipleSources"); 
    68217                document.getElementById("show-editor-button").label = Zotero.getString("citation.showEditor"); 
    69218                 
     
    77226                if(io.citation.sortable) { 
    78227                        _sortCheckbox = document.getElementById("keepSorted"); 
    79228                        _sortCheckbox.hidden = false; 
    80                         if(io.citation.properties.sort === undefined) io.citation.properties.sort = true; 
     229                        if(io.citation.properties.sort == undefined) io.citation.properties.sort = true; 
    81230                        _sortCheckbox.checked = io.citation.properties.sort; 
    82231                } 
    83232                 
     
    108257                if(io.citation.citationItems.length) { 
    109258                        if(io.citation.citationItems.length == 1) { 
    110259                                // single citation 
     260                                volumeNumber(io.citation.citationItems[0].itemID); 
    111261                                _suppressNextTreeSelect = true; 
    112262                                itemsView.selectItem(io.citation.citationItems[0].itemID);       // treeview from selectItemsDialog.js 
    113263                                for(var property in _preserveData) { 
     
    223373                        document.getElementById("add").disabled = !itemID; 
    224374                        document.getElementById("remove").disabled = true; 
    225375                        pos = document.getElementById("citation-list").childNodes.length; 
     376                        volumeNumber(itemID,pos); 
    226377                } else { 
     378                        volumeNumber(itemID); 
    227379                        _updateAccept(); 
    228380                        _updatePreview(); 
    229381                } 
     
    237389                var itemID = (selectedListItem ? selectedListItem.value : false); 
    238390                var pos = selectedListItem.parentNode.selectedIndex; 
    239391                _itemSelected(itemID,pos); 
     392 
     393                volumeNumber(itemID,pos); 
    240394                 
    241395                document.getElementById("remove").disabled = !itemID; 
    242396                document.getElementById("add").disabled = true; 
     
    330484         * Ask whether to modfiy the preview 
    331485         */ 
    332486        function confirmRegenerate(focusShifted) { 
     487                if (focusShifted && _multipleSourcesOn) { 
     488                        var listing = document.getElementById("citation-list"); 
     489                        var selectedListItem = document.getElementById("citation-list").getSelectedItem(0); 
     490                    var itemID = selectedListItem.value; 
     491                    var pos = selectedListItem.parentNode.selectedIndex; 
     492                    var volume_selector = document.getElementById('volume-selector'); 
     493                    var volume =  document.getElementById('volume'); 
     494                    var edition = document.getElementById('edition'); 
     495                    var issued = document.getElementById('issued'); 
     496                    var elements = volume_selector.value.replace(/ ?\/ ?/g, "|").split("|"); 
     497 
     498                    if (elements.length > 1) { 
     499                        issued.setAttribute("value", elements[1]); 
     500                    } else { 
     501                        issued.removeAttribute("value"); 
     502                    } 
     503                    if (elements.length > 2) { 
     504                        edition.setAttribute("value", elements[2]); 
     505                    } else { 
     506                        edition.removeAttribute("value"); 
     507                    } 
     508                    if (elements.length > 0) { 
     509                                volume.setAttribute("value", elements[0]); 
     510                    } else { 
     511                                volume.removeAttribute("value"); 
     512                    } 
     513                    //_itemSelected(itemID,pos); 
     514                } 
     515 
    333516                if(document.getElementById('editor').value == _originalHTML || _originalHTML === undefined) { 
    334517                        // no changes; just update without asking 
    335518                        _updatePreview(); 
     
    453636         * itemID is undefined, only updates _itemData array 
    454637         */ 
    455638        function _itemSelected(itemID,pos) { 
     639                // not idempotent!  must only run once when selection is changed 
    456640                var itemDataID = (itemID ? multiKey(itemID,pos) : undefined); 
    457641                if(_lastSelected && !_itemData[_lastSelected]) { 
    458642                        _itemData[_lastSelected] = new Object(); 
     
    464648                         
    465649                        // save property 
    466650                        if(_lastSelected) { 
    467                                 if(property == "locatorType") { 
     651                                if(box == "locatorType") { 
    468652                                        _itemData[_lastSelected][box] = domBox.selectedItem.value; 
    469653                                } else { 
    470654                                        _itemData[_lastSelected][box] = domBox[property]; 
     
    487671                                domBox[property] = ""; 
    488672                        } 
    489673                } 
    490                 if(itemID !== undefined) _lastSelected = itemDataID; 
     674                if(itemDataID !== undefined) _lastSelected = itemDataID; 
    491675        } 
    492676         
    493677        /* 
  • chrome/content/zotero/addCitationDialog.xul

    diff -r -u zotero-trunk.orig/chrome/content/zotero/addCitationDialog.xul zotero-trunk/chrome/content/zotero/addCitationDialog.xul
    old new  
    181181                                <separator flex="4"/> 
    182182                                <vbox flex="1"> 
    183183                                        <hbox align="stretch"> 
    184                                                 <menulist onchange="Zotero_Citation_Dialog.confirmRegenerate(true)" id="locatorType"> 
    185                                                         <menupopup id="locator-type-popup"/> 
     184+                                               <menulist onmouseout="Zotero_Citation_Dialog.confirmRegenerate(true)" id="locatorType"> 
     185                                                        <menupopup id="locator-type-popup"/> 
     186                                                </menulist> 
     187                                                <textbox oninput="Zotero_Citation_Dialog.confirmRegenerate(false)" onchange="Zotero_Citation_Dialog.confirmRegenerate(true)" id="locator" flex="1"/> 
     188                                        </hbox> 
     189                                        <separator height="2px" flex="1"/> 
     190                                        <hbox align="stretch"> 
     191                                                <checkbox oncommand="Zotero_Citation_Dialog.confirmRegenerate(true)" id="suppressAuthor" label="&zotero.citation.suppressAuthor.label;"/> 
     192                                                <spacer flex="1"/> 
     193                                                <label value="&zotero.citation.volume.label;" id="volume-label"/> 
     194                                                <menulist onselect="Zotero_Citation_Dialog.confirmRegenerate(true)" id="volume-selector"> 
     195                                                        <menupopup id="volume-popup"/> 
    186196                                                </menulist> 
    187                                                 <textbox oninput="Zotero_Citation_Dialog.confirmRegenerate(false)" onchange="Zotero_Citation_Dialog.confirmRegenerate(true)" id="locator" flex="1"/> 
     197                                                <label id="edition" value="" hidden="true"/> 
     198                                                <label id="issued" value="" hidden="true"/> 
     199                                                <label id="volume" value="" hidden="true"/> 
    188200                                        </hbox> 
    189                                         <separator style="height: 2px" flex="1"/> 
    190                                         <checkbox oncommand="Zotero_Citation_Dialog.confirmRegenerate(true)" id="suppressAuthor" label="&zotero.citation.suppressAuthor.label;"/> 
    191                                 </vbox> 
     201                                </vbox> 
    192202                        </hbox> 
    193203                </vbox> 
    194204                 
  • chrome/content/zotero/xpcom/csl.js

    diff -r -u zotero-trunk.orig/chrome/content/zotero/xpcom/csl.js zotero-trunk/chrome/content/zotero/xpcom/csl.js
    old new  
    783783                                 
    784784                                for(var j=0; j<variables.length; j++) { 
    785785                                        if(ignore[0][variables[j]]) continue; 
    786                                          
     786                                                var text = citationItem && citationItem.locator ? citationItem.locator : ""; 
    787787                                        if(variables[j] == "locator") { 
    788788                                                // special case for locator 
    789789                                                var text = citationItem && citationItem.locator ? citationItem.locator : ""; 
     790                                        } else if(variables[j] == "volume") { 
     791                                                // special case for volume (first of three overrides) 
     792                                                var text = citationItem && citationItem.volume ? citationItem.volume : item.getVariable("volume"); 
     793                                        } else if(variables[j] == "edition") { 
     794                                                // special case for edition 
     795                                                var text = citationItem && citationItem.edition ? citationItem.edition : item.getVariable("edition"); 
     796                                        } else if(variables[j] == "date") { 
     797                                                // special case for date 
     798                                                var text = citationItem && citationItem.date ? citationItem.date : item.getVariable("date"); 
    790799                                        } else if(variables[j] == "firstref") { 
    791800                                                // note number of first reference to this citation 
    792                                                 var text = citationItem && citationItem.firstref ? citationItem.firstref : 0; 
     801                                                var text = citationItem && citationItem.firstRef ? citationItem.firstRef : 0; 
    793802                                        } else if(citationItem && citationItem._csl && citationItem._csl[variables[j]]) { 
    794803                                                // override if requested 
    795804                                                var text = citationItem._csl[variables[j]]; 
     
    19821991         
    19831992        var matches; 
    19841993        for each(var zoteroField in zoteroFields) { 
    1985                 var value = this.zoteroItem.getField(zoteroField, false, true).toString(); 
    1986                  
     1994                if(zoteroField == "locator") { 
     1995                    var value = citationItem.locator.toString(); 
     1996                } else if ( zoteroField == "volume" && citationItem && citationItem.volume) {  
     1997                // special handling for volume field 
     1998                    var value = citationItem.volume; 
     1999                } else if(zoteroField == "edition" && citationItem && citationItem.edition) { 
     2000                // edition too 
     2001                    var value = citationItem.edition; 
     2002                } else { 
     2003                    var value = this.zoteroItem.getField(zoteroField, false, true).toString(); 
     2004                } 
     2005 
    19872006                // Quoted strings are never numeric 
    19882007                if(value.match(Zotero.CSL._quotedRegexp)) { 
    19892008                        continue; 
  • chrome/locale/en-US/zotero/zotero.dtd

    diff -r -u zotero-trunk.orig/chrome/locale/en-US/zotero/zotero.dtd zotero-trunk/chrome/locale/en-US/zotero/zotero.dtd
    old new  
    132132<!ENTITY zotero.citation.suppressAuthor.label                   "Suppress Author"> 
    133133<!ENTITY zotero.citation.prefix.label                                   "Prefix:"> 
    134134<!ENTITY zotero.citation.suffix.label                                   "Suffix:"> 
     135<!ENTITY zotero.citation.volume.label                                   "Volume:"> 
    135136 
    136137<!ENTITY zotero.richText.italic.label                                   "Italic"> 
    137138<!ENTITY zotero.richText.bold.label                                             "Bold">