Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added keysCallback, keysBackspaceCallback, getElementFocusListener and the possibility of a decimal separator key for numpad #81

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions src/kioskboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,16 @@
keysFontSize: '22px',
keysFontWeight: 'normal',
keysIconSize: '25px',
keysCallback: undefined,
keysBackspaceCallback: undefined,
keysEnterText: 'Enter',
keysEnterCallback: undefined,
keysEnterCanClose: true,
};
var kioskBoardCachedKeys;
var kioskBoardNewOptions;
var kioskBoardGithubUrl = 'https://github.com/furcan/KioskBoard';
var kioskBoardElementsWithFocusListener = {};
var kioskBoardSpecialCharacters = {
'0': '!',
'1': '\'',
Expand Down Expand Up @@ -442,7 +445,7 @@
if (keyboardType === kioskBoardTypes.Numpad) {
// check "keysNumpadArrayOfNumbers" for override: begin
var numpadKeys = opt.keysNumpadArrayOfNumbers;
if (Array.isArray(numpadKeys) && numpadKeys.length === 10) {
if (Array.isArray(numpadKeys) && numpadKeys.length === 11) { // length is the number of numbers + 1 decimal separator char (',' or '.')
kioskBoardNumpadKeysObject = numpadKeys.reduce(function (numpadMemo, numpadKey, numpadIndex) {
numpadMemo[numpadIndex] = numpadKey;
return numpadMemo;
Expand All @@ -451,15 +454,21 @@
// check "keysNumpadArrayOfNumbers" for override: end

var numpadKeysContent = '';
var decimalSeparatorKey = '';
for (var key3 in kioskBoardNumpadKeysObject) {
if (Object.prototype.hasOwnProperty.call(kioskBoardNumpadKeysObject, key3)) {
var index3 = key3;
var value3 = kioskBoardNumpadKeysObject[key3];
var eachKey3 = '<span style="font-family:' + fontFamily + ',sans-serif;font-weight:' + fontWeight + ';font-size:' + fontSize + ';" class="kioskboard-key kioskboard-key-' + value3.toString() + ' ' + (index3 === '9' ? 'kioskboard-key-last' : '') + '" data-index="' + index3.toString() + '" data-value="' + value3.toString() + '">' + value3.toString() + '</span>';
numpadKeysContent += eachKey3;
if (!isNaN(parseInt(value3))) { // only the numbers
var eachKey3 = '<span style="font-family:' + fontFamily + ',sans-serif;font-weight:' + fontWeight + ';font-size:' + fontSize + ';" class="kioskboard-key kioskboard-key-' + value3.toString() + ' ' + (index3 === '9' ? 'kioskboard-key-last' : '') + '" data-index="' + index3.toString() + '" data-value="' + value3.toString() + '">' + value3.toString() + '</span>';
numpadKeysContent += eachKey3;
}
if (value3 == ',' || value3 == '.') { // decimal separator
decimalSeparatorKey = '<span style="font-family:' + fontFamily + ',sans-serif;font-weight:' + fontWeight + ';font-size:' + fontSize + ';" class="kioskboard-key" data-index="' + index3.toString() + '" data-value="' + value3.toString() + '">' + value3.toString() + '</span>';
}
}
}
keysRowElements += '<div class="kioskboard-row kioskboard-row-numpad">' + numpadKeysContent + backspaceKey + enterKey + '</div>';
keysRowElements += '<div class="kioskboard-row kioskboard-row-numpad">' + numpadKeysContent + backspaceKey + enterKey + decimalSeparatorKey + '</div>';
}
// keyboard type is "numpad": end

Expand Down Expand Up @@ -662,6 +671,10 @@
// input trigger change event for update the value
input.dispatchEvent(changeEvent);
}

if (typeof opt.keysCallback === 'function') {
opt.keysCallback();
}
});
}
}
Expand Down Expand Up @@ -715,6 +728,10 @@

// input trigger change event for update the value
input.dispatchEvent(changeEvent);

if (typeof opt.keysBackspaceCallback === 'function') {
opt.keysBackspaceCallback();
}
});
}
// backspace key click listener: end
Expand Down Expand Up @@ -875,6 +892,9 @@
// append keyboard: end
};
input.addEventListener('focus', inputFocusListener); // add input focus listener
if (input.id) {
kioskBoardElementsWithFocusListener[input.id] = inputFocusListener;
}
// each input focus listener: end

// each input focusout listener: begin
Expand Down Expand Up @@ -946,6 +966,9 @@
}
// Step 3: Select the element(s): end
},
getElementFocusListener: function (elementId) {
return kioskBoardElementsWithFocusListener[elementId];
},
};

return KioskBoard;
Expand Down