From 74a43c06c62650a7fcef7a02682a8286e301c9ad Mon Sep 17 00:00:00 2001 From: Greg Denehy Date: Fri, 5 May 2017 22:32:41 +0930 Subject: [PATCH] Makes use of key binding API --- menu.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/menu.js b/menu.js index 18a0876..c36b39a 100644 --- a/menu.js +++ b/menu.js @@ -123,11 +123,13 @@ var RevealMenu = window.RevealMenu || (function(){ } function onDocumentKeyDown(event) { - if (event.keyCode === 77) { - toggleMenu(); - } else if (isOpen()) { + // opening menu is handled by registering key binding with Reveal below + if (isOpen()) { event.stopImmediatePropagation(); switch( event.keyCode ) { + // case 77: + // closeMenu(); + // break; // h, left - change panel case 72: case 37: prevPanel(); @@ -260,11 +262,13 @@ var RevealMenu = window.RevealMenu || (function(){ if (config.keyboardCondition && typeof config.keyboardCondition === 'function') { // combine user defined keyboard condition with the menu's own condition var userCondition = config.keyboardCondition; - config.keyboardCondition = function() { - return userCondition() && !isOpen(); + config.keyboardCondition = function(event) { + return userCondition(event) && (!isOpen() || event.keyCode == 77); }; } else { - config.keyboardCondition = function() { return !isOpen(); } + config.keyboardCondition = function(event) { + return !isOpen() || event.keyCode == 77; + } } } @@ -665,6 +669,8 @@ var RevealMenu = window.RevealMenu || (function(){ } } + Reveal.addKeyBinding({keyCode: 77, key: 'M', description: 'Toggle menu'}, toggleMenu); + dispatchEvent('menu-ready'); } })