diff --git a/dist/hotkeys.common.js b/dist/hotkeys.common.js index b43aca9..1232c0c 100644 --- a/dist/hotkeys.common.js +++ b/dist/hotkeys.common.js @@ -1,5 +1,5 @@ /*! - * hotkeys-js v3.6.4 + * hotkeys-js v3.6.5 * A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies. * * Copyright (c) 2019 kenny wong @@ -138,7 +138,7 @@ _mods[isff ? 224 : 91] = false; var _scope = 'all'; // 默认热键范围 -var isBindElement = false; // 是否绑定节点 +var elementHasBindEvent = []; // 已绑定事件的节点记录 // 返回键码 var code = function code(x) { @@ -353,6 +353,11 @@ function dispatch(event) { } } } +} // 判断 element 是否已经绑定事件 + + +function isElementBind(element) { + return elementHasBindEvent.indexOf(element) > -1; } function hotkeys(key, option, method) { @@ -374,11 +379,11 @@ function hotkeys(key, option, method) { if (Object.prototype.toString.call(option) === '[object Object]') { if (option.scope) scope = option.scope; // eslint-disable-line - if (option.element) element = option.element; // eslint-disable-line + if (option.element) element = option.element; // eslint-disable-line - if (option.keyup) keyup = option.keyup; // eslint-disable-line + if (option.keyup) keyup = option.keyup; // eslint-disable-line - if (option.keydown) keydown = option.keydown; // eslint-disable-line + if (option.keydown) keydown = option.keydown; // eslint-disable-line } if (typeof option === 'string') scope = option; // 对于每个快捷键进行处理 @@ -408,20 +413,13 @@ function hotkeys(key, option, method) { } // 在全局document上设置快捷键 - if (typeof element !== 'undefined' && !isBindElement) { - isBindElement = true; - - if (keydown) { - addEvent(element, 'keydown', function (e) { - dispatch(e); - }); - } - + if (typeof element !== 'undefined' && !isElementBind(element)) { + elementHasBindEvent.push(element); + addEvent(element, 'keydown', function (e) { + dispatch(e); + }); addEvent(element, 'keyup', function (e) { - if (keyup) { - dispatch(e); - } - + dispatch(e); clearModifier(e); }); } diff --git a/dist/hotkeys.common.min.js b/dist/hotkeys.common.min.js index 1a1904e..cfe630e 100644 --- a/dist/hotkeys.common.min.js +++ b/dist/hotkeys.common.min.js @@ -1,2 +1,2 @@ -/*! hotkeys-js v3.6.4 | MIT (c) 2019 kenny wong | http://jaywcjlove.github.io/hotkeys */ -"use strict";var isff="undefined"!=typeof navigator&&0 | http://jaywcjlove.github.io/hotkeys */ +"use strict";var isff="undefined"!=typeof navigator&&0 @@ -136,7 +136,7 @@ _mods[isff ? 224 : 91] = false; var _scope = 'all'; // 默认热键范围 -var isBindElement = false; // 是否绑定节点 +var elementHasBindEvent = []; // 已绑定事件的节点记录 // 返回键码 var code = function code(x) { @@ -351,6 +351,11 @@ function dispatch(event) { } } } +} // 判断 element 是否已经绑定事件 + + +function isElementBind(element) { + return elementHasBindEvent.indexOf(element) > -1; } function hotkeys(key, option, method) { @@ -372,11 +377,11 @@ function hotkeys(key, option, method) { if (Object.prototype.toString.call(option) === '[object Object]') { if (option.scope) scope = option.scope; // eslint-disable-line - if (option.element) element = option.element; // eslint-disable-line + if (option.element) element = option.element; // eslint-disable-line - if (option.keyup) keyup = option.keyup; // eslint-disable-line + if (option.keyup) keyup = option.keyup; // eslint-disable-line - if (option.keydown) keydown = option.keydown; // eslint-disable-line + if (option.keydown) keydown = option.keydown; // eslint-disable-line } if (typeof option === 'string') scope = option; // 对于每个快捷键进行处理 @@ -406,20 +411,13 @@ function hotkeys(key, option, method) { } // 在全局document上设置快捷键 - if (typeof element !== 'undefined' && !isBindElement) { - isBindElement = true; - - if (keydown) { - addEvent(element, 'keydown', function (e) { - dispatch(e); - }); - } - + if (typeof element !== 'undefined' && !isElementBind(element)) { + elementHasBindEvent.push(element); + addEvent(element, 'keydown', function (e) { + dispatch(e); + }); addEvent(element, 'keyup', function (e) { - if (keyup) { - dispatch(e); - } - + dispatch(e); clearModifier(e); }); } diff --git a/dist/hotkeys.js b/dist/hotkeys.js index a3dbe84..cbbfb0c 100644 --- a/dist/hotkeys.js +++ b/dist/hotkeys.js @@ -1,5 +1,5 @@ /*! - * hotkeys-js v3.6.4 + * hotkeys-js v3.6.5 * A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies. * * Copyright (c) 2019 kenny wong @@ -142,7 +142,7 @@ var _scope = 'all'; // 默认热键范围 - var isBindElement = false; // 是否绑定节点 + var elementHasBindEvent = []; // 已绑定事件的节点记录 // 返回键码 var code = function code(x) { @@ -357,6 +357,11 @@ } } } + } // 判断 element 是否已经绑定事件 + + + function isElementBind(element) { + return elementHasBindEvent.indexOf(element) > -1; } function hotkeys(key, option, method) { @@ -378,11 +383,11 @@ if (Object.prototype.toString.call(option) === '[object Object]') { if (option.scope) scope = option.scope; // eslint-disable-line - if (option.element) element = option.element; // eslint-disable-line + if (option.element) element = option.element; // eslint-disable-line - if (option.keyup) keyup = option.keyup; // eslint-disable-line + if (option.keyup) keyup = option.keyup; // eslint-disable-line - if (option.keydown) keydown = option.keydown; // eslint-disable-line + if (option.keydown) keydown = option.keydown; // eslint-disable-line } if (typeof option === 'string') scope = option; // 对于每个快捷键进行处理 @@ -412,20 +417,13 @@ } // 在全局document上设置快捷键 - if (typeof element !== 'undefined' && !isBindElement) { - isBindElement = true; - - if (keydown) { - addEvent(element, 'keydown', function (e) { - dispatch(e); - }); - } - + if (typeof element !== 'undefined' && !isElementBind(element)) { + elementHasBindEvent.push(element); + addEvent(element, 'keydown', function (e) { + dispatch(e); + }); addEvent(element, 'keyup', function (e) { - if (keyup) { - dispatch(e); - } - + dispatch(e); clearModifier(e); }); } diff --git a/dist/hotkeys.min.js b/dist/hotkeys.min.js index 0c07aa3..049e049 100644 --- a/dist/hotkeys.min.js +++ b/dist/hotkeys.min.js @@ -1,2 +1,2 @@ -/*! hotkeys-js v3.6.4 | MIT (c) 2019 kenny wong | http://jaywcjlove.github.io/hotkeys */ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).hotkeys=t()}(this,function(){"use strict";var e="undefined"!=typeof navigator&&0 | http://jaywcjlove.github.io/hotkeys */ +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).hotkeys=t()}(this,function(){"use strict";var e="undefined"!=typeof navigator&&0