diff --git a/application/palemoon/app/profile/palemoon.js b/application/palemoon/app/profile/palemoon.js index 45f0e9925f..9bc52cf4c5 100644 --- a/application/palemoon/app/profile/palemoon.js +++ b/application/palemoon/app/profile/palemoon.js @@ -494,6 +494,9 @@ pref("browser.bookmarks.autoExportHTML", false); // 0: no backups created (and deletes all existing backups) pref("browser.bookmarks.max_backups", 10); +// Whether menu should close after Ctrl-click, middle-click, etc. +pref("browser.bookmarks.openInTabClosesMenu", true); + // Scripts & Windows prefs pref("dom.disable_open_during_load", true); pref("javascript.options.showInConsole", true); diff --git a/application/palemoon/base/content/browser-menubar.inc b/application/palemoon/base/content/browser-menubar.inc index 8a93e3a55e..0680876f6b 100644 --- a/application/palemoon/base/content/browser-menubar.inc +++ b/application/palemoon/base/content/browser-menubar.inc @@ -371,6 +371,7 @@ placespopup="true" context="placesContext" openInTabs="children" + onmouseup="BookmarksEventHandler.onMouseUp(event);" oncommand="BookmarksEventHandler.onCommand(event, this.parentNode._placesView);" onclick="BookmarksEventHandler.onClick(event, this.parentNode._placesView);" onpopupshowing="PlacesCommandHook.updateBookmarkAllTabsCommand(); diff --git a/application/palemoon/base/content/browser-places.js b/application/palemoon/base/content/browser-places.js index f58b4118e3..a420d96650 100644 --- a/application/palemoon/base/content/browser-places.js +++ b/application/palemoon/base/content/browser-places.js @@ -767,17 +767,46 @@ HistoryMenu.prototype = { * Functions for handling events in the Bookmarks Toolbar and menu. */ var BookmarksEventHandler = { + + /** + * Handler for mouseUp event for an item in the bookmarks toolbar or menu. + * When items are middle-clicked (or clicked with modifier), check if the + * menu should remain open. + * @param aEvent + * DOMEvent for the click + */ + + onMouseUp(aEvent) { + // Handles left-click with modifier if not browser.bookmarks.openInTabClosesMenu. + if (aEvent.button != 0 || + Services.prefs.getBoolPref("browser.bookmarks.openInTabClosesMenu", true)) + return; + let target = aEvent.originalTarget; + if (target.tagName != "menuitem") + return; +#ifdef XP_MACOSX + var modifKey = aEvent.metaKey; +#else + var modifKey = aEvent.ctrlKey; +#endif + // Don't keep menu open for 'Open all in Tabs'. + if (modifKey && !target.classList.contains("openintabs-menuitem")) { + target.setAttribute("closemenu", "none"); + } + }, + /** * Handler for click event for an item in the bookmarks toolbar or menu. * Menus and submenus from the folder buttons bubble up to this handler. * Left-click is handled in the onCommand function. * When items are middle-clicked (or clicked with modifier), open in tabs. - * If the click came through a menu, close the menu. + * If the click came through a menu, close the menu unless preffed otherwise. * @param aEvent * DOMEvent for the click * @param aView * The places view which aEvent should be associated with. */ + onClick: function(aEvent, aView) { // Only handle middle-click or left-click with modifiers. var modifKey = aEvent.ctrlKey || aEvent.shiftKey; @@ -786,19 +815,23 @@ var BookmarksEventHandler = { } var target = aEvent.originalTarget; - // If this event bubbled up from a menu or menuitem, close the menus. - // Do this before opening tabs, to avoid hiding the open tabs confirm-dialog. - if (target.localName == "menu" || target.localName == "menuitem") { - for (node = target.parentNode; node; node = node.parentNode) { - if (node.localName == "menupopup") { - node.hidePopup(); - } else if (node.localName != "menu" && - node.localName != "splitmenu" && - node.localName != "hbox" && - node.localName != "vbox" ) { - break; - } - } + // If this event bubbled up from a menu or menuitem, + // close the menus if browser.bookmarks.openInTabClosesMenu. + if ((Services.prefs.getBoolPref("browser.bookmarks.openInTabClosesMenu", true) && + target.tagName == "menuitem") || + target.tagName == "menu" || + target.classList.contains("openintabs-menuitem")) { + closeMenus(aEvent.target); + } + // Command already precesssed so remove any closemenu attr set in onMouseUp. + if (aEvent.button == 0 && + target.tagName == "menuitem" && + target.getAttribute("closemenu") == "none") { + // On Mac we need to extend when we remove the flag, to avoid any pre-close + // animations. + setTimeout(() => { + target.removeAttribute("closemenu"); + }, 500); } if (target._placesNode && PlacesUtils.nodeIsContainer(target._placesNode)) { diff --git a/application/palemoon/base/content/browser.xul b/application/palemoon/base/content/browser.xul index 9575199813..027c7a5177 100644 --- a/application/palemoon/base/content/browser.xul +++ b/application/palemoon/base/content/browser.xul @@ -548,6 +548,7 @@ placespopup="true" context="placesContext" openInTabs="children" + onmouseup="BookmarksEventHandler.onMouseUp(event);" oncommand="BookmarksEventHandler.onCommand(event, this.parentNode._placesView);" onclick="event.stopPropagation(); BookmarksEventHandler.onClick(event, this.parentNode._placesView);" @@ -704,6 +705,7 @@