From 0d564010a866538b54a9c5c2678ddb3b23a2b83f Mon Sep 17 00:00:00 2001 From: Rui Barreira <83356081+rpbarreira@users.noreply.github.com> Date: Mon, 3 Apr 2023 11:55:17 +0100 Subject: [PATCH 1/2] Added keysCallback, keysBackspaceCallback and getElementFocusListener method Added keysCallback to be able to call it every time any key is clicked Added keysBackspaceCallback to be able to call it every time the backspace key is clicked Added getElementFocusListener method to get the focus event listener of an element by its id --- src/kioskboard.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/kioskboard.js b/src/kioskboard.js index a008a08..bfa62cd 100644 --- a/src/kioskboard.js +++ b/src/kioskboard.js @@ -65,6 +65,8 @@ keysFontSize: '22px', keysFontWeight: 'normal', keysIconSize: '25px', + keysCallback: undefined, + keysBackspaceCallback: undefined, keysEnterText: 'Enter', keysEnterCallback: undefined, keysEnterCanClose: true, @@ -72,6 +74,7 @@ var kioskBoardCachedKeys; var kioskBoardNewOptions; var kioskBoardGithubUrl = 'https://github.com/furcan/KioskBoard'; + var kioskBoardElementsWithFocusListener = {}; var kioskBoardSpecialCharacters = { '0': '!', '1': '\'', @@ -662,6 +665,10 @@ // input trigger change event for update the value input.dispatchEvent(changeEvent); } + + if (typeof opt.keysCallback === 'function') { + opt.keysCallback(); + } }); } } @@ -715,6 +722,10 @@ // input trigger change event for update the value input.dispatchEvent(changeEvent); + + if (typeof opt.keysBackspaceCallback === 'function') { + opt.keysBackspaceCallback(); + } }); } // backspace key click listener: end @@ -875,6 +886,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 @@ -946,6 +960,9 @@ } // Step 3: Select the element(s): end }, + getElementFocusListener: function (elementId) { + return kioskBoardElementsWithFocusListener[elementId]; + }, }; return KioskBoard; From e6e47d6f61440722c3cb3894553b5049cd5ae56e Mon Sep 17 00:00:00 2001 From: Rui Barreira <83356081+rpbarreira@users.noreply.github.com> Date: Mon, 18 Mar 2024 18:05:29 +0000 Subject: [PATCH 2/2] Add a decimal separator key for numpad on "keysNumpadArrayOfNumbers" for override --- src/kioskboard.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/kioskboard.js b/src/kioskboard.js index bfa62cd..d9f9270 100644 --- a/src/kioskboard.js +++ b/src/kioskboard.js @@ -445,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; @@ -454,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 = '' + value3.toString() + ''; - numpadKeysContent += eachKey3; + if (!isNaN(parseInt(value3))) { // only the numbers + var eachKey3 = '' + value3.toString() + ''; + numpadKeysContent += eachKey3; + } + if (value3 == ',' || value3 == '.') { // decimal separator + decimalSeparatorKey = '' + value3.toString() + ''; + } } } - keysRowElements += '
' + numpadKeysContent + backspaceKey + enterKey + '
'; + keysRowElements += '
' + numpadKeysContent + backspaceKey + enterKey + decimalSeparatorKey + '
'; } // keyboard type is "numpad": end