--- a/2048.html Wed Sep 10 20:41:49 2014 +0300
+++ b/2048.html Thu Sep 11 01:35:56 2014 +0300
@@ -436,16 +436,13 @@
document.body.addEventListener("keydown", function(event) {
if (document.activeElement.value)
- return false;
+ return;
var key = event.keyCode || event.which;
- switch (key) {
- case 38: ui.action.up(); break;
- case 40: ui.action.down(); break;
- case 37: ui.action.left(); break;
- case 39: ui.action.right(); break;
+ var keyMoves = {38: "up", 40: "down", 37: "left", 39: "right"};
+ if (key in keyMoves) {
+ ui.action[keyMoves[key]]();
+ event.preventDefault();
}
- event.preventDefault();
- return false;
});
document.getElementById("test").addEventListener("click", function() {