shortcuts_handler.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* vim: set expandtab sw=4 ts=4 sts=4: */
  2. /**
  3. * @fileoverview Handle shortcuts in various pages
  4. * @name Shortcuts handler
  5. *
  6. * @requires jQuery
  7. * @requires jQueryUI
  8. */
  9. /**
  10. * Register key events on load
  11. */
  12. $(document).ready(function () {
  13. var databaseOp = false;
  14. var tableOp = false;
  15. var keyD = 68;
  16. var keyT = 84;
  17. var keyK = 75;
  18. var keyS = 83;
  19. var keyF = 70;
  20. var keyE = 69;
  21. var keyH = 72;
  22. var keyC = 67;
  23. var keyBackSpace = 8;
  24. $(document).on('keyup', function (e) {
  25. if (e.target.nodeName === 'INPUT' || e.target.nodeName === 'TEXTAREA' || e.target.nodeName === 'SELECT') {
  26. return;
  27. }
  28. if (e.keyCode === keyD) {
  29. setTimeout(function () {
  30. databaseOp = false;
  31. }, 2000);
  32. } else if (e.keyCode === keyT) {
  33. setTimeout(function () {
  34. tableOp = false;
  35. }, 2000);
  36. }
  37. });
  38. $(document).on('keydown', function (e) {
  39. if (e.ctrlKey && e.altKey && e.keyCode === keyC) {
  40. PMA_console.toggle();
  41. }
  42. if (e.ctrlKey && e.keyCode === keyK) {
  43. e.preventDefault();
  44. PMA_console.toggle();
  45. }
  46. if (e.target.nodeName === 'INPUT' || e.target.nodeName === 'TEXTAREA' || e.target.nodeName === 'SELECT') {
  47. return;
  48. }
  49. var isTable;
  50. var isDb;
  51. if (e.keyCode === keyD) {
  52. databaseOp = true;
  53. } else if (e.keyCode === keyK) {
  54. e.preventDefault();
  55. PMA_console.toggle();
  56. } else if (e.keyCode === keyS) {
  57. if (databaseOp === true) {
  58. isTable = PMA_commonParams.get('table');
  59. isDb = PMA_commonParams.get('db');
  60. if (isDb && ! isTable) {
  61. $('.tab .ic_b_props').first().trigger('click');
  62. }
  63. } else if (tableOp === true) {
  64. isTable = PMA_commonParams.get('table');
  65. isDb = PMA_commonParams.get('db');
  66. if (isDb && isTable) {
  67. $('.tab .ic_b_props').first().trigger('click');
  68. }
  69. } else {
  70. $('#pma_navigation_settings_icon').trigger('click');
  71. }
  72. } else if (e.keyCode === keyF) {
  73. if (databaseOp === true) {
  74. isTable = PMA_commonParams.get('table');
  75. isDb = PMA_commonParams.get('db');
  76. if (isDb && ! isTable) {
  77. $('.tab .ic_b_search').first().trigger('click');
  78. }
  79. } else if (tableOp === true) {
  80. isTable = PMA_commonParams.get('table');
  81. isDb = PMA_commonParams.get('db');
  82. if (isDb && isTable) {
  83. $('.tab .ic_b_search').first().trigger('click');
  84. }
  85. }
  86. } else if (e.keyCode === keyT) {
  87. tableOp = true;
  88. } else if (e.keyCode === keyE) {
  89. $('.ic_b_export').first().trigger('click');
  90. } else if (e.keyCode === keyBackSpace) {
  91. window.history.back();
  92. } else if (e.keyCode === keyH) {
  93. $('.ic_b_home').first().trigger('click');
  94. }
  95. });
  96. });