From 20b44f77eaf7a0d475c361c5e966649a3b1f8ace Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Sun, 5 Feb 2017 17:54:09 -0500 Subject: [PATCH] Only override key events for keys that are used. --- src/js/pannellum.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/js/pannellum.js b/src/js/pannellum.js index f1865ca..382740b 100644 --- a/src/js/pannellum.js +++ b/src/js/pannellum.js @@ -102,6 +102,8 @@ var defaultConfig = { loadButtonLabel: 'Click to\nLoad\nPanorama', }; +var usedKeyNumbers = [16, 17, 27, 37, 38, 39, 40, 61, 65, 68, 83, 87, 107, 109, 173, 187, 189]; + // Initialize container container = typeof container === 'string' ? document.getElementById(container) : container; container.classList.add('pnlm-container'); @@ -950,9 +952,10 @@ function onDocumentKeyPress(event) { // Record key pressed var keynumber = event.which || event.keycode; - // Override default action except for tabbing - if (keynumber != 9) - event.preventDefault(); + // Override default action for keys that are used + if (usedKeyNumbers.indexOf(keynumber) < 0) + return + event.preventDefault(); // If escape key is pressed if (keynumber == 27) { @@ -982,14 +985,13 @@ function clearKeys() { * @param {KeyboardEvent} event - Document key up event. */ function onDocumentKeyUp(event) { - // Override default action - event.preventDefault(); + // Record key pressed + var keynumber = event.which || event.keycode; - // Record key released - var keynumber = event.keycode; - if (event.which) { - keynumber = event.which; - } + // Override default action for keys that are used + if (usedKeyNumbers.indexOf(keynumber) < 0) + return + event.preventDefault(); // Change key changeKey(keynumber, false); @@ -1005,12 +1007,12 @@ function changeKey(keynumber, value) { var keyChanged = false; switch(keynumber) { // If minus key is released - case 109: case 189: case 17: + case 109: case 189: case 17: case 173: if (keysDown[0] != value) { keyChanged = true; } keysDown[0] = value; break; // If plus key is released - case 107: case 187: case 16: + case 107: case 187: case 16: case 61: if (keysDown[1] != value) { keyChanged = true; } keysDown[1] = value; break;