74 lines
1.4 KiB
JavaScript
74 lines
1.4 KiB
JavaScript
|
|
(function ($) {
|
||
|
|
$.fn.enableCellNavigation = function () {
|
||
|
|
|
||
|
|
var arrow = { left: 37, up: 38, right: 39, down: 40 };
|
||
|
|
|
||
|
|
// select all on focus
|
||
|
|
this.find('input').keydown(function (e) {
|
||
|
|
|
||
|
|
// shortcut for key other than arrow keys
|
||
|
|
if ($.inArray(e.which, [arrow.left, arrow.up, arrow.right, arrow.down]) < 0) { return; }
|
||
|
|
|
||
|
|
var input = e.target;
|
||
|
|
var td = $(e.target).closest('td');
|
||
|
|
var moveTo = null;
|
||
|
|
|
||
|
|
switch (e.which) {
|
||
|
|
|
||
|
|
case arrow.left: {
|
||
|
|
if (input.selectionStart == 0) {
|
||
|
|
var $myDiv = $("[id^=ui-id-]");
|
||
|
|
moveTo = td.prev('td:has(input,textarea)');
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
case arrow.right: {
|
||
|
|
if (input.selectionEnd == input.value.length) {
|
||
|
|
var $myDiv = $("[id^=ui-id-]");
|
||
|
|
moveTo = td.next('td:has(input,textarea)');
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
|
||
|
|
case arrow.up:
|
||
|
|
case arrow.down: {
|
||
|
|
|
||
|
|
var tr = td.closest('tr');
|
||
|
|
var pos = td[0].cellIndex;
|
||
|
|
|
||
|
|
var moveToRow = null;
|
||
|
|
if (e.which == arrow.down) {
|
||
|
|
var $myDiv = $("[id^=ui-id-]");
|
||
|
|
moveToRow = tr.next('tr');
|
||
|
|
}
|
||
|
|
else if (e.which == arrow.up) {
|
||
|
|
var $myDiv = $("[id^=ui-id-]");
|
||
|
|
moveToRow = tr.prev('tr');
|
||
|
|
}
|
||
|
|
|
||
|
|
if (moveToRow.length) {
|
||
|
|
moveTo = $(moveToRow[0].cells[pos]);
|
||
|
|
}
|
||
|
|
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
//sprawdza czy wyswietla sie pole autocomplete, jeśli tak to blokuje poruszanie po tabelce
|
||
|
|
if (moveTo && moveTo.length && $myDiv.css('display') != 'block') {
|
||
|
|
|
||
|
|
e.preventDefault();
|
||
|
|
|
||
|
|
moveTo.find('input,textarea').each(function (i, input) {
|
||
|
|
input.focus();
|
||
|
|
input.select();
|
||
|
|
});
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
});
|
||
|
|
|
||
|
|
};
|
||
|
|
})(jQuery);
|
||
|
|
|