-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
220 lines (186 loc) · 7.57 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<html>
<head>
<title>chord</title>
<script type="text/javascript" src="./js/chordly.js"></script>
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function () {
const bodyElement = document.querySelector('body');
bodyElement.pushToChordly(
{
maxBufferLength: 5,
greedyTimeoutMs: 250,
sequenceMap:
[
{
sequence: [
window.chordly.literalStringToSequence('dog'),
window.chordly.literalStringToSequence('wolf'),
],
matched: function () { console.log('bark!') }
},
{
sequence: [window.chordly.literalStringToSequence('nada')],
lookup: 'nothing'
},
{
sequence: [window.chordly.literalStringToSequence('zero')],
},
{
sequence: [
window.chordly.makeSequencePart(window.chordly.scanCodeMap.UpArrow),
window.chordly.makeSequencePart(window.chordly.scanCodeMap.UpArrow),
window.chordly.makeSequencePart(window.chordly.scanCodeMap.DownArrow),
window.chordly.makeSequencePart(window.chordly.scanCodeMap.DownArrow),
window.chordly.makeSequencePart(window.chordly.scanCodeMap.LeftArrow),
window.chordly.makeSequencePart(window.chordly.scanCodeMap.RightArrow),
window.chordly.makeSequencePart(window.chordly.scanCodeMap.LeftArrow),
window.chordly.makeSequencePart(window.chordly.scanCodeMap.RightArrow),
window.chordly.makeSequencePart(window.chordly.scanCodeMap.B),
window.chordly.makeSequencePart(window.chordly.scanCodeMap.A),
window.chordly.makeSequencePart(window.chordly.scanCodeMap.Space),
],
matched: function () { console.log('cheat codes!') }
},
{
sequence: window.chordly.stringToSequence('shift+U shift+alt+P')
},
{
sequence: window.chordly.stringToSequence('U !shift+P')
},
{
sequence: window.chordly.stringToSequence('[66] A [84]'), // B A T
matched: function () { console.log('na na na na na') }
},
{
sequence: [
window.chordly.makeSequencePart(window.chordly.scanCodeMap.Q, null, null, true),
],
matched: function () { console.log('ctrl + (q | Q)!') }
},
{
sequence: [
window.chordly.makeSequencePart(window.chordly.scanCodeMap.H, true, null, false),
],
matched: function () { console.log('shift + H!') }
},
]
}
);
bodyElement.addEventListener('chordlyMatch', function (e) {
console.log('chordlyMatch event:');
console.log('\t event:', e);
console.log('\t lookup:', e.lookup);
console.log('\t sequence:', e.sequence);
console.log('\t sequenceString:', e.sequenceString);
console.log('\t originalEvent:', e.originalEvent);
});
bodyElement.pushToChordly('bind', [{
sequence: window.chordly.literalStringToSequence('mouse'),
matched: function () { console.log('squeak!') }
},
{
sequence: [
window.chordly.literalStringToSequence('cow'),
window.chordly.literalStringToSequence('bull'),
],
matched: function () { console.log('moo!') }
}]);
bodyElement.pushToChordly('bind',
{
sequence: window.chordly.literalStringToSequence('wolf'),
matched: function () { console.log('howl!') }
});
bodyElement.pushToChordly('bindSequence', 'J A C K', function () { console.log('pop!') }, 'jack in the box');
bodyElement.pushToChordly('bindLiteralSequence', 'chicken');
bodyElement.pushToChordly('bindLiteralSequence', 'pig', function () { console.log('oink') });
bodyElement.pushToChordly('bindLiteralSequence', 'pigs', function () { console.log('oink oink squeal') });
const initialInputs = document.querySelectorAll('.initialInputs');
initialInputs.forEach(ip => {
ip.pushToChordly({
ignoreFormElements: false,
sequenceMap:
[
{
sequence: window.chordly.literalStringToSequence('duck'),
matched: function () { console.log('quack!') }
},
{
sequence: window.chordly.literalStringToSequence('man'),
matched: function () { console.log('hello!') }
}
]
});
ip.addEventListener('chordlyMatch', () => console.log('man or duck'))
});
document.querySelector('#adiv').pushToChordly(
{
keyEvent: 'keydown',
ignoreFormElements: false,
sequenceMap:
[
{
sequence: window.chordly.literalStringToSequence('cat'),
matched: function () { console.log('meow!') }
}
]
}
);
document.querySelector('#pause').addEventListener('click', function () { bodyElement.pushToChordly('pause') });
document.querySelector('#resume').addEventListener('click', function () { bodyElement.pushToChordly('resume') });
document.querySelector('#toggle').addEventListener('click', function () { bodyElement.pushToChordly('togglePause') });
document.querySelector('#destroy').addEventListener('click', function () { bodyElement.pushToChordly('destroy') });
document.querySelector('#pushDog').addEventListener('click', function () {
bodyElement.pushToChordly('pushSequence', window.chordly.literalStringToSequence('dog'));
});
document.querySelector('#pushDogAndAct').addEventListener('click', function () {
bodyElement.pushToChordly('pushSequenceAndAct', window.chordly.literalStringToSequence('dog'));
});
document.querySelector('#actOnBuffer').addEventListener('click', function () {
bodyElement.pushToChordly('actOnBuffer');
});
document.querySelector('#unbindDog').addEventListener('click', function () {
bodyElement.pushToChordly('unbind', window.chordly.literalStringToSequence('dog'));
});
});
</script>
</head>
<body>
<p>
Type 'dog' (case insensitive) within this page and the console will bark at you.
Note that form inputs are ignored for this event, so typing 'dog' will not trigger a bark
</p>
<p>
Ctrl + Q (case insensitive) will trigger a console write
Shift + H (case sensitive) will trigger a console write
</p>
<p>
Greedy pattern matching: both "pig" or "pigs" may be defined to fire an event but triggering "pigs" will not trigger "pig"
</p>
<fieldset>
<legend>A man and his duck</legend>
<p>
enter 'man' or 'duck' in either of these inputs and the console will respond accordingly
(the event is attached to inputs within this div by class selector)
</p>
<input id="input1" class="initialInputs" placeholder="a man, or a duck" />
<br />
<textarea id="input2" class="initialInputs" placeholder="a man, or a duck"></textarea>
</fieldset>
<div id="adiv" style="border: 1px solid green">
<p>
the event is attached to the green div, typing 'CAT' (case sensitive) within (when in focus via the inputs) will make the console meow at you
</p>
<input id="input3" placeholder="Felix"/>
<input id="Text1" placeholder="Garfield"/>
<input id="Text2" placeholder="Tom"/>
</div>
<a href="#" id="pause">Pause document chord</a><br/>
<a href="#" id="resume">Resume document chord</a><br/>
<a href="#" id="toggle">Toggle document chord</a><br/>
<a href="#" id="destroy">destroy document chord</a><br/>
<a href="#" id="pushDog">push D O G</a><br/>
<a href="#" id="actOnBuffer">actOnBuffer</a><br/>
<a href="#" id="pushDogAndAct">push D O G and act</a><br/>
<a href="#" id="unbindDog">unbind D O G</a><br/>
</body>
</html>