diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-23 06:17:13 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-23 06:17:13 +0300 |
commit | a9fa13e4ba46e00081cec1f3af332edcd1520785 (patch) | |
tree | 1d3bca7bd91d7b121633cd3536c0d31031fdb7e6 /app/assets/javascripts/lib | |
parent | 6adb784bf2839a2b8a73de5602cbfe617836526c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/lib')
-rw-r--r-- | app/assets/javascripts/lib/utils/resize_observer.js | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/app/assets/javascripts/lib/utils/resize_observer.js b/app/assets/javascripts/lib/utils/resize_observer.js index e72c6fe1679..5d194340b9e 100644 --- a/app/assets/javascripts/lib/utils/resize_observer.js +++ b/app/assets/javascripts/lib/utils/resize_observer.js @@ -10,22 +10,30 @@ export function createResizeObserver() { }); } -// watches for change in size of a container element (e.g. for lazy-loaded images) -// and scroll the target element to the top of the content area -// stop watching after any user input. So if user opens sidebar or manually -// scrolls the page we don't hijack their scroll position +/** + * Watches for change in size of a container element (e.g. for lazy-loaded images) + * and scrolls the target note to the top of the content area. + * Stops watching after any user input. So if user opens sidebar or manually + * scrolls the page we don't hijack their scroll position + * + * @param {Object} options + * @param {string} options.targetId - id of element to scroll to + * @param {string} options.container - Selector of element containing target + * + * @return {ResizeObserver|null} - ResizeObserver instance if target looks like a note DOM ID + */ export function scrollToTargetOnResize({ - target = window.location.hash, + targetId = window.location.hash.slice(1), container = '#content-body', } = {}) { - if (!target) return null; + if (!targetId) return null; const ro = createResizeObserver(); const containerEl = document.querySelector(container); let interactionListenersAdded = false; function keepTargetAtTop() { - const anchorEl = document.querySelector(target); + const anchorEl = document.getElementById(targetId); if (!anchorEl) return; |