|
701 | 701 | });
|
702 | 702 |
|
703 | 703 | var search_input = document.getElementsByClassName('search-input')[0];
|
704 |
| - search_input.onkeydown = null; |
705 | 704 | search_input.onkeydown = function(e) {
|
706 |
| - var actives = []; |
| 705 | + // "actives" references the currently highlighted item in each search tab. |
| 706 | + // Each array in "actives" represents a tab. |
| 707 | + var actives = [[], [], []]; |
| 708 | + // "current" is used to know which tab we're looking into. |
| 709 | + var current = 0; |
707 | 710 | onEach(document.getElementsByClassName('search-results'), function(e) {
|
708 |
| - onEach(document.getElementsByClassName('highlighted'), function(e) { |
709 |
| - actives.push(e); |
| 711 | + onEach(e.getElementsByClassName('highlighted'), function(e) { |
| 712 | + actives[current].push(e); |
710 | 713 | });
|
| 714 | + current += 1; |
711 | 715 | });
|
712 | 716 |
|
713 | 717 | if (e.which === 38) { // up
|
714 |
| - if (!actives.length || !actives[0].previousElementSibling) { |
| 718 | + if (!actives[currentTab].length || |
| 719 | + !actives[currentTab][0].previousElementSibling) { |
715 | 720 | return;
|
716 | 721 | }
|
717 | 722 |
|
718 |
| - addClass(actives[0].previousElementSibling, 'highlighted'); |
719 |
| - removeClass(actives[0], 'highlighted'); |
| 723 | + addClass(actives[currentTab][0].previousElementSibling, 'highlighted'); |
| 724 | + removeClass(actives[currentTab][0], 'highlighted'); |
720 | 725 | } else if (e.which === 40) { // down
|
721 |
| - if (!actives.length) { |
| 726 | + if (!actives[currentTab].length) { |
722 | 727 | var results = document.getElementsByClassName('search-results');
|
723 | 728 | if (results.length > 0) {
|
724 |
| - var res = results[0].getElementsByClassName('result'); |
| 729 | + var res = results[currentTab].getElementsByClassName('result'); |
725 | 730 | if (res.length > 0) {
|
726 | 731 | addClass(res[0], 'highlighted');
|
727 | 732 | }
|
728 | 733 | }
|
729 |
| - } else if (actives[0].nextElementSibling) { |
730 |
| - addClass(actives[0].nextElementSibling, 'highlighted'); |
731 |
| - removeClass(actives[0], 'highlighted'); |
| 734 | + } else if (actives[currentTab][0].nextElementSibling) { |
| 735 | + addClass(actives[currentTab][0].nextElementSibling, 'highlighted'); |
| 736 | + removeClass(actives[currentTab][0], 'highlighted'); |
732 | 737 | }
|
733 | 738 | } else if (e.which === 13) { // return
|
734 |
| - if (actives.length) { |
735 |
| - document.location.href = actives[0].getElementsByTagName('a')[0].href; |
| 739 | + if (actives[currentTab].length) { |
| 740 | + document.location.href = |
| 741 | + actives[currentTab][0].getElementsByTagName('a')[0].href; |
736 | 742 | }
|
737 |
| - } else if (actives.length > 0) { |
738 |
| - removeClass(actives[0], 'highlighted'); |
| 743 | + } else if (e.which === 9) { // tab |
| 744 | + if (e.shiftKey) { |
| 745 | + printTab(currentTab > 0 ? currentTab - 1 : 2); |
| 746 | + } else { |
| 747 | + printTab(currentTab > 1 ? 0 : currentTab + 1); |
| 748 | + } |
| 749 | + e.preventDefault(); |
| 750 | + } else if (e.which === 16) { // shift |
| 751 | + // Does nothing, it's just to avoid losing "focus" on the highlighted element. |
| 752 | + } else if (actives[currentTab].length > 0) { |
| 753 | + removeClass(actives[currentTab][0], 'highlighted'); |
739 | 754 | }
|
740 | 755 | };
|
741 | 756 | }
|
|
0 commit comments