Fix skip to content jump link

This commit is contained in:
Eric Lippmann 2016-01-18 11:36:50 +01:00
parent 81d73bb5e4
commit 3ab5b5b721
2 changed files with 15 additions and 8 deletions

View File

@ -441,7 +441,6 @@
if (href.match(remote)) {
return true;
}
// window.open is used as return true; didn't work reliable
if (linkTarget === '_blank' || linkTarget === '_self') {
window.open(href, linkTarget);
@ -472,7 +471,8 @@
// This is an anchor only
if (href.substr(0, 1) === '#' && href.length > 1
&& href.substr(1, 1) !== '!') {
&& href.substr(1, 1) !== '!'
) {
icinga.ui.focusElement(href.substr(1), $a.closest('.container'));
return;
}

View File

@ -132,17 +132,21 @@
/**
* Focus the given element and scroll to its position
*
* @param {string} element The name or id of the element to focus
* @param {object} $container The container containing the element
* @param {string} element The name or id of the element to focus
* @param {object} [$container] The container containing the element
*/
focusElement: function(element, $container) {
var $element = $('#' + element, $container);
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.replace(/'/, '\\\'') + '"]', $container);
if ($container && $container.length) {
$element = $container.find('[name="' + element.replace(/'/, '\\\'') + '"]');
} else {
$element = $('[name="' + element.replace(/'/, '\\\'') + '"]');
}
}
if ($element.length) {
@ -151,8 +155,11 @@
}
$element.focus();
$container.scrollTop(0);
$container.scrollTop($element.first().position().top);
if ($container && $container.length) {
$container.scrollTop(0);
$container.scrollTop($element.first().position().top);
}
}
},