Browse Source

Hide context menu on mousedown, not click

tags/v0.1.0
Gerben 5 years ago
parent
commit
f2ba0c3ad8
1 changed files with 9 additions and 3 deletions
  1. +9
    -3
      app/create-bookmarks/contentscript.js

+ 9
- 3
app/create-bookmarks/contentscript.js View File

@@ -64,7 +64,7 @@ export default async function init(playlist) {
menuEl = html`
<ul class="context-menu" style="top: ${top}; left: ${left};">
<li>
<button onclick=${createBookmark}>
<button onclick=${() => { hideMenu(); createBookmark(); }}>
${browser.i18n.getMessage(end !== undefined
? 'bookmarkSelectionContextMenuItemForFragment'
: 'bookmarkSelectionContextMenuItemForSingleMoment'
@@ -76,7 +76,13 @@ export default async function init(playlist) {
document.body.appendChild(menuEl);
}

document.addEventListener('contextmenu', onContextMenu, false);
function onMouseDown(event) {
// A mouse-down outside the menu hides the menu.
if (menuEl && !menuEl.contains(event.target)) { // note nodeX.contains(nodeX) === true
hideMenu();
}
}

document.addEventListener('click', event => { hideMenu(); });
document.addEventListener('contextmenu', onContextMenu);
document.addEventListener('mousedown', onMouseDown);
}

Loading…
Cancel
Save