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 26 26 "suffix":"value", 27 27 "locatorType":"selectedIndex", 28 28 "locator":"value", 29 "suppressAuthor":"checked" 29 "suppressAuthor":"checked", 30 "volume-selector":"value", 31 "volume":"value", 32 "issued":"value", 33 "edition":"value" 30 34 }; 31 35 32 36 var _itemData = new Object(); … … 52 56 this.confirmRegenerate = confirmRegenerate; 53 57 this.accept = accept; 54 58 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 56 204 /* 57 205 * To generate unique keys for items in multi-cite list 58 206 */ … … 64 212 * initialize add citation dialog 65 213 */ 66 214 function load() { 215 volumeNumberInit(); 67 216 document.getElementById("multiple-sources-button").label = Zotero.getString("citation.multipleSources"); 68 217 document.getElementById("show-editor-button").label = Zotero.getString("citation.showEditor"); 69 218 … … 77 226 if(io.citation.sortable) { 78 227 _sortCheckbox = document.getElementById("keepSorted"); 79 228 _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; 81 230 _sortCheckbox.checked = io.citation.properties.sort; 82 231 } 83 232 … … 108 257 if(io.citation.citationItems.length) { 109 258 if(io.citation.citationItems.length == 1) { 110 259 // single citation 260 volumeNumber(io.citation.citationItems[0].itemID); 111 261 _suppressNextTreeSelect = true; 112 262 itemsView.selectItem(io.citation.citationItems[0].itemID); // treeview from selectItemsDialog.js 113 263 for(var property in _preserveData) { … … 223 373 document.getElementById("add").disabled = !itemID; 224 374 document.getElementById("remove").disabled = true; 225 375 pos = document.getElementById("citation-list").childNodes.length; 376 volumeNumber(itemID,pos); 226 377 } else { 378 volumeNumber(itemID); 227 379 _updateAccept(); 228 380 _updatePreview(); 229 381 } … … 237 389 var itemID = (selectedListItem ? selectedListItem.value : false); 238 390 var pos = selectedListItem.parentNode.selectedIndex; 239 391 _itemSelected(itemID,pos); 392 393 volumeNumber(itemID,pos); 240 394 241 395 document.getElementById("remove").disabled = !itemID; 242 396 document.getElementById("add").disabled = true; … … 330 484 * Ask whether to modfiy the preview 331 485 */ 332 486 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 333 516 if(document.getElementById('editor').value == _originalHTML || _originalHTML === undefined) { 334 517 // no changes; just update without asking 335 518 _updatePreview(); … … 453 636 * itemID is undefined, only updates _itemData array 454 637 */ 455 638 function _itemSelected(itemID,pos) { 639 // not idempotent! must only run once when selection is changed 456 640 var itemDataID = (itemID ? multiKey(itemID,pos) : undefined); 457 641 if(_lastSelected && !_itemData[_lastSelected]) { 458 642 _itemData[_lastSelected] = new Object(); … … 464 648 465 649 // save property 466 650 if(_lastSelected) { 467 if( property== "locatorType") {651 if(box == "locatorType") { 468 652 _itemData[_lastSelected][box] = domBox.selectedItem.value; 469 653 } else { 470 654 _itemData[_lastSelected][box] = domBox[property]; … … 487 671 domBox[property] = ""; 488 672 } 489 673 } 490 if(item ID !== undefined) _lastSelected = itemDataID;674 if(itemDataID !== undefined) _lastSelected = itemDataID; 491 675 } 492 676 493 677 /* -
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 181 181 <separator flex="4"/> 182 182 <vbox flex="1"> 183 183 <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"/> 186 196 </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"/> 188 200 </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> 192 202 </hbox> 193 203 </vbox> 194 204 -
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 783 783 784 784 for(var j=0; j<variables.length; j++) { 785 785 if(ignore[0][variables[j]]) continue; 786 786 var text = citationItem && citationItem.locator ? citationItem.locator : ""; 787 787 if(variables[j] == "locator") { 788 788 // special case for locator 789 789 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"); 790 799 } else if(variables[j] == "firstref") { 791 800 // note number of first reference to this citation 792 var text = citationItem && citationItem.first ref ? citationItem.firstref : 0;801 var text = citationItem && citationItem.firstRef ? citationItem.firstRef : 0; 793 802 } else if(citationItem && citationItem._csl && citationItem._csl[variables[j]]) { 794 803 // override if requested 795 804 var text = citationItem._csl[variables[j]]; … … 1982 1991 1983 1992 var matches; 1984 1993 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 1987 2006 // Quoted strings are never numeric 1988 2007 if(value.match(Zotero.CSL._quotedRegexp)) { 1989 2008 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 132 132 <!ENTITY zotero.citation.suppressAuthor.label "Suppress Author"> 133 133 <!ENTITY zotero.citation.prefix.label "Prefix:"> 134 134 <!ENTITY zotero.citation.suffix.label "Suffix:"> 135 <!ENTITY zotero.citation.volume.label "Volume:"> 135 136 136 137 <!ENTITY zotero.richText.italic.label "Italic"> 137 138 <!ENTITY zotero.richText.bold.label "Bold">