From a8500150b0bc5e4c0e78cc71a73a15f6db9a35d8 Mon Sep 17 00:00:00 2001 From: Hung Nguyen Date: Sat, 14 Apr 2018 21:43:19 +0700 Subject: [PATCH] fixed menu popup on alt --- browser/main/index.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/browser/main/index.js b/browser/main/index.js index ae906538..3fa682cd 100644 --- a/browser/main/index.js +++ b/browser/main/index.js @@ -24,6 +24,46 @@ document.addEventListener('dragover', function (e) { e.stopPropagation() }) +// prevent menu from popup when alt pressed +// but still able to toggle menu when only alt is pressed +let isAltPressing = false +let isAltWithMouse = false +let isAltWithOtherKey = false +let isOtherKey = false + +document.addEventListener('keydown', function (e) { + if (e.key === 'Alt') { + isAltPressing = true + if (isOtherKey) { + isAltWithOtherKey = true + } + } else { + if (isAltPressing) { + isAltWithOtherKey = true + } + isOtherKey = true + } +}) + +document.addEventListener('mousedown', function (e) { + if (isAltPressing) { + isAltWithMouse = true + } +}) + +document.addEventListener('keyup', function (e) { + if (e.key === 'Alt') { + if (isAltWithMouse || isAltWithOtherKey) { + console.log(isAltWithMouse, isAltWithOtherKey) + e.preventDefault() + } + isAltWithMouse = false + isAltWithOtherKey = false + isAltPressing = false + isOtherKey = false + } +}) + document.addEventListener('click', function (e) { const className = e.target.className if (!className && typeof (className) !== 'string') return