Skip Links: Add anchor handlint to events

refs #7933
This commit is contained in:
Marius Hein 2015-02-12 13:08:08 +01:00
parent ca4477de5b
commit 53818f50c6
2 changed files with 18 additions and 1 deletions

View File

@ -10,5 +10,6 @@ use Icinga\Web\Widget\SearchDashboard;
/> />
</form> </form>
<? endif; ?> <? endif; ?>
<h1 id="navigation" class="sr-only"><?= t('Navigation'); ?></h1>
<?= $menuRenderer; ?> <?= $menuRenderer; ?>

View File

@ -334,6 +334,17 @@
return false; return false;
}, },
handleAnchor: function(query) {
var element = $(query);
if (element.length > 0) {
// 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.focus();
}
},
/** /**
* Someone clicked a link or tr[href] * Someone clicked a link or tr[href]
@ -383,7 +394,6 @@
return; return;
} }
// ignore multiselect table row clicks // ignore multiselect table row clicks
if ($a.is('tr') && $a.closest('table.multiselect').length > 0) { if ($a.is('tr') && $a.closest('table.multiselect').length > 0) {
return; return;
@ -393,6 +403,12 @@
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
// This is an anchor only
if (href.substr(0, 1) === '#' && href.substr(1, 1) !== '!') {
self.handleAnchor(href);
return;
}
// If link has hash tag... // If link has hash tag...
if (href.match(/#/)) { if (href.match(/#/)) {
if (href === '#') { if (href === '#') {