js: Don't use jquery.focus shorthand anymore, but icinga.ui.focusElement

This commit is contained in:
Johannes Meyer 2019-07-15 16:05:17 +02:00
parent f844094475
commit b168c3d7db
3 changed files with 18 additions and 22 deletions

View File

@ -18,7 +18,7 @@
if (document.activeElement === e.target if (document.activeElement === e.target
|| document.activeElement === document.body || document.activeElement === document.body
) { ) {
$(e.target).find('.autofocus').focus(); e.data.self.icinga.ui.focusElement($(e.target).find('.autofocus'));
} }
}, 0); }, 0);
}; };

View File

@ -819,14 +819,6 @@
// TODO: We do not want to wrap this twice... // TODO: We do not want to wrap this twice...
var $content = $('<div>' + content + '</div>'); var $content = $('<div>' + content + '</div>');
// Disable all click events while rendering
// (Disabling disabled, was ways too slow)
// $('*').click(function (event) {
// event.stopImmediatePropagation();
// event.stopPropagation();
// event.preventDefault();
// });
$('.container', $container).each(function() { $('.container', $container).each(function() {
_this.stopPendingRequestsFor($(this)); _this.stopPendingRequestsFor($(this));
}); });
@ -861,7 +853,7 @@
} }
// Do not touch focus in case a module or component already placed it // Do not touch focus in case a module or component already placed it
if ($(document.activeElement).closest('.container').attr('id') !== containerId) { if ($(document.activeElement).closest('.container').attr('id') !== containerId) {
$container.focus(); _this.icinga.ui.focusElement($container);
} }
}, 0); }, 0);
} }
@ -873,11 +865,11 @@
$activeElement[0].focus({preventScroll: autorefresh}); $activeElement[0].focus({preventScroll: autorefresh});
} else if (! autorefresh) { } else if (! autorefresh) {
if (focusFallback) { if (focusFallback) {
$(focusFallback.parent).find(focusFallback.child).focus(); _this.icinga.ui.focusElement($(focusFallback.parent).find(focusFallback.child));
} else if (typeof $container.attr('tabindex') === 'undefined') { } else if (typeof $container.attr('tabindex') === 'undefined') {
$container.attr('tabindex', -1); $container.attr('tabindex', -1);
} }
$container.focus(); _this.icinga.ui.focusElement($container);
} }
}, 0); }, 0);
} }

View File

@ -154,16 +154,20 @@
* @param {object} [$container] The container containing the element * @param {object} [$container] The container containing the element
*/ */
focusElement: function(element, $container) { focusElement: function(element, $container) {
var $element = $('#' + element); var $element = element;
if (! $element.length) { if (typeof element === 'string') {
// The name attribute is actually deprecated, on anchor tags, $element = $('#' + element);
// but we'll possibly handle links from another source
// (module etc) so that's used as a fallback if (! $element.length) {
if ($container && $container.length) { // The name attribute is actually deprecated, on anchor tags,
$element = $container.find('[name="' + element.replace(/'/, '\\\'') + '"]'); // but we'll possibly handle links from another source
} else { // (module etc) so that's used as a fallback
$element = $('[name="' + element.replace(/'/, '\\\'') + '"]'); if ($container && $container.length) {
$element = $container.find('[name="' + element.replace(/'/, '\\\'') + '"]');
} else {
$element = $('[name="' + element.replace(/'/, '\\\'') + '"]');
}
} }
} }
@ -172,7 +176,7 @@
$element.attr('tabindex', -1); $element.attr('tabindex', -1);
} }
$element.focus(); $element[0].focus();
if ($container && $container.length) { if ($container && $container.length) {
$container.scrollTop(0); $container.scrollTop(0);