|
76 | 76 | highlightSourceLines(null); |
77 | 77 | $(window).on('hashchange', highlightSourceLines); |
78 | 78 |
|
79 | | - $(document).on('keyup', function handleKeyboardShortcut(e) { |
| 79 | + // Helper function for Keyboard events, |
| 80 | + // Get's the char from the keypress event |
| 81 | + // |
| 82 | + // This method is used because e.wich === x is not |
| 83 | + // compatible with non-english keyboard layouts |
| 84 | + // |
| 85 | + // Note: event.type must be keypress ! |
| 86 | + function getChar(event) { |
| 87 | + if (event.which == null) { |
| 88 | + return String.fromCharCode(event.keyCode) // IE |
| 89 | + } else if (event.which!=0 && event.charCode!=0) { |
| 90 | + return String.fromCharCode(event.which) // the rest |
| 91 | + } else { |
| 92 | + return null // special key |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + $(document).on('keypress', function handleKeyboardShortcut(e) { |
80 | 97 | if (document.activeElement.tagName === 'INPUT') { |
81 | 98 | return; |
82 | 99 | } |
83 | 100 |
|
84 | | - if (e.which === 191) { // question mark |
| 101 | + if (getChar(e) === '?') { |
85 | 102 | if (e.shiftKey && $('#help').hasClass('hidden')) { |
86 | 103 | e.preventDefault(); |
87 | 104 | $('#help').removeClass('hidden'); |
88 | 105 | } |
89 | | - } else if (e.which === 27) { // esc |
| 106 | + } else if (getChar(e) === 's' || getChar(e) === 'S') { |
| 107 | + e.preventDefault(); |
| 108 | + $('.search-input').focus(); |
| 109 | + } |
| 110 | + }).on('keydown', function(e) { |
| 111 | + // The escape key event has to be captured with the keydown event. |
| 112 | + // Because keypressed has no keycode for the escape key |
| 113 | + // (and other special keys in general)... |
| 114 | + if (document.activeElement.tagName === 'INPUT') { |
| 115 | + return; |
| 116 | + } |
| 117 | + |
| 118 | + if (e.keyCode === 27) { // escape key |
90 | 119 | if (!$('#help').hasClass('hidden')) { |
91 | 120 | e.preventDefault(); |
92 | 121 | $('#help').addClass('hidden'); |
|
95 | 124 | $('#search').addClass('hidden'); |
96 | 125 | $('#main').removeClass('hidden'); |
97 | 126 | } |
98 | | - } else if (e.which === 83) { // S |
99 | | - e.preventDefault(); |
100 | | - $('.search-input').focus(); |
101 | 127 | } |
102 | 128 | }).on('click', function(e) { |
103 | 129 | if (!$(e.target).closest('#help').length) { |
104 | 130 | $('#help').addClass('hidden'); |
105 | 131 | } |
106 | 132 | }); |
107 | 133 |
|
| 134 | + |
108 | 135 | $('.version-selector').on('change', function() { |
109 | 136 | var i, match, |
110 | 137 | url = document.location.href, |
|
0 commit comments