www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 53f4a49900572e3f63e383e28c08162827877332
parent 28c64a3bd0abb19b12c0b4588f906f4314c677ee
Author: Simon Kornblith <simon@simonster.com>
Date:   Fri, 29 Jul 2011 20:32:39 +0000

- "Keep Sources Sorted" now works
- Option to open classic dialog


Diffstat:
Mchrome/content/zotero/integration/quickFormat.js | 163++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------
Mchrome/content/zotero/integration/quickFormat.xul | 13++++++++++++-
Mchrome/content/zotero/xpcom/integration.js | 5++++-
Mchrome/locale/en-US/zotero/zotero.dtd | 3+++
Mchrome/skin/default/zotero/integration.css | 15+++++++++++----
5 files changed, 162 insertions(+), 37 deletions(-)

diff --git a/chrome/content/zotero/integration/quickFormat.js b/chrome/content/zotero/integration/quickFormat.js @@ -24,17 +24,14 @@ */ var Zotero_QuickFormat = new function () { - var io, qfs, qfi, qfiWindow, qfiDocument, qfe, - qfb, qfbHeight, - referenceBox, referenceHeight, - dragX, dragY, curLocator, curLocatorLabel, - curIDs = [], curResizer, dragging; + var io, qfs, qfi, qfiWindow, qfiDocument, qfe, qfb, qfbHeight, keepSorted, showEditor, + referenceBox, referenceHeight, dragX, dragY, curLocator, curLocatorLabel, curIDs = [], + curResizer, dragging; const SHOWN_REFERENCES = 7; - /** - * Initialize add citation dialog - */ - this.onLoad = function() { + this.onDOMContentLoaded = function() { + io = window.arguments[0].wrappedJSObject; + qfs = document.getElementById("quick-format-search"); qfi = document.getElementById("quick-format-iframe"); qfb = document.getElementById("quick-format-entry"); @@ -44,9 +41,8 @@ var Zotero_QuickFormat = new function () { qfiDocument = qfi.contentDocument; qfb.addEventListener("keypress", _onQuickSearchKeyPress, false); qfe = qfiDocument.getElementById("quick-format-editor"); - qfe.focus(); - // Add labels to popup + // add labels to popup var locators = Zotero.Cite.labels; var menu = document.getElementById("locator-label"); var labelList = document.getElementById("locator-label-popup"); @@ -62,8 +58,24 @@ var Zotero_QuickFormat = new function () { } menu.selectedIndex = 0; + keepSorted = document.getElementById("keep-sorted"); + showEditor = document.getElementById("show-editor"); + if(io.sortable) { + keepSorted.hidden = false; + if(!io.citation.properties.unsorted) { + keepSorted.setAttribute("checked", "true"); + } + } + } + + /** + * Initialize add citation dialog + */ + this.onLoad = function() { + window.focus(); + qfe.focus(); + // load citation data - io = window.arguments[0].wrappedJSObject; if(io.citation.citationItems.length) { // hack to get spacing right var evt = qfiDocument.createEvent("KeyboardEvent"); @@ -71,13 +83,10 @@ var Zotero_QuickFormat = new function () { 0, 0, 0, 0, 0, " ".charCodeAt(0)) qfe.dispatchEvent(evt); - window.setTimeout(function() { + window.setTimeout(function() { var node = qfe.firstChild; node.nodeValue = ""; - - for(var i=0; i<io.citation.citationItems.length; i++) { - _insertBubble(io.citation.citationItems[i], node); - } + _showCitation(node); }, 1); } }; @@ -176,18 +185,14 @@ var Zotero_QuickFormat = new function () { if(charRe.test(str)) { Zotero.debug("QuickFormat: QuickSearch: "+str); - try { - s.addCondition("quicksearch-titlesAndCreators", "contains", str); - } catch(e) { - Zotero.debug(e.toString()); - } + s.addCondition("quicksearch-titlesAndCreators", "contains", str); haveConditions = true; } if(year) { Zotero.debug("QuickFormat: Year: "+year); - s.addCondition("date", "isAfter", (year-1)+"-12-31 23:59:59"); - s.addCondition("date", "isBefore", (year+1)+"-01-01 00:00:00"); + s.addCondition("date", "isAfter", (year)+"-01-01 00:00:00"); + s.addCondition("date", "isBefore", (year)+"-12-31 23:59:59"); haveConditions = true; } @@ -361,8 +366,8 @@ var Zotero_QuickFormat = new function () { // make sure that there are no rogue <br>s var elements = qfe.getElementsByTagName("br"); - for(var i=0, n=elements.length; i<n; i++) { - elements[i].parentNode.removeChild(elements[i]); + while(elements.length) { + elements[0].parentNode.removeChild(elements[0]); } return bubble; } @@ -394,6 +399,7 @@ var Zotero_QuickFormat = new function () { node.nodeValue = ""; var bubble = _insertBubble(citationItem, node); _clearEntryList(); + _previewAndSort(); return true; } @@ -417,9 +423,8 @@ var Zotero_QuickFormat = new function () { } if(height === window.innerHeight) return; - Zotero.debug(qfeHeight); if(qfeHeight > 20) { - qfs.style.height = (22-16+qfeHeight+(qfi.style.height == "22px" ? 2 : -2))+"px"; + qfs.style.height = (22-16+qfeHeight+(qfs.style.height == "22px" ? 2 : -2))+"px"; qfe.style.lineHeight = "18px"; qfs.setAttribute("multiline", true); } else { @@ -433,14 +438,85 @@ var Zotero_QuickFormat = new function () { } /** - * Accepts current selection and adds citation + * Clears all citations */ - function _accept() { + function _clearCitation() { + var citations = qfe.getElementsByClassName("quick-format-bubble"); + while(citations.length) { + citations[0].parentNode.removeChild(citations[0]); + } + } + + /** + * Shows citations in the citation object + */ + function _showCitation(insertBefore) { + if(!io.citation.properties.unsorted + && keepSorted.hasAttribute("checked") + && io.citation.sortedItems.length) { + for(var i=0, n=io.citation.sortedItems.length; i<n; i++) { + _insertBubble(io.citation.sortedItems[i][1], insertBefore); + } + } else { + for(var i=0, n=io.citation.citationItems.length; i<n; i++) { + _insertBubble(io.citation.citationItems[i], insertBefore); + } + } + } + + /** + * Populates the citation object + */ + function _updateCitationObject() { var nodes = qfe.childNodes; io.citation.citationItems = []; for(var i=0, n=nodes.length; i<n; i++) { if(nodes[i].citationItem) io.citation.citationItems.push(nodes[i].citationItem); } + + if(io.sortable) { + if(keepSorted.hasAttribute("checked")) { + delete io.citation.properties.unsorted; + } else { + io.citation.properties.unsorted = true; + } + } + } + + /** + * Generates the preview and sorts citations + */ + function _previewAndSort() { + var shouldKeepSorted = keepSorted.hasAttribute("checked"), + editorShowing = showEditor.hasAttribute("checked"); + if(!shouldKeepSorted && !editorShowing) return; + + _updateCitationObject(); + io.previewFunction(); + if(shouldKeepSorted) { + // means we need to resort citations + _clearCitation(); + _showCitation(); + + // select past last citation + var lastBubble = qfe.getElementsByClassName("quick-format-bubble"); + lastBubble = lastBubble[lastBubble.length-1]; + + var nodeRange = qfiDocument.createRange(); + nodeRange.selectNode(lastBubble); + nodeRange.collapse(false); + + var selection = qfiWindow.getSelection(); + selection.removeAllRanges(); + selection.addRange(nodeRange); + } + } + + /** + * Accepts current selection and adds citation + */ + function _accept() { + _updateCitationObject(); window.close(); } @@ -515,7 +591,6 @@ var Zotero_QuickFormat = new function () { var el = qfiDocument.getElementById("zotero-drag"); if(el) { _insertBubble(dragging, el); - Zotero.debug(dragging); el.parentNode.removeChild(el); } }, 0); @@ -614,6 +689,31 @@ var Zotero_QuickFormat = new function () { }; /** + * Handle checking/unchecking "Keep Citations Sorted" + */ + this.onKeepSortedCommand = function(event) { + _previewAndSort(); + }; + + /** + * Handle checking/unchecking "Show Editor" + */ + this.onShowEditorCommand = function(event) { + }; + + /** + * Open classic Add Citation window + */ + this.onClassicViewCommand = function(event) { + _updateCitationObject(); + var newWindow = window.newWindow = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] + .getService(Components.interfaces.nsIWindowWatcher) + .openWindow(null, 'chrome://zotero/content/integration/addCitationDialog.xul', + '', 'chrome,centerscreen,resizable', io); + newWindow.addEventListener("load", function() { window.close(); }, false); + } + + /** * Resizes windows * @constructor */ @@ -651,4 +751,5 @@ var Zotero_QuickFormat = new function () { }; } +window.addEventListener("DOMContentLoaded", Zotero_QuickFormat.onDOMContentLoaded, false); window.addEventListener("load", Zotero_QuickFormat.onLoad, false); \ No newline at end of file diff --git a/chrome/content/zotero/integration/quickFormat.xul b/chrome/content/zotero/integration/quickFormat.xul @@ -48,7 +48,18 @@ <vbox id="zotero-select-items-container" flex="1"> <hbox id="quick-format-entry" ondragstart="Zotero_QuickFormat.onDragStart(this, event)"> <hbox id="quick-format-search" flex="1" align="start"> - <image id="zotero-icon"/> + <toolbarbutton id="zotero-icon" type="menu"> + <menupopup> + <menuitem id="keep-sorted" label="&zotero.citation.keepSorted.label;" + oncommand="Zotero_QuickFormat.onKeepSortedCommand()" type="checkbox" + hidden="true"/> + <menuitem id="show-editor" label="&zotero.integration.showEditor.label;" + oncommand="Zotero_QuickFormat.onShowEditorCommand()" type="checkbox" + hidden="true"/> + <menuitem id="classic-view" label="&zotero.integration.classicView.label;" + oncommand="Zotero_QuickFormat.onClassicViewCommand()"/> + </menupopup> + </toolbarbutton> <!-- javascript:encodeURIComponent('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="chrome://zotero/skin/integration.css"/></head><body id="quick-format-editor"/></html>') --> <iframe id="quick-format-iframe" ondragstart="event.stopPropagation()" src="data:application/xhtml+xml,%3C!DOCTYPE%20html%20PUBLIC%20%22-%2F%2FW3C%2F%2FDTD%20XHTML%201.0%20Strict%2F%2FEN%22%20%22http%3A%2F%2Fwww.w3.org%2FTR%2Fxhtml1%2FDTD%2Fxhtml1-strict.dtd%22%3E%3Chtml%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Chead%3E%3Clink%20rel%3D%22stylesheet%22%20type%3D%22text%2Fcss%22%20href%3D%22chrome%3A%2F%2Fzotero%2Fskin%2Fintegration.css%22%2F%3E%3C%2Fhead%3E%3Cbody%20contenteditable%3D%22true%22%20id%3D%22quick-format-editor%22%2F%3E%3C%2Fhtml%3E" tabindex="1" flex="1"/> diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js @@ -1073,7 +1073,10 @@ Zotero.Integration.Session.prototype._displayDialog = function(url, options, io) .getService(Components.interfaces.nsIWindowWatcher) .openWindow(null, url, '', 'chrome,centerscreen'+(options ? ','+options : ""), (io ? io : null)); Zotero.Integration.activate(window); - while(!window.closed) Zotero.mainThread.processNextEvent(true); + while(!window.closed) { + Zotero.mainThread.processNextEvent(true); + if(window.newWindow) window = window.newWindow; + } } /** diff --git a/chrome/locale/en-US/zotero/zotero.dtd b/chrome/locale/en-US/zotero/zotero.dtd @@ -176,6 +176,9 @@ <!ENTITY zotero.integration.prefs.bookmarks.label "Bookmarks"> <!ENTITY zotero.integration.prefs.bookmarks.caption "Bookmarks are preserved across Microsoft Word and OpenOffice, but may be accidentally modified. For &#xA;compatibility reasons, citations cannot be inserted into footnotes or endnotes when this option is selected."> +<!ENTITY zotero.integration.showEditor.label "Show Editor"> +<!ENTITY zotero.integration.classicView.label "Classic View"> + <!ENTITY zotero.integration.references.label "References in Bibliography"> <!ENTITY zotero.sync.button "Sync with Zotero Server"> diff --git a/chrome/skin/default/zotero/integration.css b/chrome/skin/default/zotero/integration.css @@ -235,8 +235,16 @@ richlistitem[selected="true"] { #zotero-icon { list-style-image: url("chrome://zotero/skin/zotero-new-z-16px.png"); + background-color: #fff; + margin: 0 0 0 -13px; + padding: 0; +} + +#zotero-icon .toolbarbutton-text { + display: none; +} + +#zotero-icon .toolbarbutton-icon { width: 16px; height: 16px; - background-color: #fff; - margin-left: -13px; -} -\ No newline at end of file +}