virtual-keypad 5.13.3 → 5.13.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/receiver.html +25 -16
- package/package.json +1 -1
- package/src/keypad.js +1 -0
- package/src/maxKeySize.js +1 -7
- package/src/receiver.js +1 -0
package/dist/receiver.html
CHANGED
|
@@ -66,16 +66,20 @@
|
|
|
66
66
|
</p>
|
|
67
67
|
</div>
|
|
68
68
|
<div id="display"></div>
|
|
69
|
-
<div style="display: flex
|
|
70
|
-
<button id="toggle-disable" style="display: none
|
|
71
|
-
<button id="randomize-alphabet" style="display: none
|
|
69
|
+
<div style="display: flex">
|
|
70
|
+
<button id="toggle-disable" style="display: none">Disable keys.</button>
|
|
71
|
+
<button id="randomize-alphabet" style="display: none">
|
|
72
|
+
Randomize character set.
|
|
73
|
+
</button>
|
|
72
74
|
</div>
|
|
73
75
|
<script>
|
|
74
|
-
if (
|
|
76
|
+
if (window.location !== window.parent.location) {
|
|
75
77
|
// The page is in an iframe, per https://tommcfarlin.com/check-if-a-page-is-in-an-iframe/
|
|
76
78
|
document.getElementById("info").style.display = "none";
|
|
77
|
-
}
|
|
78
|
-
let starting_alphabet = [
|
|
79
|
+
}
|
|
80
|
+
let starting_alphabet = [
|
|
81
|
+
..."ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789".split(""),
|
|
82
|
+
];
|
|
79
83
|
const ctrl = ["RETURN", "SPACE"];
|
|
80
84
|
let alphabet = [...starting_alphabet, ...ctrl];
|
|
81
85
|
|
|
@@ -86,6 +90,7 @@
|
|
|
86
90
|
font: "Arial", // Supported font, in which to display letters
|
|
87
91
|
targetElementId: "display", // id of the the div where messages should be displayed
|
|
88
92
|
visualResponseFeedback: false,
|
|
93
|
+
onErrorReconnectMessage: "Custom error message",
|
|
89
94
|
};
|
|
90
95
|
let ondata_callback = (data) => {
|
|
91
96
|
document.getElementById("display").innerText += "\n" + data.response;
|
|
@@ -98,15 +103,18 @@
|
|
|
98
103
|
ev.target.innerText = "Enable keys.";
|
|
99
104
|
} else {
|
|
100
105
|
receiver.enableKeys();
|
|
101
|
-
ev.target.innerText = "Disable keys."
|
|
106
|
+
ev.target.innerText = "Disable keys.";
|
|
102
107
|
}
|
|
103
108
|
};
|
|
104
109
|
const changeAlphabet = (ev) => {
|
|
105
|
-
const sampledAlphabet = [
|
|
110
|
+
const sampledAlphabet = [
|
|
111
|
+
...randomSelection(starting_alphabet),
|
|
112
|
+
...ctrl,
|
|
113
|
+
];
|
|
106
114
|
if (ev.target.toggleAttribute("keys-changed")) {
|
|
107
115
|
// Reset disabled keys on alphabet change, easier than persisting disabled for this demo page
|
|
108
|
-
ev.target.toggleAttribute("keys-disabled")
|
|
109
|
-
ev.target.innerText = "Disable keys."
|
|
116
|
+
ev.target.toggleAttribute("keys-disabled");
|
|
117
|
+
ev.target.innerText = "Disable keys.";
|
|
110
118
|
|
|
111
119
|
alphabet = sampledAlphabet;
|
|
112
120
|
ev.target.innerText = "Reset alphabet.";
|
|
@@ -119,24 +127,25 @@
|
|
|
119
127
|
var receiver = new virtualKeypad.Receiver(
|
|
120
128
|
keypad_options,
|
|
121
129
|
ondata_callback,
|
|
122
|
-
()=>{
|
|
130
|
+
() => {
|
|
123
131
|
const disableButton = document.getElementById("toggle-disable");
|
|
124
132
|
disableButton.style.display = "block";
|
|
125
133
|
disableButton.onclick = disableSomeKeys;
|
|
126
|
-
const changeAlphabetButton =
|
|
134
|
+
const changeAlphabetButton =
|
|
135
|
+
document.getElementById("randomize-alphabet");
|
|
127
136
|
changeAlphabetButton.style.display = "block";
|
|
128
137
|
changeAlphabetButton.onclick = changeAlphabet;
|
|
129
138
|
|
|
130
139
|
console.log("RECEIV Handshake complete");
|
|
131
140
|
},
|
|
132
|
-
()=>console.log("RECEIV Connection connected"),
|
|
133
|
-
()=>console.log("RECEIV Connection closed"),
|
|
134
|
-
()=>console.log("RECEIV Connection error")
|
|
141
|
+
() => console.log("RECEIV Connection connected"),
|
|
142
|
+
() => console.log("RECEIV Connection closed"),
|
|
143
|
+
() => console.log("RECEIV Connection error")
|
|
135
144
|
);
|
|
136
145
|
const randomSelection = (source) => {
|
|
137
146
|
const maybe = () => Math.random() > 0.5;
|
|
138
147
|
const selection = [];
|
|
139
|
-
for (let i=0; i<source.length; i++){
|
|
148
|
+
for (let i = 0; i < source.length; i++) {
|
|
140
149
|
if (maybe()) selection.push(source[i]);
|
|
141
150
|
}
|
|
142
151
|
return selection;
|
package/package.json
CHANGED
package/src/keypad.js
CHANGED
package/src/maxKeySize.js
CHANGED
|
@@ -60,9 +60,7 @@ export const applyMaxKeySize = (numberOfKeys) => {
|
|
|
60
60
|
numberOfKeys,
|
|
61
61
|
aspect
|
|
62
62
|
);
|
|
63
|
-
|
|
64
|
-
`keyHeightPx: ${keyHeightPx}, cols: ${cols}, rows: ${rows}, widthPx: ${widthPx}, heightPx: ${heightPx}`
|
|
65
|
-
);
|
|
63
|
+
|
|
66
64
|
const keyElems = [...keysElem.getElementsByClassName("response-button")];
|
|
67
65
|
const controlKeyElemsMask = keyElems.map(
|
|
68
66
|
(e) => e.parentNode.id === "keypad-control-keys"
|
|
@@ -77,10 +75,6 @@ export const applyMaxKeySize = (numberOfKeys) => {
|
|
|
77
75
|
const verticalMarginOffset = Math.floor(freeHeight / 2);
|
|
78
76
|
const horizontalMarginOffset = Math.floor(freeWidth / 2);
|
|
79
77
|
|
|
80
|
-
console.log(
|
|
81
|
-
`widthUsed: ${widthUsed}, heightUsed: ${heightUsed}, freeHeight: ${freeHeight}, freeWidth: ${freeWidth}, verticalMarginOffset: ${verticalMarginOffset}, horizontalMarginOffset: ${horizontalMarginOffset}`
|
|
82
|
-
);
|
|
83
|
-
|
|
84
78
|
const controlKeys = [];
|
|
85
79
|
let controlKeyFontSize = Infinity;
|
|
86
80
|
let keyFontSize;
|