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:
Diffstat (limited to 'app/assets/javascripts/lib/utils/common_utils.js')
-rw-r--r--app/assets/javascripts/lib/utils/common_utils.js12
1 files changed, 8 insertions, 4 deletions
diff --git a/app/assets/javascripts/lib/utils/common_utils.js b/app/assets/javascripts/lib/utils/common_utils.js
index 1ed0cc3130b..7925a10344a 100644
--- a/app/assets/javascripts/lib/utils/common_utils.js
+++ b/app/assets/javascripts/lib/utils/common_utils.js
@@ -11,6 +11,8 @@ import { convertToCamelCase, convertToSnakeCase } from './text_utility';
import { isObject } from './type_utility';
import { getLocationHash } from './url_utility';
+export const NO_SCROLL_TO_HASH_CLASS = 'js-no-scroll-to-hash';
+
export const getPagePath = (index = 0) => {
const { page = '' } = document.body.dataset;
return page.split(':')[index];
@@ -68,6 +70,10 @@ export const handleLocationHash = () => {
hash = decodeURIComponent(hash);
const target = document.getElementById(hash) || document.getElementById(`user-content-${hash}`);
+
+ // Allow targets to opt out of scroll behavior
+ if (target?.classList.contains(NO_SCROLL_TO_HASH_CLASS)) return;
+
const fixedTabs = document.querySelector('.js-tabs-affix');
const fixedDiffStats = document.querySelector('.js-diff-files-changed');
const fixedNav = document.querySelector('.navbar-gitlab');
@@ -585,8 +591,7 @@ export const addSelectOnFocusBehaviour = (selector = '.js-select-on-focus') => {
* @param {Number} precision
*/
export const roundOffFloat = (number, precision = 0) => {
- // eslint-disable-next-line no-restricted-properties
- const multiplier = Math.pow(10, precision);
+ const multiplier = 10 ** precision;
return Math.round(number * multiplier) / multiplier;
};
@@ -616,8 +621,7 @@ export const roundToNearestHalf = (num) => Math.round(num * 2).toFixed() / 2;
* @param {Number} precision
*/
export const roundDownFloat = (number, precision = 0) => {
- // eslint-disable-next-line no-restricted-properties
- const multiplier = Math.pow(10, precision);
+ const multiplier = 10 ** precision;
return Math.floor(number * multiplier) / multiplier;
};