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

Make it so unbind('') does not remove all event handlers #372

Merged
merged 1 commit into from
May 20, 2022
Merged
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
19 changes: 11 additions & 8 deletions dist/hotkeys.common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**!
* hotkeys-js v3.9.0
* hotkeys-js v3.9.3
* A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.
*
* Copyright (c) 2022 kenny wong <wowohoo@qq.com>
Expand All @@ -11,9 +11,9 @@

var isff = typeof navigator !== 'undefined' ? navigator.userAgent.toLowerCase().indexOf('firefox') > 0 : false; // 绑定事件

function addEvent(object, event, method) {
function addEvent(object, event, method, useCapture) {
if (object.addEventListener) {
object.addEventListener(event, method, false);
object.addEventListener(event, method, useCapture);
} else if (object.attachEvent) {
object.attachEvent("on".concat(event), function () {
method(window.event);
Expand Down Expand Up @@ -256,7 +256,7 @@ function clearModifier(event) {

function unbind(keysInfo) {
// unbind(), unbind all keys
if (!keysInfo) {
if (typeof keysInfo === 'undefined') {
Object.keys(_handlers).forEach(function (key) {
return delete _handlers[key];
});
Expand Down Expand Up @@ -480,7 +480,8 @@ function hotkeys(key, option, method) {
var i = 0;
var keyup = false;
var keydown = true;
var splitKey = '+'; // 对为设定范围的判断
var splitKey = '+';
var capture = false; // 对为设定范围的判断

if (method === undefined && typeof option === 'function') {
method = option;
Expand All @@ -495,6 +496,8 @@ function hotkeys(key, option, method) {

if (option.keydown !== undefined) keydown = option.keydown; // eslint-disable-line

if (option.capture !== undefined) capture = option.capture; // eslint-disable-line

if (typeof option.splitKey === 'string') splitKey = option.splitKey; // eslint-disable-line
}

Expand Down Expand Up @@ -531,19 +534,19 @@ function hotkeys(key, option, method) {
elementHasBindEvent.push(element);
addEvent(element, 'keydown', function (e) {
dispatch(e, element);
});
}, capture);

if (!winListendFocus) {
winListendFocus = true;
addEvent(window, 'focus', function () {
_downKeys = [];
});
}, capture);
}

addEvent(element, 'keyup', function (e) {
dispatch(e, element);
clearModifier(e);
});
}, capture);
}
}

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.

19 changes: 11 additions & 8 deletions dist/hotkeys.esm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**!
* hotkeys-js v3.9.0
* hotkeys-js v3.9.3
* A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.
*
* Copyright (c) 2022 kenny wong <wowohoo@qq.com>
Expand All @@ -9,9 +9,9 @@

var isff = typeof navigator !== 'undefined' ? navigator.userAgent.toLowerCase().indexOf('firefox') > 0 : false; // 绑定事件

function addEvent(object, event, method) {
function addEvent(object, event, method, useCapture) {
if (object.addEventListener) {
object.addEventListener(event, method, false);
object.addEventListener(event, method, useCapture);
} else if (object.attachEvent) {
object.attachEvent("on".concat(event), function () {
method(window.event);
Expand Down Expand Up @@ -254,7 +254,7 @@ function clearModifier(event) {

function unbind(keysInfo) {
// unbind(), unbind all keys
if (!keysInfo) {
if (typeof keysInfo === 'undefined') {
Object.keys(_handlers).forEach(function (key) {
return delete _handlers[key];
});
Expand Down Expand Up @@ -478,7 +478,8 @@ function hotkeys(key, option, method) {
var i = 0;
var keyup = false;
var keydown = true;
var splitKey = '+'; // 对为设定范围的判断
var splitKey = '+';
var capture = false; // 对为设定范围的判断

if (method === undefined && typeof option === 'function') {
method = option;
Expand All @@ -493,6 +494,8 @@ function hotkeys(key, option, method) {

if (option.keydown !== undefined) keydown = option.keydown; // eslint-disable-line

if (option.capture !== undefined) capture = option.capture; // eslint-disable-line

if (typeof option.splitKey === 'string') splitKey = option.splitKey; // eslint-disable-line
}

Expand Down Expand Up @@ -529,19 +532,19 @@ function hotkeys(key, option, method) {
elementHasBindEvent.push(element);
addEvent(element, 'keydown', function (e) {
dispatch(e, element);
});
}, capture);

if (!winListendFocus) {
winListendFocus = true;
addEvent(window, 'focus', function () {
_downKeys = [];
});
}, capture);
}

addEvent(element, 'keyup', function (e) {
dispatch(e, element);
clearModifier(e);
});
}, capture);
}
}

Expand Down
Loading