Skip to content

Commit

Permalink
released 3.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Apr 7, 2018
1 parent 21aac4e commit d6ce525
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 53 deletions.
41 changes: 25 additions & 16 deletions dist/hotkeys.common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* hotkeys-js v3.1.2
* hotkeys-js v3.2.0
* A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.
*
* Copyright (c) 2018 kenny wong <[email protected]>
Expand Down Expand Up @@ -129,6 +129,8 @@ modifierMap[isff ? 224 : 91] = 'metaKey';
_mods[isff ? 224 : 91] = false;

var _scope = 'all'; // 默认热键范围
var isBindElement = false; // 是否绑定节点

// 返回键码
var code = function code(x) {
return _keyMap[x.toLowerCase()] || x.toUpperCase().charCodeAt(0);
Expand Down Expand Up @@ -308,7 +310,6 @@ function dispatch(event) {
if (asterisk[i].scope === scope) eventHandler(event, asterisk[i], scope);
}
}

// key 不在_handlers中返回
if (!(key in _handlers)) return;

Expand All @@ -318,17 +319,25 @@ function dispatch(event) {
}
}

function hotkeys(key, scope, method) {
function hotkeys(key, option, method) {
var keys = getKeys(key); // 需要处理的快捷键列表
var mods = [];
var scope = 'all'; // scope默认为all,所有范围都有效
var element = document; // 快捷键事件绑定节点
var i = 0;

// 对为设定范围的判断
if (method === undefined) {
method = scope;
scope = 'all'; // scope默认为all,所有范围都有效
if (method === undefined && typeof option === 'function') {
method = option;
}

if (toString.call(option) === '[object Object]') {
if (option.scope) scope = option.scope; // eslint-disable-line
if (option.element) element = option.element; // eslint-disable-line
}

if (typeof option === 'string') scope = option;

// 对于每个快捷键进行处理
for (; i < keys.length; i++) {
key = keys[i].split('+'); // 按键列表
Expand All @@ -352,16 +361,16 @@ function hotkeys(key, scope, method) {
key: keys[i]
});
}
}

// 在全局document上设置快捷键
if (typeof document !== 'undefined') {
addEvent(document, 'keydown', function (e) {
dispatch(e);
});
addEvent(document, 'keyup', function (e) {
clearModifier(e);
});
// 在全局document上设置快捷键
if (typeof element !== 'undefined' && !isBindElement) {
isBindElement = true;
addEvent(element, 'keydown', function (e) {
dispatch(e);
});
addEvent(element, 'keyup', function (e) {
clearModifier(e);
});
}
}

var _api = {
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.

41 changes: 25 additions & 16 deletions dist/hotkeys.esm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* hotkeys-js v3.1.2
* hotkeys-js v3.2.0
* A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.
*
* Copyright (c) 2018 kenny wong <[email protected]>
Expand Down Expand Up @@ -127,6 +127,8 @@ modifierMap[isff ? 224 : 91] = 'metaKey';
_mods[isff ? 224 : 91] = false;

var _scope = 'all'; // 默认热键范围
var isBindElement = false; // 是否绑定节点

// 返回键码
var code = function code(x) {
return _keyMap[x.toLowerCase()] || x.toUpperCase().charCodeAt(0);
Expand Down Expand Up @@ -306,7 +308,6 @@ function dispatch(event) {
if (asterisk[i].scope === scope) eventHandler(event, asterisk[i], scope);
}
}

// key 不在_handlers中返回
if (!(key in _handlers)) return;

Expand All @@ -316,17 +317,25 @@ function dispatch(event) {
}
}

function hotkeys(key, scope, method) {
function hotkeys(key, option, method) {
var keys = getKeys(key); // 需要处理的快捷键列表
var mods = [];
var scope = 'all'; // scope默认为all,所有范围都有效
var element = document; // 快捷键事件绑定节点
var i = 0;

// 对为设定范围的判断
if (method === undefined) {
method = scope;
scope = 'all'; // scope默认为all,所有范围都有效
if (method === undefined && typeof option === 'function') {
method = option;
}

if (toString.call(option) === '[object Object]') {
if (option.scope) scope = option.scope; // eslint-disable-line
if (option.element) element = option.element; // eslint-disable-line
}

if (typeof option === 'string') scope = option;

// 对于每个快捷键进行处理
for (; i < keys.length; i++) {
key = keys[i].split('+'); // 按键列表
Expand All @@ -350,16 +359,16 @@ function hotkeys(key, scope, method) {
key: keys[i]
});
}
}

// 在全局document上设置快捷键
if (typeof document !== 'undefined') {
addEvent(document, 'keydown', function (e) {
dispatch(e);
});
addEvent(document, 'keyup', function (e) {
clearModifier(e);
});
// 在全局document上设置快捷键
if (typeof element !== 'undefined' && !isBindElement) {
isBindElement = true;
addEvent(element, 'keydown', function (e) {
dispatch(e);
});
addEvent(element, 'keyup', function (e) {
clearModifier(e);
});
}
}

var _api = {
Expand Down
41 changes: 25 additions & 16 deletions dist/hotkeys.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* hotkeys-js v3.1.2
* hotkeys-js v3.2.0
* A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.
*
* Copyright (c) 2018 kenny wong <[email protected]>
Expand Down Expand Up @@ -133,6 +133,8 @@ modifierMap[isff ? 224 : 91] = 'metaKey';
_mods[isff ? 224 : 91] = false;

var _scope = 'all'; // 默认热键范围
var isBindElement = false; // 是否绑定节点

// 返回键码
var code = function code(x) {
return _keyMap[x.toLowerCase()] || x.toUpperCase().charCodeAt(0);
Expand Down Expand Up @@ -312,7 +314,6 @@ function dispatch(event) {
if (asterisk[i].scope === scope) eventHandler(event, asterisk[i], scope);
}
}

// key 不在_handlers中返回
if (!(key in _handlers)) return;

Expand All @@ -322,17 +323,25 @@ function dispatch(event) {
}
}

function hotkeys(key, scope, method) {
function hotkeys(key, option, method) {
var keys = getKeys(key); // 需要处理的快捷键列表
var mods = [];
var scope = 'all'; // scope默认为all,所有范围都有效
var element = document; // 快捷键事件绑定节点
var i = 0;

// 对为设定范围的判断
if (method === undefined) {
method = scope;
scope = 'all'; // scope默认为all,所有范围都有效
if (method === undefined && typeof option === 'function') {
method = option;
}

if (toString.call(option) === '[object Object]') {
if (option.scope) scope = option.scope; // eslint-disable-line
if (option.element) element = option.element; // eslint-disable-line
}

if (typeof option === 'string') scope = option;

// 对于每个快捷键进行处理
for (; i < keys.length; i++) {
key = keys[i].split('+'); // 按键列表
Expand All @@ -356,16 +365,16 @@ function hotkeys(key, scope, method) {
key: keys[i]
});
}
}

// 在全局document上设置快捷键
if (typeof document !== 'undefined') {
addEvent(document, 'keydown', function (e) {
dispatch(e);
});
addEvent(document, 'keyup', function (e) {
clearModifier(e);
});
// 在全局document上设置快捷键
if (typeof element !== 'undefined' && !isBindElement) {
isBindElement = true;
addEvent(element, 'keydown', function (e) {
dispatch(e);
});
addEvent(element, 'keyup', function (e) {
clearModifier(e);
});
}
}

var _api = {
Expand Down
Loading

0 comments on commit d6ce525

Please sign in to comment.