Skip to content

Commit

Permalink
Press enter to add new rows
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspard committed May 1, 2012
1 parent 65fb93e commit 029502f
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions public/javascripts/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,27 +148,38 @@ Grid.keydown = function(event) {
}
Grid.open_cell(prev);
event.stop();
} else if (key == 40) {
} else if (key == 40 || key == 13) {
// find position
var pos = Grid.pos(cell);
// go to next row
var row = cell.up().nextSiblings().first();
var crow = cell.up();
var row = crow.nextSiblings().first();
// find elem
var next = row.childElements()[pos];
if (next) Grid.open_cell(next);
if (!row) {
// open new row
Grid.add_row(crow.up(), cell.up());
row = crow.nextSiblings().first();
var next = row.childElements()[0];
setTimeout(function() {
Grid.open_cell(next);
}, 100);
} else {
next = row.childElements()[pos];
Grid.open_cell(next);
}
event.stop();
} else if (key == 38) {
// go to prev row
var row = cell.up();
if (Grid.pos(row) == 1) {
// stop
} else {
var pos = Grid.pos(cell);
// move up
row = row.previousSiblings().first();
var next = row.childElements()[pos];
Grid.open_cell(next);
}
if (Grid.pos(row) == 1) {
// stop
} else {
var pos = Grid.pos(cell);
// move up
row = row.previousSiblings().first();
var next = row.childElements()[pos];
Grid.open_cell(next);
}
event.stop();
}
return false;
Expand Down

0 comments on commit 029502f

Please sign in to comment.