Skip to content

Commit f01eadc

Browse files
committed
feat: add a key-combination
1 parent 8ab1976 commit f01eadc

File tree

3 files changed

+412
-0
lines changed

3 files changed

+412
-0
lines changed

key-combination/Readme.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
### keyCombination
2+
3+
> 快捷使用(两个)组合键
4+
5+
6+
### Usage
7+
8+
```
9+
var keyCombination = require('./index.js')
10+
var keyCombinationTest = new keyCombination({isElement: false})
11+
12+
// Here is easy to bind
13+
// default is window
14+
keyCombinationTest.bindEvent('ctrl shift', function () {
15+
console.log('ctrl shift is work')
16+
})
17+
```
18+
19+
20+
### API Reference
21+
22+
keyCombination({})
23+
24+
default Object
25+
26+
{
27+
element: null, // 需要绑定的HTML元素
28+
}
29+
30+
31+
#### 构造函数返回对象API
32+
33+
bindEvent(keyCode, callback)
34+
35+
> description: 添加回调函数进事件集
36+
> eg: bindEvent('ctrl 5', function () { // do some things})
37+
38+
---
39+
40+
removeListeners(keyCode, callback)
41+
42+
> description: 从事件集中删除
43+
> eg: removeListeners('ctrl 5', function () {})
44+
45+
这里你需要注意,这个回调函数的引用应该与bindEvent一致。
46+
47+
---
48+
49+
detach
50+
51+
> 彻底解绑事件
52+
> eg: new keyCombination({}).detach()
53+
54+
解绑事件
55+
56+
---
57+
58+
init
59+
60+
> eg: new keyCombination({}).init()
61+
62+
你可以重新初始化一些参数.用于复用对象
63+
64+
---
65+
66+
subscribeAction
67+
68+
> eg: new keyCombination({}).subscribeAction()
69+
70+
初始化数据后你可以手动执行一下进行绑定。
71+
72+
---
73+
74+
keyCode in [keycodes](https://github.com/wesbos/keycodes)
75+
76+
---
77+
78+
### MIT

key-combination/elementExample.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>element Example</title>
8+
</head>
9+
<body>
10+
<div class="container">
11+
<input type="text" id="testInput">
12+
</div>
13+
14+
<script src="./index.js">
15+
</script>
16+
</body>
17+
</html>

0 commit comments

Comments
 (0)