Added keybindings for calculator usage
This commit is contained in:
parent
2f38fdb634
commit
7ebbacf3ac
1 changed files with 33 additions and 5 deletions
38
app.js
38
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',
|
el: '#calculator',
|
||||||
data: {
|
data: {
|
||||||
result: 0,
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue