Keyboard support

Press 1-9 to choose 1st to 9th options, press 0 to choose 10th
This commit is contained in:
Alexander Yakovlev 2021-08-24 15:24:49 +07:00
parent 391eaf25d2
commit 8bc70d497c
Signed by: oreolek
GPG key ID: 8D24103F5EE2A6C0
2 changed files with 29 additions and 7 deletions

View file

@ -106,15 +106,38 @@ jQuery(document).on('click', "#restart", function() {
window.location.reload();
});
jQuery(document).on('click', "#options li a", function() {
s.ChooseChoiceIndex(jQuery(this).data("index"));
saveChoice(jQuery(this).data("index"));
function choose(index) {
s.ChooseChoiceIndex(index);
saveChoice(index);
continueToNextChoice(s);
}
jQuery(document).on('click', "#options li a", function() {
choose(jQuery(this).data("index"));
return false;
});
jQuery(document).on('click', "#options li", function() {
s.ChooseChoiceIndex(jQuery(this).find('a').data("index"));
saveChoice(jQuery(this).data("index"));
continueToNextChoice(s);
choose(jQuery(this).find('a').data("index"));
return false;
});
jQuery(document).on('keydown', function(key) {
key = key.key
switch (key) {
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
jQuery(`#options li:nth-child(${key})`).first().trigger("click")
break;
case '0':
jQuery(`#options li:nth-child(10)`).first().trigger("click")
break;
}
return false;
});

View file

@ -1,7 +1,6 @@
{
"scripts": {
"build": "webpack --config ./webpack.config.js",
"start": "webpack-dev-server --content-base public/ --inline --port 3001",
"prod": "./node_modules/cross-env/src/bin/cross-env.js NODE_ENV=production ./node_modules/webpack/bin/webpack.js --mode=production",
"dev": "./node_modules/cross-env/src/bin/cross-env.js NODE_ENV=development ./node_modules/webpack/bin/webpack.js",
"watch": "./node_modules/webpack/bin/webpack.js --watch"