You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

62 lines
1.5 KiB

  1. (function($){
  2. var SELECTED_FILE_ELEM = null;
  3. var ENABLE_KEY_NAV = true;
  4. $(document).keydown(function(event) {
  5. if (!ENABLE_KEY_NAV)
  6. return true;
  7. var selection = SELECTED_FILE_ELEM;
  8. switch (event.keyCode) {
  9. case 74: // j
  10. if (selection == null) {
  11. selection = $('#f0');
  12. } else {
  13. do {
  14. selection = selection.next();
  15. } while (selection.length > 0 && selection.css('display') == 'none');
  16. }
  17. break;
  18. case 75: // k
  19. if (selection == null) {
  20. selection = $('#f0');
  21. } else {
  22. do {
  23. selection = selection.prev();
  24. } while (selection.length > 0 && selection.css('display') == 'none');
  25. }
  26. break;
  27. case 13: // Enter
  28. case 79: // o
  29. if (selection != null) {
  30. var expander = selection.find('.expander');
  31. if (expander.length > 0) {
  32. expander.click();
  33. } else {
  34. window.location = selection.find('a.file').attr('href');
  35. }
  36. }
  37. return false;
  38. break;
  39. default:
  40. return true;
  41. }
  42. if (selection.length > 0) {
  43. if (SELECTED_FILE_ELEM != null)
  44. SELECTED_FILE_ELEM.removeClass('focus');
  45. selection.addClass('focus');
  46. SELECTED_FILE_ELEM = selection;
  47. }
  48. return false;
  49. });
  50. $(function() {
  51. $('a,input,select,textarea,button')
  52. .focus(function(event) {
  53. ENABLE_KEY_NAV = false;
  54. })
  55. .blur(function(event) {
  56. ENABLE_KEY_NAV = true;
  57. });
  58. });
  59. })(jQuery);