diff --git a/src/kioskboard.js b/src/kioskboard.js index a008a08..d9f9270 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': '\'', @@ -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; @@ -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 = '' + 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 @@ -662,6 +671,10 @@ // input trigger change event for update the value input.dispatchEvent(changeEvent); } + + if (typeof opt.keysCallback === 'function') { + opt.keysCallback(); + } }); } } @@ -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 @@ -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 @@ -946,6 +966,9 @@ } // Step 3: Select the element(s): end }, + getElementFocusListener: function (elementId) { + return kioskBoardElementsWithFocusListener[elementId]; + }, }; return KioskBoard;