mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-26 23:34:08 +02:00
js: Don't scroll to re-focused elements after auto-refreshes
refs #2048 refs #3295 refs #3492 refs #3518
This commit is contained in:
parent
f54f2f8627
commit
cb3528a7be
@ -144,6 +144,10 @@
|
|||||||
req.addToHistory = true;
|
req.addToHistory = true;
|
||||||
req.progressTimer = progressTimer;
|
req.progressTimer = progressTimer;
|
||||||
|
|
||||||
|
if (url.match(/#/)) {
|
||||||
|
req.forceFocus = url.split(/#/)[1];
|
||||||
|
}
|
||||||
|
|
||||||
if (id) {
|
if (id) {
|
||||||
this.requests[id] = req;
|
this.requests[id] = req;
|
||||||
}
|
}
|
||||||
@ -453,9 +457,8 @@
|
|||||||
this.failureNotice = null;
|
this.failureNotice = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var url = req.url;
|
|
||||||
this.icinga.logger.debug(
|
this.icinga.logger.debug(
|
||||||
'Got response for ', req.$target, ', URL was ' + url
|
'Got response for ', req.$target, ', URL was ' + req.url
|
||||||
);
|
);
|
||||||
this.processNotificationHeader(req);
|
this.processNotificationHeader(req);
|
||||||
|
|
||||||
@ -606,9 +609,6 @@
|
|||||||
if (oldNotifications) {
|
if (oldNotifications) {
|
||||||
oldNotifications.appendTo($('#notifications'));
|
oldNotifications.appendTo($('#notifications'));
|
||||||
}
|
}
|
||||||
if (url.match(/#/)) {
|
|
||||||
setTimeout(this.icinga.ui.focusElement, 0, url.split(/#/)[1], req.$target);
|
|
||||||
}
|
|
||||||
if (newBody) {
|
if (newBody) {
|
||||||
this.icinga.ui.fixDebugVisibility().triggerWindowResize();
|
this.icinga.ui.fixDebugVisibility().triggerWindowResize();
|
||||||
}
|
}
|
||||||
@ -782,10 +782,15 @@
|
|||||||
var containerId = $container.attr('id');
|
var containerId = $container.attr('id');
|
||||||
|
|
||||||
var activeElementPath = false;
|
var activeElementPath = false;
|
||||||
|
var navigationAnchor = false;
|
||||||
var focusFallback = false;
|
var focusFallback = false;
|
||||||
|
|
||||||
if (forceFocus && forceFocus.length) {
|
if (forceFocus && forceFocus.length) {
|
||||||
|
if (typeof forceFocus === 'string') {
|
||||||
|
navigationAnchor = forceFocus;
|
||||||
|
} else {
|
||||||
activeElementPath = this.icinga.utils.getCSSPath($(forceFocus));
|
activeElementPath = this.icinga.utils.getCSSPath($(forceFocus));
|
||||||
|
}
|
||||||
} else if (document.activeElement && document.activeElement.id === 'search') {
|
} else if (document.activeElement && document.activeElement.id === 'search') {
|
||||||
activeElementPath = '#search';
|
activeElementPath = '#search';
|
||||||
} else if (document.activeElement
|
} else if (document.activeElement
|
||||||
@ -804,7 +809,7 @@
|
|||||||
activeElementPath = this.icinga.utils.getCSSPath($activeElement);
|
activeElementPath = this.icinga.utils.getCSSPath($activeElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof containerId !== 'undefined') {
|
if (! forceFocus && typeof containerId !== 'undefined') {
|
||||||
if (autorefresh || autoSubmit) {
|
if (autorefresh || autoSubmit) {
|
||||||
scrollPos = $container.scrollTop();
|
scrollPos = $container.scrollTop();
|
||||||
} else {
|
} else {
|
||||||
@ -863,7 +868,9 @@
|
|||||||
}
|
}
|
||||||
this.icinga.ui.assignUniqueContainerIds();
|
this.icinga.ui.assignUniqueContainerIds();
|
||||||
|
|
||||||
if (! activeElementPath) {
|
if (navigationAnchor) {
|
||||||
|
setTimeout(this.icinga.ui.focusElement, 0, navigationAnchor, $container);
|
||||||
|
} else if (! activeElementPath) {
|
||||||
// Active element was not in this container
|
// Active element was not in this container
|
||||||
if (! autorefresh) {
|
if (! autorefresh) {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
@ -881,7 +888,7 @@
|
|||||||
var $activeElement = $(activeElementPath);
|
var $activeElement = $(activeElementPath);
|
||||||
|
|
||||||
if ($activeElement.length && $activeElement.is(':visible')) {
|
if ($activeElement.length && $activeElement.is(':visible')) {
|
||||||
$activeElement.focus();
|
$activeElement[0].focus({preventScroll: autorefresh});
|
||||||
} else if (! autorefresh) {
|
} else if (! autorefresh) {
|
||||||
if (focusFallback) {
|
if (focusFallback) {
|
||||||
$(focusFallback.parent).find(focusFallback.child).focus();
|
$(focusFallback.parent).find(focusFallback.child).focus();
|
||||||
@ -900,6 +907,13 @@
|
|||||||
|
|
||||||
if (scrollPos !== false) {
|
if (scrollPos !== false) {
|
||||||
$container.scrollTop(scrollPos);
|
$container.scrollTop(scrollPos);
|
||||||
|
|
||||||
|
// Fallback for browsers without support for focus({preventScroll: true})
|
||||||
|
setTimeout(function () {
|
||||||
|
if ($container.scrollTop() !== scrollPos) {
|
||||||
|
$container.scrollTop(scrollPos);
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Re-enable all click events (disabled as of performance reasons)
|
// Re-enable all click events (disabled as of performance reasons)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user