From 5284da05af1a2e92502d74d74f8063b498d1cb13 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Sun, 6 Jun 2010 00:57:47 +0000 Subject: [PATCH] - return "Keep Citations Sorted" checkbox - update to citeproc-js 1.0.22 From Frank's announcement: - Bypass sorting of citations that have a value for "unsorted" in citation.properties. This permits per-citation override of style-driven citation sorts, as supported by Zotero and required for some common use cases. --- .../zotero/integration/addCitationDialog.js | 106 +++++++++--------- chrome/content/zotero/xpcom/citeproc.js | 10 +- chrome/content/zotero/xpcom/integration.js | 56 +++++---- 3 files changed, 89 insertions(+), 83 deletions(-) diff --git a/chrome/content/zotero/integration/addCitationDialog.js b/chrome/content/zotero/integration/addCitationDialog.js index 0beca4849b..b75b60b4c5 100644 --- a/chrome/content/zotero/integration/addCitationDialog.js +++ b/chrome/content/zotero/integration/addCitationDialog.js @@ -42,6 +42,7 @@ var Zotero_Citation_Dialog = new function () { var _autoRegeneratePref; var _acceptButton; var _sortCheckbox; + var _citationList; var _originalHTML; var io; @@ -71,13 +72,13 @@ var Zotero_Citation_Dialog = new function () { // find accept button _acceptButton = document.getElementById("zotero-add-citation-dialog").getButton("accept"); _autoRegeneratePref = Zotero.Prefs.get("integration.autoRegenerate"); + _citationList = document.getElementById("citation-list"); // if a style with sortable citations, present checkbox - if(io.citation.sortable) { + if(io.sortable) { _sortCheckbox = document.getElementById("keepSorted"); _sortCheckbox.hidden = false; - if(io.citation.properties.sort === undefined) io.citation.properties.sort = true; - _sortCheckbox.checked = io.citation.properties.sort; + _sortCheckbox.checked = !io.citation.properties.unsorted; } // load locators @@ -217,30 +218,29 @@ var Zotero_Citation_Dialog = new function () { _updateAccept(); _updatePreview(); } - _configListPosition(document.getElementById("citation-list"), true); + _configListPosition(true); } /* * called when an item in the selected items list is clicked */ function listItemSelected() { - var itemList = document.getElementById("citation-list"); - var selectedListItem = itemList.getSelectedItem(0); + var selectedListItem = _citationList.getSelectedItem(0); var itemID = (selectedListItem ? selectedListItem.value : false); _itemSelected(itemID); - _configListPosition(itemList, !itemID); + _configListPosition(!itemID); document.getElementById("remove").disabled = !itemID; } - function _configListPosition(itemList,flag) { - var selectedIndex = itemList.selectedIndex; + function _configListPosition(flag) { + var selectedIndex = _citationList.selectedIndex; if (selectedIndex > 0) { document.getElementById("up").disabled = flag; } else { document.getElementById("up").disabled = true; } - if (selectedIndex < (itemList.getRowCount() - 1)) { + if (selectedIndex < (_citationList.getRowCount() - 1)) { document.getElementById("down").disabled = flag; } else { document.getElementById("down").disabled = true; @@ -248,22 +248,27 @@ var Zotero_Citation_Dialog = new function () { } function _move(direction) { + // automatically uncheck sorted checkbox if user is rearranging citation + if(_sortCheckbox && _sortCheckbox.checked) { + _sortCheckbox.checked = false; + sortCitation(); + } + var insertBeforeItem; - var itemList = document.getElementById("citation-list"); - var selectedListItem = itemList.getSelectedItem(0); + var selectedListItem = _citationList.getSelectedItem(0); var itemID = selectedListItem.value; - var selectedListIndex = itemList.selectedIndex; + var selectedListIndex = _citationList.selectedIndex; if (direction === -1) { insertBeforeItem = selectedListItem.previousSibling; } else { insertBeforeItem = selectedListItem.nextSibling.nextSibling; } - var listItem = itemList.removeChild(selectedListItem); - itemList.insertBefore(listItem, insertBeforeItem); - itemList.selectedIndex = (selectedListIndex + direction); + var listItem = _citationList.removeChild(selectedListItem); + _citationList.insertBefore(listItem, insertBeforeItem); + _citationList.selectedIndex = (selectedListIndex + direction); _itemSelected(itemID); _updatePreview(); - _configListPosition(itemList, false); + _configListPosition(false); } function up() { @@ -281,6 +286,8 @@ var Zotero_Citation_Dialog = new function () { var item = itemsView.getSelectedItems()[0]; // treeview from selectItemsDialog.js _itemSelected(item.getID()); _addItem(item); + _citationList.selectedIndex = _citationList.getRowCount()-1; + _citationList.focus(); // don't let someone select it again document.getElementById("add").disabled = true; @@ -295,8 +302,7 @@ var Zotero_Citation_Dialog = new function () { * Deletes a citation from the multipleSources list */ function remove() { - var citationList = document.getElementById("citation-list"); - var selectedListItem = citationList.getSelectedItem(0); + var selectedListItem = _citationList.getSelectedItem(0); var itemID = selectedListItem.value; // remove from _itemData @@ -312,7 +318,7 @@ var Zotero_Citation_Dialog = new function () { } // remove from list - citationList.removeChild(selectedListItem); + _citationList.removeChild(selectedListItem); _updateAccept(); _updatePreview(); @@ -323,22 +329,29 @@ var Zotero_Citation_Dialog = new function () { * Sorts the list of citations */ function sortCitation() { - io.citation.properties.sort = _sortCheckbox && _sortCheckbox.checked; - if(io.citation.properties.sort) { - _getCitation(); - - // delete all existing items from list - _clearCitationList(); - - // run preview function to re-sort, if it hasn't already been - // run - io.previewFunction(); - - // add items back to list - for(var i=0; i 0; var window = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] .getService(Components.interfaces.nsIWindowWatcher)