Guest User

Untitled

a guest
May 28th, 2021
62
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. var isCtrlKeyPressed = false;
  3. var isShiftKeyPressed = false;
  4. var lastSelectedRow = -1;
  5. var numRequests = 0;
  6.  
  7. var onKeyPress = (e) => {
  8.     if (_currentWindowId == null || _currentTable == null)
  9.         return;
  10.  
  11.     if (e.ctrlKey)
  12.         isCtrlKeyPressed = true;
  13.     if (e.shiftKey)
  14.         isShiftKeyPressed = true;
  15.  
  16.     if (isCtrlKeyPressed && e.key == 'a') {
  17.         _currentTable.rows().select();
  18.         isShiftKeyPressed = false;
  19.  
  20.         e.preventDefault();
  21.         e.stopPropagation();
  22.     }
  23.  
  24.     if (e.key == 'ArrowUp') {
  25.         if (!isShiftKeyPressed)
  26.             _currentTable.rows().deselect();
  27.  
  28.         var selectedItems = _currentTable.rows(".selected").indexes();
  29.         if (selectedItems.length == 1)
  30.             lastSelectedRow = selectedItems[0] - 1;
  31.  
  32.         var row = _currentTable.row(lastSelectedRow, { order: 'current' });
  33.         var el = row.node();
  34.  
  35.         if ($(el).hasClass("selected") && lastSelectedRow > 0) {
  36.             row.deselect();
  37.         }
  38.         else
  39.             row.select();
  40.  
  41.         el.scrollIntoView({ block: "center" });
  42.  
  43.         if(lastSelectedRow > 0)
  44.             lastSelectedRow--;
  45.     }
  46.     if (e.key == 'ArrowDown') {
  47.         if (!isShiftKeyPressed)
  48.             _currentTable.rows().deselect();
  49.  
  50.         var selectedItems = _currentTable.rows(".selected").indexes();
  51.         if (selectedItems.length == 1)
  52.             lastSelectedRow = selectedItems[0];
  53.  
  54.         var row = _currentTable.row(lastSelectedRow + 1);
  55.         var el = row.node();
  56.         if ($(el).hasClass("selected") && lastSelectedRow < _currentTable.rows().indexes().length - 2) {
  57.             row.deselect();
  58.         }
  59.         else
  60.             row.select();
  61.  
  62.         el.scrollIntoView({ block: "center" });
  63.  
  64.         if (lastSelectedRow < _currentTable.rows().indexes().length - 2)
  65.             lastSelectedRow++;
  66.     }
  67.     numRequests++;
  68.  
  69.     var redrawTable = function () {
  70.         if (numRequests > 1)
  71.             return;
  72.  
  73.         _currentTable.draw(false);
  74.         numRequests = 0;
  75.     };
  76.  
  77.     window.setTimeout(redrawTable, 50);
  78. }
  79.  
  80. var onKeyUp = (e) => {
  81.     if (e.ctrlKey)
  82.         isCtrlKeyPressed = false;
  83.     if (e.shiftKey)
  84.         isShiftKeyPressed = false;
  85. }
  86.  
  87. $(function () {
  88.     $(document).on("keydown", onKeyPress);
  89.     $(document).on("keyup", onKeyUp);
  90. });
RAW Paste Data