From afaaf20c90a1ef5381d458bc9cba3aacf92088ad Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 7 Apr 2016 06:09:14 -0400 Subject: [PATCH] Allow click on menu title to select feed item add target Instead of requiring a click on the menuitem at the top of the submenu, allow a click on the menu itself. This is a hack that, among other things, replicates the flash effect on menuitems on OS X. Unfortunately, elements can't have checkboxes, so only the menuitem in the submenu will be checked. (Otherwise I'd remove the redundant menuitem in the submenu.) --- chrome/content/zotero/itemPane.js | 24 +++++++++++++++++-- .../zotero/xpcom/utilities_internal.js | 16 +++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/chrome/content/zotero/itemPane.js b/chrome/content/zotero/itemPane.js index 36114d624..e33a97f1b 100644 --- a/chrome/content/zotero/itemPane.js +++ b/chrome/content/zotero/itemPane.js @@ -251,8 +251,28 @@ var ZoteroItemPane = new function() { menu, target, function(event, libraryOrCollection) { - ZoteroItemPane.setTranslationTarget(libraryOrCollection); - event.stopPropagation(); + if (event.target.tagName == 'menu') { + Zotero.Promise.coroutine(function* () { + // Simulate menuitem flash on OS X + if (Zotero.isMac) { + event.target.setAttribute('_moz-menuactive', false); + yield Zotero.Promise.delay(50); + event.target.setAttribute('_moz-menuactive', true); + yield Zotero.Promise.delay(50); + event.target.setAttribute('_moz-menuactive', false); + yield Zotero.Promise.delay(50); + event.target.setAttribute('_moz-menuactive', true); + } + menu.hidePopup(); + + ZoteroItemPane.setTranslationTarget(libraryOrCollection); + event.stopPropagation(); + })(); + } + else { + ZoteroItemPane.setTranslationTarget(libraryOrCollection); + event.stopPropagation(); + } } ); } diff --git a/chrome/content/zotero/xpcom/utilities_internal.js b/chrome/content/zotero/xpcom/utilities_internal.js index 55233a28b..032c0181c 100644 --- a/chrome/content/zotero/xpcom/utilities_internal.js +++ b/chrome/content/zotero/xpcom/utilities_internal.js @@ -955,10 +955,13 @@ Zotero.Utilities.Internal = { return menuitem } - function _createMenu(label, icon) { + function _createMenu(label, value, icon, command) { let menu = doc.createElement('menu'); menu.setAttribute("label", label); + menu.setAttribute("value", value); menu.setAttribute("image", icon); + // Allow click on menu itself to select a target + menu.addEventListener('click', command); menu.classList.add('menu-iconic'); let menupopup = doc.createElement('menupopup'); menu.appendChild(menupopup); @@ -985,12 +988,21 @@ Zotero.Utilities.Internal = { collections = Zotero.Collections.getByLibrary(libraryOrCollection.id); } + // If no subcollections, place menuitem for target directly in containing men if (collections.length == 0) { elem.appendChild(menuitem); return menuitem } - var menu = _createMenu(libraryOrCollection.name, imageSrc); + // Otherwise create a submenu for the target's subcollections + var menu = _createMenu( + libraryOrCollection.name, + libraryOrCollection.collectionTreeViewID, + imageSrc, + function (event) { + clickAction(event, libraryOrCollection); + } + ); var menupopup = menu.firstChild; menupopup.appendChild(menuitem); menupopup.appendChild(doc.createElement('menuseparator'));