In js from the docs, change keyboard eventlistener to be compatible with non-english keyboard layouts. Fixes #26016 Fixes #16572

This commit is contained in:
Mathieu David 2015-06-30 09:32:15 +02:00
parent 27975c49a6
commit 49b73e46d6

View File

@ -76,17 +76,46 @@
highlightSourceLines(null);
$(window).on('hashchange', highlightSourceLines);
$(document).on('keyup', function handleKeyboardShortcut(e) {
// Helper function for Keyboard events,
// Get's the char from the keypress event
//
// This method is used because e.wich === x is not
// compatible with non-english keyboard layouts
//
// Note: event.type must be keypress !
function getChar(event) {
if (event.which == null) {
return String.fromCharCode(event.keyCode) // IE
} else if (event.which!=0 && event.charCode!=0) {
return String.fromCharCode(event.which) // the rest
} else {
return null // special key
}
}
$(document).on('keypress', function handleKeyboardShortcut(e) {
if (document.activeElement.tagName === 'INPUT') {
return;
}
if (e.which === 191) { // question mark
if (getChar(e) === '?') {
if (e.shiftKey && $('#help').hasClass('hidden')) {
e.preventDefault();
$('#help').removeClass('hidden');
}
} else if (e.which === 27) { // esc
} else if (getChar(e) === 's' || getChar(e) === 'S') {
e.preventDefault();
$('.search-input').focus();
}
}).on('keydown', function(e) {
// The escape key event has to be captured with the keydown event.
// Because keypressed has no keycode for the escape key
// (and other special keys in general)...
if (document.activeElement.tagName === 'INPUT') {
return;
}
if (e.keyCode === 27) { // escape key
if (!$('#help').hasClass('hidden')) {
e.preventDefault();
$('#help').addClass('hidden');
@ -95,9 +124,6 @@
$('#search').addClass('hidden');
$('#main').removeClass('hidden');
}
} else if (e.which === 83) { // S
e.preventDefault();
$('.search-input').focus();
}
}).on('click', function(e) {
if (!$(e.target).closest('#help').length) {
@ -105,6 +131,7 @@
}
});
$('.version-selector').on('change', function() {
var i, match,
url = document.location.href,