From 7ebbacf3ac3412cba330e144a9cc6c79a8bfcaa5 Mon Sep 17 00:00:00 2001 From: "Joe L. Wroten" Date: Sun, 1 Nov 2015 22:51:25 -0600 Subject: [PATCH] Added keybindings for calculator usage --- app.js | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/app.js b/app.js index dbce150..c816d75 100644 --- a/app.js +++ b/app.js @@ -1,9 +1,5 @@ -$(document).ready(function() { - // This command is used to initialize some elements and make them work properly - $.material.init(); -}); -new Vue({ +var App = new Vue({ el: '#calculator', data: { result: 0, @@ -40,3 +36,35 @@ new Vue({ } } }); + +$(document).ready(function() { + // This command is used to initialize some elements and make them work properly + $.material.init(); + + // Key Bindings + $(document).on('keypress', function(event) { + switch (event.keyCode) { + case 61: // = + case 13: // Enter + App.equals(); + break; + case 47: // / (Forward Slash... haha) + App.calcAdd('/'); + break; + case 42: // * + case 120: // x + App.calcAdd('*'); + break; + case 45: // - + App.calcAdd('-'); + break; + case 43: // + + App.calcAdd('+'); + break; + default: + if (event.keyCode >= 48 && event.keyCode <= 57) { + App.calcAdd(event.keyCode - 48); + } + } + }); +});