diff options
Diffstat (limited to 'core/misc/ajax.js')
-rw-r--r-- | core/misc/ajax.js | 32 |
1 files changed, 9 insertions, 23 deletions
diff --git a/core/misc/ajax.js b/core/misc/ajax.js index 252e0db24d1..d7c776a7065 100644 --- a/core/misc/ajax.js +++ b/core/misc/ajax.js @@ -1337,14 +1337,16 @@ // Parse response.data into an element collection. const parseHTML = (htmlString) => { const fragment = document.createDocumentFragment(); - // Create a temporary div element - const tempDiv = fragment.appendChild(document.createElement('div')); + // Create a temporary template element. + const template = fragment.appendChild( + document.createElement('template'), + ); - // Set the innerHTML of the div to the provided HTML string - tempDiv.innerHTML = htmlString; + // Set the innerHTML of the template to the provided HTML string. + template.innerHTML = htmlString; - // Return the contents of the temporary div - return tempDiv.childNodes; + // Return the contents of the temporary template. + return template.content.childNodes; }; let $newContent = $(parseHTML(response.data)); @@ -1860,23 +1862,7 @@ * Selector to use. */ scrollTop(ajax, response) { - const offset = $(response.selector).offset(); - // We can't guarantee that the scrollable object should be - // the body, as the element could be embedded in something - // more complex such as a modal popup. Recurse up the DOM - // and scroll the first element that has a non-zero top. - let scrollTarget = response.selector; - while ($(scrollTarget).scrollTop() === 0 && $(scrollTarget).parent()) { - scrollTarget = $(scrollTarget).parent(); - } - - // Only scroll upward. - if (offset.top - 10 < $(scrollTarget).scrollTop()) { - scrollTarget.get(0).scrollTo({ - top: offset.top - 10, - behavior: 'smooth', - }); - } + document.querySelector(response.selector)?.scrollIntoView(); }, }; |