Do not scroll into view empty element

Closes #12783
This commit is contained in:
Cédric Krier
2023-12-03 01:51:48 +01:00
parent e70d24d375
commit e63fe001cb
2 changed files with 14 additions and 11 deletions
+8 -6
View File
@@ -80,12 +80,14 @@
Sao.common.scrollIntoViewIfNeeded = function(element) {
element = element[0];
var rect = element.getBoundingClientRect();
if (rect.bottom > window.innerHeight) {
element.scrollIntoView(false);
}
if (rect.top < 0) {
element.scrollIntoView();
if (element) {
var rect = element.getBoundingClientRect();
if (rect.bottom > window.innerHeight) {
element.scrollIntoView(false);
}
if (rect.top < 0) {
element.scrollIntoView();
}
}
};
+6 -5
View File
@@ -292,8 +292,9 @@
return toolbar;
},
show: function() {
jQuery('#tablist').find('a[href="#' + this.id + '"]')
.tab('show')[0].scrollIntoView();
Sao.common.scrollIntoViewIfNeeded(
jQuery('#tablist').find('a[href="#' + this.id + '"]')
.tab('show'));
},
close: function() {
var tabs = jQuery('#tabs');
@@ -378,8 +379,8 @@
}
for (const other of Sao.Tab.tabs) {
if (other.compare(attributes)) {
tablist.find('a[href="#' + other.id + '"]')
.tab('show')[0].scrollIntoView();
Sao.common.scrollIntoViewIfNeeded(
tablist.find('a[href="#' + other.id + '"]').tab('show'));
return;
}
}
@@ -436,7 +437,7 @@
tab_link.on('shown.bs.tab', function(evt) {
tabs.scrollTop(jQuery(evt.target).data('scrollTop') || 0);
});
tab_link.tab('show')[0].scrollIntoView();
Sao.common.scrollIntoViewIfNeeded(tab_link.tab('show'));
tabs.trigger('ready');
};