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, <menu> 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.)
This commit is contained in:
Dan Stillman 2016-04-07 06:09:14 -04:00
parent 4bc4acb923
commit afaaf20c90
2 changed files with 36 additions and 4 deletions

View File

@ -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();
}
}
);
}

View File

@ -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'));