Focus: Set the focus to the next usable element

Fix copy and paste error and find h1 first.

refs #7976
This commit is contained in:
Marius Hein 2015-02-13 11:39:28 +01:00
parent ce3a564de7
commit bcc03f8160
1 changed files with 9 additions and 11 deletions

View File

@ -337,21 +337,19 @@
handleAnchor: function(query) {
var $element = $(query);
if ($element.length > 0) {
// Try to find the first header. It is more pleasant to users
// to select the header instead a container
var $header = $element.find(':header:first');
if ($header.length > 0) {
$element = $header;
} else {
var $input = $element.find(':header:first');
if ($input.length > 0) {
$element = $input
var focusQueries = ['h1:first', ':header:first', ':input:first'];
$.each(focusQueries, function(index,q) {
var $item = $element.find(q);
if ($item.length > 0) {
$element = $item;
return false;
}
}
});
// If we want to focus an element which has no tabindex
// add one that we can focus is
if ($element.prop('tabindex') < 0) {
$element.prop('tabindex', 0);
$element.prop('tabindex', '-1');
}
$element.focus();
}