Prevent from blocking Firefox key binding.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Thu, 11 Sep 2014 01:35:56 +0300
changeset 44 518ab579d24b
parent 43 8b1577211149
child 45 0bcdec3bdaa8
Prevent from blocking Firefox key binding.
2048.html
--- 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() {