diff options
Diffstat (limited to 'public/scripts/input_pin.js')
-rw-r--r-- | public/scripts/input_pin.js | 74 |
1 files changed, 50 insertions, 24 deletions
diff --git a/public/scripts/input_pin.js b/public/scripts/input_pin.js index c28d6e9..69b068b 100644 --- a/public/scripts/input_pin.js +++ b/public/scripts/input_pin.js @@ -6,6 +6,7 @@ */ const $ = require('jquery'); + let pin = []; /** @@ -13,31 +14,50 @@ let pin = []; * @param callback */ function init(callback) { - let tryCount = 0; + let tryCount = 0; - $('#1').focus().on('input', (el) => { - pin.push($(el.target).val()); - $(el.target).val('*'); - $('#' + (parseInt($(el.target).attr('id')) + 1).toString()).focus(); + $('#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(); + $('#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(); + $('#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) + $('#4') + .on('input', (el) => { + pin.push($(el.target) + .val()); + $(el.target) + .val('*'); + tryCount++; + callback(pin.join(''), tryCount); }); } @@ -45,18 +65,24 @@ function init(callback) { * 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 = []; + $('#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...'); + // TODO: Add loading animation + $('#pin_message') + .text('Generating keys...'); } exports.init = init; |