Permalink
Browse files

Unnecessary loop

  • Loading branch information...
lem9 committed Mar 30, 2013
1 parent 1e5d225 commit a746469e9785b12c0bd49b4ad89df3ccca202807
Showing with 27 additions and 33 deletions.
  1. +27 −33 js/keyhandler.js
View
@@ -47,46 +47,40 @@ function onKeyDownArrowsHandler(e)
return;
}
- var x = pos[2], y=pos[1];
+ var x = pos[2], y = pos[1];
var nO = null;
- // skip non existent fields
- for (var i=0; i < 10; i++)
- {
- switch(e.keyCode) {
- case 38:
- // up
- y--;
- break;
- case 40:
- // down
- y++;
- break;
- case 37:
- // left
- x--;
- break;
- case 39:
- // right
- x++;
- break;
- default:
- return;
- }
+ switch(e.keyCode) {
+ case 38:
+ // up
+ y--;
+ break;
+ case 40:
+ // down
+ y++;
+ break;
+ case 37:
+ // left
+ x--;
+ break;
+ case 39:
+ // right
+ x++;
+ break;
+ default:
+ return;
+ }
- var id = "field_" + y + "_" + x;
+ var id = "field_" + y + "_" + x;
+ nO = document.getElementById(id);
+ if (! nO) {
+ id = "field_" + y + "_" + x + "_0";
nO = document.getElementById(id);
- if (!nO) {
- id = "field_" + y + "_" + x + "_0";
- nO = document.getElementById(id);
- }
- if (nO) {
- break;
- }
}
- if (!nO) {
+ // skip non existent fields
+ if (! nO) {
return;
}
nO.focus();

0 comments on commit a746469

Please sign in to comment.