diff --git a/dist/hotkeys.common.js b/dist/hotkeys.common.js index b9c56b41..ede74717 100644 --- a/dist/hotkeys.common.js +++ b/dist/hotkeys.common.js @@ -1,5 +1,5 @@ /*! - * hotkeys-js v3.3.8 + * hotkeys-js v3.4.0 * A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies. * * Copyright (c) 2018 kenny wong @@ -208,11 +208,17 @@ function clearModifier(event) { } // 解除绑定某个范围的快捷键 -function unbind(key, scope) { +function unbind(key, scope, method) { var multipleKeys = getKeys(key); var keys = void 0; var mods = []; var obj = void 0; + // 通过函数判断,是否解除绑定 + // https://github.com/jaywcjlove/hotkeys/issues/44 + if (typeof scope === 'function') { + method = scope; + scope = 'all'; + } for (var i = 0; i < multipleKeys.length; i++) { // 将组合快捷键拆分为数组 @@ -235,6 +241,8 @@ function unbind(key, scope) { // 让触发快捷键键之后没有事件执行到达解除快捷键绑定的目的 for (var r = 0; r < _handlers[key].length; r++) { obj = _handlers[key][r]; + // 通过函数判断,是否解除绑定,函数相等直接返回 + if (method && obj.method !== method) return; // 判断是否在范围内并且键值相同 if (obj.scope === scope && compareArray(obj.mods, mods)) { _handlers[key][r] = {}; diff --git a/dist/hotkeys.common.min.js b/dist/hotkeys.common.min.js index 8deeedf5..c0211688 100644 --- a/dist/hotkeys.common.min.js +++ b/dist/hotkeys.common.min.js @@ -1,2 +1,2 @@ -/*! hotkeys-js v3.3.8 | MIT (c) 2018 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 @@ -206,11 +206,17 @@ function clearModifier(event) { } // 解除绑定某个范围的快捷键 -function unbind(key, scope) { +function unbind(key, scope, method) { var multipleKeys = getKeys(key); var keys = void 0; var mods = []; var obj = void 0; + // 通过函数判断,是否解除绑定 + // https://github.com/jaywcjlove/hotkeys/issues/44 + if (typeof scope === 'function') { + method = scope; + scope = 'all'; + } for (var i = 0; i < multipleKeys.length; i++) { // 将组合快捷键拆分为数组 @@ -233,6 +239,8 @@ function unbind(key, scope) { // 让触发快捷键键之后没有事件执行到达解除快捷键绑定的目的 for (var r = 0; r < _handlers[key].length; r++) { obj = _handlers[key][r]; + // 通过函数判断,是否解除绑定,函数相等直接返回 + if (method && obj.method !== method) return; // 判断是否在范围内并且键值相同 if (obj.scope === scope && compareArray(obj.mods, mods)) { _handlers[key][r] = {}; diff --git a/dist/hotkeys.js b/dist/hotkeys.js index 8c1e01e2..7ca6a6ae 100644 --- a/dist/hotkeys.js +++ b/dist/hotkeys.js @@ -1,5 +1,5 @@ /*! - * hotkeys-js v3.3.8 + * hotkeys-js v3.4.0 * A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies. * * Copyright (c) 2018 kenny wong @@ -212,11 +212,17 @@ } // 解除绑定某个范围的快捷键 - function unbind(key, scope) { + function unbind(key, scope, method) { var multipleKeys = getKeys(key); var keys = void 0; var mods = []; var obj = void 0; + // 通过函数判断,是否解除绑定 + // https://github.com/jaywcjlove/hotkeys/issues/44 + if (typeof scope === 'function') { + method = scope; + scope = 'all'; + } for (var i = 0; i < multipleKeys.length; i++) { // 将组合快捷键拆分为数组 @@ -239,6 +245,8 @@ // 让触发快捷键键之后没有事件执行到达解除快捷键绑定的目的 for (var r = 0; r < _handlers[key].length; r++) { obj = _handlers[key][r]; + // 通过函数判断,是否解除绑定,函数相等直接返回 + if (method && obj.method !== method) return; // 判断是否在范围内并且键值相同 if (obj.scope === scope && compareArray(obj.mods, mods)) { _handlers[key][r] = {}; diff --git a/dist/hotkeys.min.js b/dist/hotkeys.min.js index ca3e3605..321d79d0 100644 --- a/dist/hotkeys.min.js +++ b/dist/hotkeys.min.js @@ -1,2 +1,2 @@ -/*! hotkeys-js v3.3.8 | MIT (c) 2018 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.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.hotkeys=t()}(this,function(){"use strict";var e="undefined"!=typeof navigator&&0