From b2c9a421033f62801003851e0708f11b7edbac36 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sun, 10 Dec 2017 23:15:09 -0500 Subject: [PATCH] Prevent Add Item by Identifier button from flashing on textbox click Nesting the panel in the toolbarbutton seems to cause the button to appear as if it were clicked on any click/right-click in the textbox, and I couldn't find a way to prevent that with event.stopPropagation(). Also cleans up this code in general --- chrome/content/zotero/lookup.js | 97 +++++++++++++++------------- chrome/content/zotero/zoteroPane.xul | 47 ++++++++------ 2 files changed, 80 insertions(+), 64 deletions(-) diff --git a/chrome/content/zotero/lookup.js b/chrome/content/zotero/lookup.js index 72bd7ce14..0a7431aa5 100644 --- a/chrome/content/zotero/lookup.js +++ b/chrome/content/zotero/lookup.js @@ -92,6 +92,45 @@ var Zotero_Lookup = new function () { return false; }); + + this.showPanel = function (button) { + var panel = document.getElementById('zotero-lookup-panel'); + panel.openPopup(button, "after_start", 16, -2, false, false); + } + + + /** + * Focuses the field + */ + this.onShowing = function (event) { + // Ignore context menu + if (event.originalTarget.id != 'zotero-lookup-panel') return; + + document.getElementById("zotero-lookup-panel").style.padding = "10px"; + this.getActivePanel().getElementsByTagName('textbox')[0].focus(); + } + + + /** + * Cancels the popup and resets fields + */ + this.onHidden = function (event) { + // Ignore context menu + if (event.originalTarget.id != 'zotero-lookup-panel') return; + + document.getElementById("zotero-lookup-textbox").value = ""; + document.getElementById("zotero-lookup-multiline-textbox").value = ""; + Zotero_Lookup.toggleProgress(false); + } + + + this.getActivePanel = function() { + var mlPanel = document.getElementById("zotero-lookup-multiline"); + if (mlPanel.collapsed) return document.getElementById("zotero-lookup-singleLine"); + return mlPanel; + } + + /** * Handles a key press */ @@ -114,50 +153,27 @@ var Zotero_Lookup = new function () { return true; } - /** - * Focuses the field - */ - this.onShowing = function (event) { - // Ignore context menu - if (event.originalTarget.id != 'zotero-lookup-panel') return; - - document.getElementById("zotero-lookup-panel").style.padding = "10px"; - - // Workaround for field being truncated in middle - // https://github.com/zotero/zotero/issues/343 - this.toggleMultiline(true); - - var identifierElement = Zotero_Lookup.toggleMultiline(false); - Zotero_Lookup.toggleProgress(false); - identifierElement.focus(); - } - /** - * Cancels the popup and resets fields - */ - this.onHidden = function (event) { - // Ignore context menu to prevent blanking on paste - if (event.originalTarget.id != 'zotero-lookup-panel') return; - - var txtBox = Zotero_Lookup.toggleMultiline(false); - var mlTextbox = document.getElementById("zotero-lookup-multiline-textbox"); - txtBox.value = ""; - mlTextbox.value = ""; - } - + this.onInput = function (event, textbox) { + this.adjustTextbox(textbox); + }; + + /** * Converts the textbox to multiline if newlines are detected */ - this.adjustTextbox = function(txtBox) { - if(txtBox.value.trim().match(/[\r\n]/)) { + this.adjustTextbox = function (textbox) { + if (textbox.value.trim().match(/[\r\n]/)) { Zotero_Lookup.toggleMultiline(true); - } else { - //since we ignore trailing and leading newlines, we should also trim them for display - //can't use trim, because then we cannot add leading/trailing spaces to the single line textbox - txtBox.value = txtBox.value.replace(/^([ \t]*[\r\n]+[ \t]*)+|([ \t]*[\r\n]+[ \t]*)+$/g,""); + } + // Since we ignore trailing and leading newlines, we should also trim them for display + // can't use trim, because then we cannot add leading/trailing spaces to the single line textbox + else { + textbox.value = textbox.value.replace(/^([ \t]*[\r\n]+[ \t]*)+|([ \t]*[\r\n]+[ \t]*)+$/g,""); } } - + + /** * Performs the switch to multiline textbox and returns that textbox */ @@ -200,11 +216,4 @@ var Zotero_Lookup = new function () { document.getElementById("zotero-lookup-multiline-textbox").disabled = !!on; document.getElementById("zotero-lookup-multiline-progress").setAttribute("collapsed", !on); } - - this.getActivePanel = function() { - var mlPanel = document.getElementById("zotero-lookup-multiline"); - if(mlPanel.collapsed) return document.getElementById("zotero-lookup-singleLine"); - - return mlPanel; - } } diff --git a/chrome/content/zotero/zoteroPane.xul b/chrome/content/zotero/zoteroPane.xul index 4afcecbbf..11a430726 100644 --- a/chrome/content/zotero/zoteroPane.xul +++ b/chrome/content/zotero/zoteroPane.xul @@ -160,27 +160,34 @@ - - - - &zotero.lookup.description; - - - - - - - - - -