Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-09-22 21:11:12 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-09-22 21:11:12 +0300
commit1862f4a83ebb0a08a0da8269c568e1b93f75d55a (patch)
treebfec3ba41bedd2c138b60fdb5c2cc308932f16ee /app/assets/javascripts/lib
parentb6abc9850e69e4e2ab60fa6ababe25da97505edc (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/lib')
-rw-r--r--app/assets/javascripts/lib/utils/common_utils.js45
1 files changed, 20 insertions, 25 deletions
diff --git a/app/assets/javascripts/lib/utils/common_utils.js b/app/assets/javascripts/lib/utils/common_utils.js
index 7925a10344a..c39e4562c14 100644
--- a/app/assets/javascripts/lib/utils/common_utils.js
+++ b/app/assets/javascripts/lib/utils/common_utils.js
@@ -60,6 +60,15 @@ export const disableButtonIfEmptyField = (fieldSelector, buttonSelector, eventNa
});
};
+/**
+ * Return the given element's offset height, or 0 if the element doesn't exist.
+ * Probably not useful outside of handleLocationHash.
+ *
+ * @param {HTMLElement} element The element to measure.
+ * @returns {number} The element's offset height.
+ */
+const getElementOffsetHeight = (element) => element?.offsetHeight ?? 0;
+
// automatically adjust scroll position for hash urls taking the height of the navbar into account
// https://github.com/twitter/bootstrap/issues/1768
export const handleLocationHash = () => {
@@ -84,40 +93,26 @@ export const handleLocationHash = () => {
const fixedIssuableTitle = document.querySelector('.issue-sticky-header');
let adjustment = 0;
- if (fixedNav) adjustment -= fixedNav.offsetHeight;
-
- if (target && target.scrollIntoView) {
- target.scrollIntoView(true);
- }
- if (fixedTabs) {
- adjustment -= fixedTabs.offsetHeight;
- }
-
- if (fixedDiffStats) {
- adjustment -= fixedDiffStats.offsetHeight;
- }
-
- if (performanceBar) {
- adjustment -= performanceBar.offsetHeight;
- }
-
- if (diffFileHeader) {
- adjustment -= diffFileHeader.offsetHeight;
- }
-
- if (versionMenusContainer) {
- adjustment -= versionMenusContainer.offsetHeight;
- }
+ adjustment -= getElementOffsetHeight(fixedNav);
+ adjustment -= getElementOffsetHeight(fixedTabs);
+ adjustment -= getElementOffsetHeight(fixedDiffStats);
+ adjustment -= getElementOffsetHeight(performanceBar);
+ adjustment -= getElementOffsetHeight(diffFileHeader);
+ adjustment -= getElementOffsetHeight(versionMenusContainer);
if (isInIssuePage()) {
- adjustment -= fixedIssuableTitle.offsetHeight;
+ adjustment -= getElementOffsetHeight(fixedIssuableTitle);
}
if (isInMRPage()) {
adjustment -= topPadding;
}
+ if (target?.scrollIntoView) {
+ target.scrollIntoView(true);
+ }
+
setTimeout(() => {
window.scrollBy(0, adjustment);
});