JS: Try to maintain focus

This commit is contained in:
Eric Lippmann 2016-01-18 11:04:09 +01:00
parent 4f21e0fb94
commit 81d73bb5e4
1 changed files with 31 additions and 5 deletions

View File

@ -726,6 +726,16 @@
var scrollPos = false;
var self = this;
var containerId = $container.attr('id');
var activeElementPath = false;
if (document.activeElement
&& document.activeElement !== document.body
&& $.contains($container[0], document.activeElement)
) {
// Active element in container
activeElementPath = this.icinga.utils.getCSSPath($(document.activeElement));
}
if (typeof containerId !== 'undefined') {
if (autorefresh) {
scrollPos = $container.scrollTop();
@ -733,9 +743,6 @@
scrollPos = 0;
}
}
if (autorefresh && $.contains($container[0], document.activeElement)) {
var origFocus = self.icinga.utils.getDomPath(document.activeElement);
}
$container.trigger('beforerender');
@ -788,9 +795,28 @@
}
this.icinga.ui.assignUniqueContainerIds();
if (origFocus && origFocus.length > 0 && origFocus[0] !== '') {
if (! activeElementPath) {
// Active element was not in this container
if (! autorefresh) {
setTimeout(function() {
if (typeof $container.attr('tabindex') === 'undefined') {
$container.attr('tabindex', -1);
}
$container.focus();
}, 0);
}
} else {
setTimeout(function() {
$(self.icinga.utils.getElementByDomPath(origFocus)).focus();
var $activeElement = $(activeElementPath);
if ($activeElement.length) {
$activeElement.focus();
} else if (! autorefresh) {
if (typeof $container.attr('tabindex') === 'undefined') {
$container.attr('tabindex', -1);
}
$container.focus();
}
}, 0);
}