-
-
Notifications
You must be signed in to change notification settings - Fork 413
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
21aac4e
commit d6ce525
Showing
6 changed files
with
81 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]> | ||
|
@@ -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); | ||
|
@@ -308,7 +310,6 @@ function dispatch(event) { | |
if (asterisk[i].scope === scope) eventHandler(event, asterisk[i], scope); | ||
} | ||
} | ||
|
||
// key 不在_handlers中返回 | ||
if (!(key in _handlers)) return; | ||
|
||
|
@@ -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('+'); // 按键列表 | ||
|
@@ -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 = { | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]> | ||
|
@@ -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); | ||
|
@@ -306,7 +308,6 @@ function dispatch(event) { | |
if (asterisk[i].scope === scope) eventHandler(event, asterisk[i], scope); | ||
} | ||
} | ||
|
||
// key 不在_handlers中返回 | ||
if (!(key in _handlers)) return; | ||
|
||
|
@@ -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('+'); // 按键列表 | ||
|
@@ -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 = { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]> | ||
|
@@ -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); | ||
|
@@ -312,7 +314,6 @@ function dispatch(event) { | |
if (asterisk[i].scope === scope) eventHandler(event, asterisk[i], scope); | ||
} | ||
} | ||
|
||
// key 不在_handlers中返回 | ||
if (!(key in _handlers)) return; | ||
|
||
|
@@ -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('+'); // 按键列表 | ||
|
@@ -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 = { | ||
|
Oops, something went wrong.