Compatible with low-level browsers. #70

pull/73/head
jaywcjlove 6 years ago
parent 9e48e887ad
commit 0850be67f2

@ -3,7 +3,7 @@ import { _keyMap, _modifier, _downKeys, modifierMap, _mods, _handlers } from './
let _scope = 'all'; // 默认热键范围
let elementHasBindEvent = [] // 已绑定事件的节点记录
const elementHasBindEvent = []; // 已绑定事件的节点记录
// 返回键码
const code = x => _keyMap[x.toLowerCase()] || _modifier[x.toLowerCase()] || x.toUpperCase().charCodeAt(0);
@ -229,7 +229,7 @@ function dispatch(event) {
// 判断 element 是否已经绑定事件
function isElementBind(element) {
return elementHasBindEvent.some(ele => ele === element)
return elementHasBindEvent.indexOf(element) > -1;
}
function hotkeys(key, option, method) {
@ -281,7 +281,7 @@ function hotkeys(key, option, method) {
}
// 在全局document上设置快捷键
if (typeof element !== 'undefined' && !isElementBind(element)) {
elementHasBindEvent.push(element)
elementHasBindEvent.push(element);
addEvent(element, 'keydown', (e) => {
dispatch(e);
});

Loading…
Cancel
Save