diff options
author | Marvin Borner | 2019-01-27 18:25:08 +0100 |
---|---|---|
committer | Marvin Borner | 2019-01-27 18:25:08 +0100 |
commit | 517736ae1d3813fb3bc7e32c36cd90906d530b91 (patch) | |
tree | 5791a8712fb1f32417b429283fe11cb426e859f3 /public/scripts/input_pin.js | |
parent | dfce4c5a178275f4b7226ae397226cbbf84571a8 (diff) |
Cleaned up code
Diffstat (limited to 'public/scripts/input_pin.js')
-rw-r--r-- | public/scripts/input_pin.js | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/public/scripts/input_pin.js b/public/scripts/input_pin.js new file mode 100644 index 0000000..b496e95 --- /dev/null +++ b/public/scripts/input_pin.js @@ -0,0 +1,57 @@ +const $ = require('jquery'); +let pin = []; + +/** + * Initializes actions of the pin input field + * @param callback + */ +function init(callback) { + let tryCount = 0; + + $('#1').focus().on('input', (el) => { + pin.push($(el.target).val()); + $(el.target).val('*'); + $('#' + (parseInt($(el.target).attr('id')) + 1).toString()).focus(); + }); + + $('#2').on('input', (el) => { + pin.push($(el.target).val()); + $(el.target).val('*'); + $('#' + (parseInt($(el.target).attr('id')) + 1).toString()).focus(); + }); + + $('#3').on('input', (el) => { + pin.push($(el.target).val()); + $(el.target).val('*'); + $('#' + (parseInt($(el.target).attr('id')) + 1).toString()).focus(); + }); + + $('#4').on('input', (el) => { + pin.push($(el.target).val()); + $(el.target).val('*'); + tryCount++; + callback(pin.join(''), tryCount) + }); +} + +/** + * Displays error message and clears input + */ +function isWrong(message) { + $('#pin_message').text(message); + for (let i = 1; i < 5; i++) $(`#${i}`).val(''); + $('#1').focus(); + pin = []; +} + +/** + * Display generation message + */ +function needsGeneration() { + // TODO: Add loading animation + $('#pin_message').text('Generating keys...'); +} + +exports.init = init; +exports.failure = isWrong; +exports.generate = needsGeneration; |