js: Properly handle anchor tags with names

refs #8615
This commit is contained in:
Johannes Meyer 2015-08-06 10:58:15 +02:00
parent de24f5f4b6
commit 5c80486b23
1 changed files with 12 additions and 5 deletions

View File

@ -325,11 +325,18 @@
/**
* Handle anchor, i.e. focus the element which is referenced by the anchor
*
* @param {string} query jQuery selector
* @param {string} element The name or id of the element to focus
*/
handleAnchor: function(query) {
var $element = $(query);
if ($element.length > 0) {
handleAnchor: function(element) {
var $element = $('#' + element);
if (! $element.length) {
// The name attribute is actually deprecated, on anchor tags,
// but we'll possibly handle links from another source
// (module etc) so that's used as a fallback
$element = $('[name="' + element + '"]');
}
if ($element.length) {
if (typeof $element.attr('tabindex') === 'undefined') {
$element.attr('tabindex', -1);
}
@ -404,7 +411,7 @@
// This is an anchor only
if (href.substr(0, 1) === '#' && href.length > 1
&& href.substr(1, 1) !== '!') {
self.handleAnchor(href);
self.handleAnchor(href.substr(1));
return;
}