Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Table keyboard navigation
- $('.datatable').on('keydown','td',function(e){
- var currCell = $(this);
- var row = $(this).closest('tr');
- if (e.which == 13 ) { // return
- if($(row).attr('onclick')){
- $(row).trigger("click");
- }else if($(row).find("td:first-child i.icon-plus").length > 0){
- $(row).find("td:first-child i.icon-plus").click();
- }else if($(row).find('a[href]').length > 0){
- $(row).find('a[href]').click();
- }else if($(row).find('.footnote').length > 0){
- $(row).find('.footnote').trigger('click');
- }
- }
- var c = "";
- var tabables = $('a[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), *[tabindex]');
- if (e.which == 39) {
- // Right Arrow
- c = currCell.next();
- if(c.length == 0){
- c = currCell.closest('tr').next().find('td:first');
- if(c.length == 0){
- var index = tabables.index(this);
- c = tabables.eq(index + 1);
- }
- }
- } else if (e.which == 37) {
- // Left Arrow
- c = currCell.prev();
- if(c.length == 0){
- c = currCell.closest('tr').prev().find('td:last');
- if(c.length == 0){
- var index = tabables.index(this);
- c = tabables.eq(index - 1);
- }
- }
- } else if (e.which == 38) {
- // Up Arrow
- c = currCell.closest('tr').prev().find('td:eq(' +
- currCell.index() + ')');
- if(c.length == 0){
- var index = tabables.index(this);
- c = tabables.eq(index - 1);
- }
- } else if (e.which == 40) {
- // Down Arrow
- c = currCell.closest('tr').next().find('td:eq(' +
- currCell.index() + ')');
- if(c.length == 0){
- var index = tabables.index(this);
- c = tabables.eq(index + 1);
- }
- } else if (e.which == 9 && !e.shiftKey) {
- // Tab
- e.preventDefault();
- c = currCell.next();
- if(c.length == 0){
- c = currCell.closest('tr').next().find('td:first');
- if(c.length == 0){
- var index = tabables.index(this);
- c = tabables.eq(index + 1);
- }
- }
- } else if (e.which == 9 && e.shiftKey) {
- // Shift + Tab
- e.preventDefault();
- c = currCell.prev();
- if(c.length == 0){
- c = currCell.closest('tr').prev().find('td:last');
- if(c.length == 0){
- var index = tabables.index(this);
- c = tabables.eq(index - 1);
- }
- }
- }
- // If we didn't hit a boundary, update the current cell
- if (c.length > 0) {
- currCell = c;
- currCell.focus();
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement