diff options
Diffstat (limited to 'app/assets/javascripts/lib/utils/common_utils.js')
-rw-r--r-- | app/assets/javascripts/lib/utils/common_utils.js | 97 |
1 files changed, 5 insertions, 92 deletions
diff --git a/app/assets/javascripts/lib/utils/common_utils.js b/app/assets/javascripts/lib/utils/common_utils.js index a60748215ab..8bf9a281151 100644 --- a/app/assets/javascripts/lib/utils/common_utils.js +++ b/app/assets/javascripts/lib/utils/common_utils.js @@ -53,16 +53,6 @@ export const getCspNonceValue = () => { return metaTag && metaTag.content; }; -export const ajaxGet = url => - axios - .get(url, { - params: { format: 'js' }, - responseType: 'text', - }) - .then(({ data }) => { - $.globalEval(data, { nonce: getCspNonceValue() }); - }); - export const rstrip = val => { if (val) { return val.replace(/\s+$/, ''); @@ -105,6 +95,7 @@ export const handleLocationHash = () => { const topPadding = 8; const diffFileHeader = document.querySelector('.js-file-title'); const versionMenusContainer = document.querySelector('.mr-version-menus-container'); + const fixedIssuableTitle = document.querySelector('.issue-sticky-header'); let adjustment = 0; if (fixedNav) adjustment -= fixedNav.offsetHeight; @@ -133,6 +124,10 @@ export const handleLocationHash = () => { adjustment -= versionMenusContainer.offsetHeight; } + if (isInIssuePage()) { + adjustment -= fixedIssuableTitle.offsetHeight; + } + if (isInMRPage()) { adjustment -= topPadding; } @@ -370,34 +365,6 @@ export const insertText = (target, text) => { target.dispatchEvent(event); }; -export const nodeMatchesSelector = (node, selector) => { - const matches = - Element.prototype.matches || - Element.prototype.matchesSelector || - Element.prototype.mozMatchesSelector || - Element.prototype.msMatchesSelector || - Element.prototype.oMatchesSelector || - Element.prototype.webkitMatchesSelector; - - if (matches) { - return matches.call(node, selector); - } - - // IE11 doesn't support `node.matches(selector)` - - let { parentNode } = node; - - if (!parentNode) { - parentNode = document.createElement('div'); - // eslint-disable-next-line no-param-reassign - node = node.cloneNode(true); - parentNode.appendChild(node); - } - - const matchingNodes = parentNode.querySelectorAll(selector); - return Array.prototype.indexOf.call(matchingNodes, node) !== -1; -}; - /** this will take in the headers from an API response and normalize them this way we don't run into production issues when nginx gives us lowercased header keys @@ -413,24 +380,6 @@ export const normalizeHeaders = headers => { }; /** - this will take in the getAllResponseHeaders result and normalize them - this way we don't run into production issues when nginx gives us lowercased header keys -*/ -export const normalizeCRLFHeaders = headers => { - const headersObject = {}; - const headersArray = headers.split('\n'); - - headersArray.forEach(header => { - const keyValue = header.split(': '); - - // eslint-disable-next-line prefer-destructuring - headersObject[keyValue[0]] = keyValue[1]; - }); - - return normalizeHeaders(headersObject); -}; - -/** * Parses pagination object string values into numbers. * * @param {Object} paginationInformation @@ -638,13 +587,6 @@ export const setFaviconOverlay = overlayPath => { ); }; -export const setFavicon = faviconPath => { - const faviconEl = document.getElementById('favicon'); - if (faviconEl && faviconPath) { - faviconEl.setAttribute('href', faviconPath); - } -}; - export const resetFavicon = () => { const faviconEl = document.getElementById('favicon'); @@ -883,35 +825,6 @@ export const searchBy = (query = '', searchSpace = {}) => { */ export const isScopedLabel = ({ title = '' }) => title.indexOf('::') !== -1; -window.gl = window.gl || {}; -window.gl.utils = { - ...(window.gl.utils || {}), - getPagePath, - isInGroupsPage, - isInProjectPage, - getProjectSlug, - getGroupSlug, - isInIssuePage, - ajaxGet, - rstrip, - updateTooltipTitle, - disableButtonIfEmptyField, - handleLocationHash, - isInViewport, - parseUrl, - parseUrlPathname, - getUrlParamsArray, - isMetaKey, - isMetaClick, - scrollToElement, - getParameterByName, - getSelectedFragment, - insertText, - nodeMatchesSelector, - spriteIcon, - imagePath, -}; - // Methods to set and get Cookie export const setCookie = (name, value) => Cookies.set(name, value, { expires: 365 }); |