From b1506129646d7cbeec3b4bfbab148ecb9897a0ad Mon Sep 17 00:00:00 2001 From: Justin Verkuijl Date: Thu, 18 Feb 2016 08:57:38 +0100 Subject: [PATCH 1/2] added allowin to include classNames --- src/hotkeys.js | 6 +++++- test/hotkeys.coffee | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/hotkeys.js b/src/hotkeys.js index cf87fed..6c35b71 100644 --- a/src/hotkeys.js +++ b/src/hotkeys.js @@ -386,14 +386,18 @@ if (event) { var target = event.target || event.srcElement; // srcElement is IE only var nodeName = target.nodeName.toUpperCase(); + var elementClasses = target.className ? + target.className.split(/\s+/).map(function(className) {return className.toUpperCase();}) : + []; // check if the input has a mousetrap class, and skip checking preventIn if so if ((' ' + target.className + ' ').indexOf(' mousetrap ') > -1) { shouldExecute = true; } else { + var classNameAllowed = elementClasses.some(function(className) { return allowIn.indexOf(className) > -1; }); // don't execute callback if the event was fired from inside an element listed in preventIn for (var i=0; i KeyEvent.simulate('w'.charCodeAt(0), 90, undefined, $select[0]) expect(executed).toBe no + it 'should callback when hotkey is pressed in select field with allowIn class cfp-test', -> + executed = no + + $body = angular.element document.body + $select = angular.element '