From 608333db75755db1196191601853bcd6a0ebc609 Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Sun, 28 Apr 2019 13:25:03 +0800 Subject: [PATCH] released v3.6.3 --- README-zh.md | 4 +++- README.md | 3 ++- dist/hotkeys.common.js | 31 ++++++++++++++++++++----------- dist/hotkeys.common.min.js | 4 ++-- dist/hotkeys.esm.js | 31 ++++++++++++++++++++----------- dist/hotkeys.js | 31 ++++++++++++++++++++----------- dist/hotkeys.min.js | 4 ++-- package.json | 4 ++-- 8 files changed, 71 insertions(+), 41 deletions(-) diff --git a/README-zh.md b/README-zh.md index be17d77..a2436bf 100644 --- a/README-zh.md +++ b/README-zh.md @@ -2,7 +2,7 @@ [![](https://img.shields.io/github/issues/jaywcjlove/hotkeys.svg)](https://github.com/jaywcjlove/hotkeys/issues) [![](https://img.shields.io/github/forks/jaywcjlove/hotkeys.svg)](https://github.com/jaywcjlove/hotkeys/network) [![](https://img.shields.io/github/stars/jaywcjlove/hotkeys.svg)](https://github.com/jaywcjlove/hotkeys/stargazers) [![](https://img.shields.io/github/release/jaywcjlove/hotkeys.svg)](https://github.com/jaywcjlove/hotkeys/releases) ![](http://jaywcjlove.github.io/sb/status/no-dependencies.svg) [![Build Status](https://www.travis-ci.org/jaywcjlove/hotkeys.svg?branch=master)](https://www.travis-ci.org/jaywcjlove/hotkeys) [![Coverage Status](https://coveralls.io/repos/github/jaywcjlove/hotkeys/badge.svg?branch=master)](https://coveralls.io/github/jaywcjlove/hotkeys?branch=master) [![jaywcjlove/sb](https://jaywcjlove.github.io/sb/lang/english.svg)](./README.md) -这是一个强健的 Javascript 库用于捕获键盘输入和输入的组合键,它没有依赖,压缩只有(~3kb),gzip:1.9k。[官方文档DEMO预览](http://jaywcjlove.github.io/hotkeys/?lang=cn) +这是一个强健的 Javascript 库用于捕获键盘输入和输入的组合键,它没有依赖,压缩只有(~3kb),gzip:1.9k。[官方文档DEMO预览](http://jaywcjlove.github.io/hotkeys/?lang=cn),[更多实例](https://github.com/jaywcjlove/hotkeys/issues?q=label%3ADemo+). ```shell @@ -206,6 +206,8 @@ hotkeys('*','wcj', function(e){ - `scope` - `element` +- `keyup` +- `keydown` ```js hotkeys('o, enter', { diff --git a/README.md b/README.md index a35a81f..fa3f572 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![](https://img.shields.io/github/issues/jaywcjlove/hotkeys.svg)](https://github.com/jaywcjlove/hotkeys/issues) [![](https://img.shields.io/github/forks/jaywcjlove/hotkeys.svg)](https://github.com/jaywcjlove/hotkeys/network) [![](https://img.shields.io/github/stars/jaywcjlove/hotkeys.svg)](https://github.com/jaywcjlove/hotkeys/stargazers) [![](https://img.shields.io/github/release/jaywcjlove/hotkeys.svg)](https://github.com/jaywcjlove/hotkeys/releases) ![](http://jaywcjlove.github.io/sb/status/no-dependencies.svg) [![Build Status](https://www.travis-ci.org/jaywcjlove/hotkeys.svg?branch=master)](https://www.travis-ci.org/jaywcjlove/hotkeys) [![Coverage Status](https://coveralls.io/repos/github/jaywcjlove/hotkeys/badge.svg?branch=master)](https://coveralls.io/github/jaywcjlove/hotkeys?branch=master) [![jaywcjlove/sb](https://jaywcjlove.github.io/sb/lang/chinese.svg)](./README-zh.md) -HotKeys.js is an input capture library with some very special features, it is easy to pick up and use, has a reasonable footprint (~3kb) (gzipped: 1.73kb), and has no dependencies. It should not interfere with any JavaScript libraries or frameworks. Official document [demo preview](http://jaywcjlove.github.io/hotkeys). +HotKeys.js is an input capture library with some very special features, it is easy to pick up and use, has a reasonable footprint (~3kb) (gzipped: 1.73kb), and has no dependencies. It should not interfere with any JavaScript libraries or frameworks. Official document [demo preview](http://jaywcjlove.github.io/hotkeys). [More examples](https://github.com/jaywcjlove/hotkeys/issues?q=label%3ADemo+). ```shell ╭┈┈╮ ╭┈┈╮ ╭┈┈╮ @@ -172,6 +172,7 @@ hotkeys('*','wcj', function(e){ - `scope` - `element` - `keyup` +- `keydown` ```js hotkeys('o, enter', { diff --git a/dist/hotkeys.common.js b/dist/hotkeys.common.js index d5e5cb0..d710bc0 100644 --- a/dist/hotkeys.common.js +++ b/dist/hotkeys.common.js @@ -1,5 +1,5 @@ /*! - * hotkeys-js v3.6.2 + * hotkeys-js v3.6.3 * A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies. * * Copyright (c) 2019 kenny wong @@ -332,7 +332,7 @@ function dispatch(event) { if (!(key in _handlers)) return; for (var _i = 0; _i < _handlers[key].length; _i++) { - if (event.type === 'keydown' && !_handlers[key][_i].keyup || event.type === 'keyup' && _handlers[key][_i].keyup) { + if (event.type === 'keydown' && _handlers[key][_i].keydown || event.type === 'keyup' && _handlers[key][_i].keyup) { if (_handlers[key][_i].key) { var keyShortcut = _handlers[key][_i].key.split('+'); var _downKeysCurrent = []; // 记录当前按键键值 @@ -355,6 +355,8 @@ function hotkeys(key, option, method) { var scope = 'all'; // scope默认为all,所有范围都有效 var element = document; // 快捷键事件绑定节点 var i = 0; + var keyup = false; + var keydown = true; // 对为设定范围的判断 if (method === undefined && typeof option === 'function') { @@ -363,7 +365,9 @@ 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.keydown) keydown = option.keydown; // eslint-disable-line } if (typeof option === 'string') scope = option; @@ -383,7 +387,8 @@ function hotkeys(key, option, method) { // 判断key是否在_handlers中,不在就赋一个空数组 if (!(key in _handlers)) _handlers[key] = []; _handlers[key].push({ - keyup: option.keyup, + keyup: keyup, + keydown: keydown, scope: scope, mods: mods, shortcut: keys[i], @@ -394,13 +399,17 @@ function hotkeys(key, option, method) { // 在全局document上设置快捷键 if (typeof element !== 'undefined' && !isBindElement) { isBindElement = true; - addEvent(element, 'keydown', function (e) { - dispatch(e); - }); - addEvent(element, 'keyup', function (e) { - dispatch(e); - clearModifier(e); - }); + if (keydown) { + addEvent(element, 'keydown', function (e) { + dispatch(e); + }); + } + if (keyup) { + addEvent(element, 'keyup', function (e) { + dispatch(e); + clearModifier(e); + }); + } } } diff --git a/dist/hotkeys.common.min.js b/dist/hotkeys.common.min.js index cf624bd..2836871 100644 --- a/dist/hotkeys.common.min.js +++ b/dist/hotkeys.common.min.js @@ -1,2 +1,2 @@ -/*! hotkeys-js v3.6.2 | 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 @@ -330,7 +330,7 @@ function dispatch(event) { if (!(key in _handlers)) return; for (var _i = 0; _i < _handlers[key].length; _i++) { - if (event.type === 'keydown' && !_handlers[key][_i].keyup || event.type === 'keyup' && _handlers[key][_i].keyup) { + if (event.type === 'keydown' && _handlers[key][_i].keydown || event.type === 'keyup' && _handlers[key][_i].keyup) { if (_handlers[key][_i].key) { var keyShortcut = _handlers[key][_i].key.split('+'); var _downKeysCurrent = []; // 记录当前按键键值 @@ -353,6 +353,8 @@ function hotkeys(key, option, method) { var scope = 'all'; // scope默认为all,所有范围都有效 var element = document; // 快捷键事件绑定节点 var i = 0; + var keyup = false; + var keydown = true; // 对为设定范围的判断 if (method === undefined && typeof option === 'function') { @@ -361,7 +363,9 @@ 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.keydown) keydown = option.keydown; // eslint-disable-line } if (typeof option === 'string') scope = option; @@ -381,7 +385,8 @@ function hotkeys(key, option, method) { // 判断key是否在_handlers中,不在就赋一个空数组 if (!(key in _handlers)) _handlers[key] = []; _handlers[key].push({ - keyup: option.keyup, + keyup: keyup, + keydown: keydown, scope: scope, mods: mods, shortcut: keys[i], @@ -392,13 +397,17 @@ function hotkeys(key, option, method) { // 在全局document上设置快捷键 if (typeof element !== 'undefined' && !isBindElement) { isBindElement = true; - addEvent(element, 'keydown', function (e) { - dispatch(e); - }); - addEvent(element, 'keyup', function (e) { - dispatch(e); - clearModifier(e); - }); + if (keydown) { + addEvent(element, 'keydown', function (e) { + dispatch(e); + }); + } + if (keyup) { + addEvent(element, 'keyup', function (e) { + dispatch(e); + clearModifier(e); + }); + } } } diff --git a/dist/hotkeys.js b/dist/hotkeys.js index e41b738..0ae3277 100644 --- a/dist/hotkeys.js +++ b/dist/hotkeys.js @@ -1,5 +1,5 @@ /*! - * hotkeys-js v3.6.2 + * hotkeys-js v3.6.3 * A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies. * * Copyright (c) 2019 kenny wong @@ -336,7 +336,7 @@ if (!(key in _handlers)) return; for (var _i = 0; _i < _handlers[key].length; _i++) { - if (event.type === 'keydown' && !_handlers[key][_i].keyup || event.type === 'keyup' && _handlers[key][_i].keyup) { + if (event.type === 'keydown' && _handlers[key][_i].keydown || event.type === 'keyup' && _handlers[key][_i].keyup) { if (_handlers[key][_i].key) { var keyShortcut = _handlers[key][_i].key.split('+'); var _downKeysCurrent = []; // 记录当前按键键值 @@ -359,6 +359,8 @@ var scope = 'all'; // scope默认为all,所有范围都有效 var element = document; // 快捷键事件绑定节点 var i = 0; + var keyup = false; + var keydown = true; // 对为设定范围的判断 if (method === undefined && typeof option === 'function') { @@ -367,7 +369,9 @@ 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.keydown) keydown = option.keydown; // eslint-disable-line } if (typeof option === 'string') scope = option; @@ -387,7 +391,8 @@ // 判断key是否在_handlers中,不在就赋一个空数组 if (!(key in _handlers)) _handlers[key] = []; _handlers[key].push({ - keyup: option.keyup, + keyup: keyup, + keydown: keydown, scope: scope, mods: mods, shortcut: keys[i], @@ -398,13 +403,17 @@ // 在全局document上设置快捷键 if (typeof element !== 'undefined' && !isBindElement) { isBindElement = true; - addEvent(element, 'keydown', function (e) { - dispatch(e); - }); - addEvent(element, 'keyup', function (e) { - dispatch(e); - clearModifier(e); - }); + if (keydown) { + addEvent(element, 'keydown', function (e) { + dispatch(e); + }); + } + if (keyup) { + addEvent(element, 'keyup', function (e) { + dispatch(e); + clearModifier(e); + }); + } } } diff --git a/dist/hotkeys.min.js b/dist/hotkeys.min.js index 461d19f..4a7cfbf 100644 --- a/dist/hotkeys.min.js +++ b/dist/hotkeys.min.js @@ -1,2 +1,2 @@ -/*! hotkeys-js v3.6.2 | 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.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