';
20 |
21 | //init keys
22 | let numberKeys = [];
23 | for (let i = 1; i < 10; i++) {
24 | numberKeys.push(i.toString());
25 | }
26 | numberKeys.push('0');
27 |
28 | const keys = [
29 | ['`'].concat(numberKeys).concat([
30 | '-', '=', 'Delete'
31 | ]),
32 | ['Tab', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\\'],
33 | ['Caps', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', 'Enter'],
34 | ['Shift', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', 'Shift'],
35 | ['Space']
36 | ]
37 |
38 | let thisKeys;
39 | const shiftKey = [],
40 | capsKey = [];
41 | for (let i = 0; i < keys.length; i++) {
42 | shiftKey.push([]);
43 | capsKey.push([]);
44 | thisKeys = keys[i];
45 | for (let a = 0; a < thisKeys.length; a++) {
46 | if (thisKeys[a].length === 1) {
47 | capsKey[i].push(thisKeys[a].toUpperCase());
48 | switch (thisKeys[a]) {
49 | case '`':
50 | shiftKey[i].push('~');
51 | continue;
52 | case '1':
53 | shiftKey[i].push('!');
54 | continue;
55 | case '2':
56 | shiftKey[i].push('@');
57 | continue;
58 | case '3':
59 | shiftKey[i].push('#');
60 | continue;
61 | case '4':
62 | shiftKey[i].push('$');
63 | continue;
64 | case '5':
65 | shiftKey[i].push('%');
66 | continue;
67 | case '6':
68 | shiftKey[i].push('^');
69 | continue;
70 | case '7':
71 | shiftKey[i].push('&');
72 | continue;
73 | case '8':
74 | shiftKey[i].push('*');
75 | continue;
76 | case '9':
77 | shiftKey[i].push('(');
78 | continue;
79 | case '0':
80 | shiftKey[i].push(')');
81 | continue;
82 | case '-':
83 | shiftKey[i].push('_');
84 | continue;
85 | case '=':
86 | shiftKey[i].push('+');
87 | continue;
88 | case '[':
89 | shiftKey[i].push('{');
90 | continue;
91 | case ']':
92 | shiftKey[i].push('}');
93 | continue;
94 | case '\\':
95 | shiftKey[i].push('|');
96 | continue;
97 | case ';':
98 | shiftKey[i].push(':');
99 | continue;
100 | case '\'':
101 | shiftKey[i].push('"');
102 | continue;
103 | case ',':
104 | shiftKey[i].push('<');
105 | continue;
106 | case '.':
107 | shiftKey[i].push('>');
108 | continue;
109 | case '/':
110 | shiftKey[i].push('?');
111 | continue;
112 | }
113 | shiftKey[i].push(thisKeys[a].toUpperCase());
114 | continue;
115 | }
116 | shiftKey[i].push(thisKeys[a]);
117 | capsKey[i].push(thisKeys[a]);
118 | }
119 | }
120 |
121 | for (let i = 0; i < keys.length; i++) {
122 | thisKeys = keys[i];
123 | html += '
';
124 | for (let a = 0; a < thisKeys.length; a++) {
125 | html += '
' + thisKeys[a] + '
';
126 | }
127 | html += '
';
128 | }
129 |
130 | html += '
';
131 |
132 | el.innerHTML = html;
133 |
134 | //bind the shift and caps key
135 | const elKeysEl = document.querySelectorAll(obj.el + ' .akeyboard-keyboard-keys-Shift');
136 |
137 | function shiftKeyClickFn() {
138 | if (!this.isShift) {
139 | if (document.querySelector(obj.el + ' .akeyboard-keyboard-keys-Caps').isCaps) {
140 | return;
141 | }
142 |
143 | //shift
144 | elKeysEl[0].isShift = true;
145 | elKeysEl[1].isShift = true;
146 | elKeysEl[0].innerHTML = 'SHIFT';
147 | elKeysEl[1].innerHTML = 'SHIFT';
148 |
149 | const keysInnerEl = document.querySelectorAll(obj.el + ' .akeyboard-keyboard-innerKeys');
150 |
151 | let thisEl;
152 | for (let i = 0; i < keysInnerEl.length; i++) {
153 | thisEl = keysInnerEl[i];
154 | for (let a = 0; a < thisEl.childNodes.length; a++) {
155 | if (shiftKey[i][a] === 'Shift') {
156 | continue;
157 | }
158 | thisEl.childNodes[a].innerHTML = shiftKey[i][a];
159 | }
160 | }
161 |
162 | return;
163 | }
164 | elKeysEl[0].isShift = false;
165 | elKeysEl[1].isShift = false;
166 | elKeysEl[0].innerHTML = 'Shift';
167 | elKeysEl[1].innerHTML = 'Shift';
168 |
169 | const keysInnerEl = document.querySelectorAll(obj.el + ' .akeyboard-keyboard-innerKeys');
170 |
171 | let thisEl;
172 | for (let i = 0; i < keysInnerEl.length; i++) {
173 | thisEl = keysInnerEl[i];
174 | for (let a = 0; a < thisEl.childNodes.length; a++) {
175 | thisEl.childNodes[a].innerHTML = keys[i][a];
176 | }
177 | }
178 | }
179 |
180 | elKeysEl[0].onclick = shiftKeyClickFn;
181 | elKeysEl[0].isShift = false;
182 |
183 | elKeysEl[1].onclick = shiftKeyClickFn;
184 | elKeysEl[1].isShift = false;
185 |
186 |
187 | const elCapsEl = document.querySelector(obj.el + ' .akeyboard-keyboard-keys-Caps');
188 |
189 | elCapsEl.onclick = function() {
190 | if (!this.isCaps) {
191 | if (document.querySelector(obj.el + ' .akeyboard-keyboard-keys-Shift').isShift) {
192 | return;
193 | }
194 |
195 | //caps
196 | this.isCaps = true;
197 | this.classList.add('keyboard-keyboard-keys-focus');
198 |
199 | const keysInnerEl = document.querySelectorAll(obj.el + ' .akeyboard-keyboard-innerKeys');
200 |
201 | let thisEl;
202 | for (let i = 0; i < keysInnerEl.length; i++) {
203 | thisEl = keysInnerEl[i];
204 | for (let a = 0; a < thisEl.childNodes.length; a++) {
205 | thisEl.childNodes[a].innerHTML = capsKey[i][a];
206 | }
207 | }
208 |
209 | return;
210 | }
211 |
212 | this.isCaps = false;
213 | this.classList.remove('keyboard-keyboard-keys-focus');
214 |
215 | const keysInnerEl = document.querySelectorAll(obj.el + ' .akeyboard-keyboard-innerKeys');
216 |
217 | let thisEl;
218 | for (let i = 0; i < keysInnerEl.length; i++) {
219 | thisEl = keysInnerEl[i];
220 | for (let a = 0; a < thisEl.childNodes.length; a++) {
221 | thisEl.childNodes[a].innerHTML = keys[i][a];
222 | }
223 | }
224 | }
225 |
226 | elCapsEl.isCaps = false;
227 | }
228 |
229 | inputOn(inputEle, type) {
230 | if (typeof inputEle !== 'string') {
231 | console.error('aKeyboard: The inputEle parameter needs to be a string