From e63fe001cb07fa58da8f6b1a47791c42e6d24966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 3 Dec 2023 01:51:48 +0100 Subject: [PATCH] Do not scroll into view empty element Closes #12783 --- sao/src/common.js | 14 ++++++++------ sao/src/tab.js | 11 ++++++----- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/sao/src/common.js b/sao/src/common.js index 16f96be2cf..1d7d7e38b3 100644 --- a/sao/src/common.js +++ b/sao/src/common.js @@ -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(); + } } }; diff --git a/sao/src/tab.js b/sao/src/tab.js index 3711eee130..468a724ea2 100644 --- a/sao/src/tab.js +++ b/sao/src/tab.js @@ -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'); };