Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support to define classNames in allowIn #204

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/hotkeys.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* angular-hotkeys v1.6.0
* https://chieffancypants.github.io/angular-hotkeys
* Copyright (c) 2015 Wes Cruver
* Copyright (c) 2016 Wes Cruver
* License: MIT
*/
.cfp-hotkeys-container {
Expand Down
39 changes: 22 additions & 17 deletions build/hotkeys.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* angular-hotkeys v1.6.0
* https://chieffancypants.github.io/angular-hotkeys
* Copyright (c) 2015 Wes Cruver
* Copyright (c) 2016 Wes Cruver
* License: MIT
*/
/*
Expand Down Expand Up @@ -62,7 +62,7 @@
'</tr>' +
'</tbody></table>' +
'<div ng-bind-html="footer" ng-if="footer"></div>' +
'<div class="cfp-hotkeys-close" ng-click="toggleCheatSheet()">×</div>' +
'<div class="cfp-hotkeys-close" ng-click="toggleCheatSheet()">&#215;</div>' +
'</div></div>';

/**
Expand Down Expand Up @@ -98,14 +98,14 @@
*/
function symbolize (combo) {
var map = {
command : '⌘',
shift : '⇧',
left : '←',
right : '→',
up : '↑',
down : '↓',
'return' : '↩',
backspace : '⌫'
command : '\u2318', // ⌘
shift : '\u21E7', // ⇧
left : '\u2190', // ←
right : '\u2192', // →
up : '\u2191', // ↑
down : '\u2193', // ↓
'return' : '\u23CE', // ⏎
backspace : '\u232B' // ⌫
};
combo = combo.split('+');

Expand Down Expand Up @@ -221,9 +221,9 @@
* attached. This is useful to catch when the scopes are `$destroy`d and
* then automatically unbind the hotkey.
*
* @type {Array}
* @type {Object}
*/
var boundScopes = [];
var boundScopes = {};

if (this.useNgRoute) {
$rootScope.$on('$routeChangeSuccess', function (event, route) {
Expand Down Expand Up @@ -392,14 +392,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<preventIn.length; i++) {
if (preventIn[i] === nodeName) {
if (preventIn[i] === nodeName && !classNameAllowed) {
shouldExecute = false;
break;
}
Expand Down Expand Up @@ -590,13 +594,14 @@
return {
restrict: 'A',
link: function (scope, el, attrs) {
var key, allowIn;
var keys = [],
allowIn;

angular.forEach(scope.$eval(attrs.hotkey), function (func, hotkey) {
// split and trim the hotkeys string into array
allowIn = typeof attrs.hotkeyAllowIn === "string" ? attrs.hotkeyAllowIn.split(/[\s,]+/) : [];

key = hotkey;
keys.push(hotkey);

hotkeys.add({
combo: hotkey,
Expand All @@ -609,7 +614,7 @@

// remove the hotkey if the directive is destroyed:
el.bind('$destroy', function() {
hotkeys.del(key);
angular.forEach(keys, hotkeys.del);
});
}
};
Expand Down Expand Up @@ -1034,7 +1039,7 @@
}

function _belongsTo(element, ancestor) {
if (element === document) {
if (element === null || element === document) {
return false;
}

Expand Down
Loading