Skip to content

Commit

Permalink
released v3.8.9 (#352)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Apr 11, 2022
1 parent 973e607 commit 335d00f
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 29 deletions.
21 changes: 13 additions & 8 deletions dist/hotkeys.common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**!
* hotkeys-js v3.8.8
* hotkeys-js v3.8.9
* A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.
*
* Copyright (c) 2022 kenny wong <[email protected]>
Expand Down Expand Up @@ -318,7 +318,11 @@ var eachUnbind = function eachUnbind(_ref) {
}; // 对监听对应快捷键的回调函数进行处理


function eventHandler(event, handler, scope) {
function eventHandler(event, handler, scope, element) {
if (handler.element !== element) {
return;
}

var modifiersMatch; // 看它是否在当前范围

if (handler.scope === scope || handler.scope === 'all') {
Expand All @@ -345,7 +349,7 @@ function eventHandler(event, handler, scope) {
} // 处理keydown事件


function dispatch(event) {
function dispatch(event, element) {
var asterisk = _handlers['*'];
var key = event.keyCode || event.which || event.charCode; // 表单控件过滤 默认表单控件不触发快捷键

Expand Down Expand Up @@ -430,7 +434,7 @@ function dispatch(event) {
if (asterisk) {
for (var i = 0; i < asterisk.length; i++) {
if (asterisk[i].scope === scope && (event.type === 'keydown' && asterisk[i].keydown || event.type === 'keyup' && asterisk[i].keyup)) {
eventHandler(event, asterisk[i], scope);
eventHandler(event, asterisk[i], scope, element);
}
}
} // key 不在 _handlers 中返回
Expand All @@ -452,7 +456,7 @@ function dispatch(event) {

if (_downKeysCurrent.sort().join('') === _downKeys.sort().join('')) {
// 找到处理内容
eventHandler(event, record, scope);
eventHandler(event, record, scope, element);
}
}
}
Expand Down Expand Up @@ -517,15 +521,16 @@ function hotkeys(key, option, method) {
shortcut: keys[i],
method: method,
key: keys[i],
splitKey: splitKey
splitKey: splitKey,
element: element
});
} // 在全局document上设置快捷键


if (typeof element !== 'undefined' && !isElementBind(element) && window) {
elementHasBindEvent.push(element);
addEvent(element, 'keydown', function (e) {
dispatch(e);
dispatch(e, element);
});

if (!winListendFocus) {
Expand All @@ -536,7 +541,7 @@ function hotkeys(key, option, method) {
}

addEvent(element, 'keyup', function (e) {
dispatch(e);
dispatch(e, element);
clearModifier(e);
});
}
Expand Down
4 changes: 2 additions & 2 deletions dist/hotkeys.common.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 13 additions & 8 deletions dist/hotkeys.esm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**!
* hotkeys-js v3.8.8
* hotkeys-js v3.8.9
* A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.
*
* Copyright (c) 2022 kenny wong <[email protected]>
Expand Down Expand Up @@ -316,7 +316,11 @@ var eachUnbind = function eachUnbind(_ref) {
}; // 对监听对应快捷键的回调函数进行处理


function eventHandler(event, handler, scope) {
function eventHandler(event, handler, scope, element) {
if (handler.element !== element) {
return;
}

var modifiersMatch; // 看它是否在当前范围

if (handler.scope === scope || handler.scope === 'all') {
Expand All @@ -343,7 +347,7 @@ function eventHandler(event, handler, scope) {
} // 处理keydown事件


function dispatch(event) {
function dispatch(event, element) {
var asterisk = _handlers['*'];
var key = event.keyCode || event.which || event.charCode; // 表单控件过滤 默认表单控件不触发快捷键

Expand Down Expand Up @@ -428,7 +432,7 @@ function dispatch(event) {
if (asterisk) {
for (var i = 0; i < asterisk.length; i++) {
if (asterisk[i].scope === scope && (event.type === 'keydown' && asterisk[i].keydown || event.type === 'keyup' && asterisk[i].keyup)) {
eventHandler(event, asterisk[i], scope);
eventHandler(event, asterisk[i], scope, element);
}
}
} // key 不在 _handlers 中返回
Expand All @@ -450,7 +454,7 @@ function dispatch(event) {

if (_downKeysCurrent.sort().join('') === _downKeys.sort().join('')) {
// 找到处理内容
eventHandler(event, record, scope);
eventHandler(event, record, scope, element);
}
}
}
Expand Down Expand Up @@ -515,15 +519,16 @@ function hotkeys(key, option, method) {
shortcut: keys[i],
method: method,
key: keys[i],
splitKey: splitKey
splitKey: splitKey,
element: element
});
} // 在全局document上设置快捷键


if (typeof element !== 'undefined' && !isElementBind(element) && window) {
elementHasBindEvent.push(element);
addEvent(element, 'keydown', function (e) {
dispatch(e);
dispatch(e, element);
});

if (!winListendFocus) {
Expand All @@ -534,7 +539,7 @@ function hotkeys(key, option, method) {
}

addEvent(element, 'keyup', function (e) {
dispatch(e);
dispatch(e, element);
clearModifier(e);
});
}
Expand Down
Loading

1 comment on commit 335d00f

@jaywcjlove
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.