forked from adamlaska/circleci-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
74 lines (60 loc) · 2.11 KB
/
utils.js
File metadata and controls
74 lines (60 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import Cookies from 'js-cookie';
export function isProduction() {
return window.location.origin === 'https://circleci.com';
}
export function isUnsupportedBrowser() {
if (typeof window === 'undefined') return true;
const ua = window?.navigator?.userAgent;
const msie = ua.indexOf('MSIE ');
return msie > 0;
}
const displayElement = (el, display) => {
if (el) {
el.style.display = display;
}
};
export const displayInitialElement = (el) => displayElement(el, 'initial');
export const displayBlockElement = (el) => displayElement(el, 'block');
/**
* checks if an item is in the viewport
* shamelessly borrowed from https://stackoverflow.com/a/7557433
* */
export function isElementInViewport(el) {
if (!(el instanceof HTMLElement)) {
return false;
}
// Special bonus for those using jQuery
if (typeof jQuery === 'function' && el instanceof jQuery) {
el = el[0];
}
var rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <=
(window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
}
// Refreshes a given cookie (if set) with a new expiration date. If cookie is
// not already set, no action will be taken.
export function updateCookieExpiration(cookieName, newExpiration) {
// Ensure cookie name is a non-empty string. If no cookie name is given,
// js-cookie will return ALL cookies on the subsequent `get()` call.
if (typeof cookieName !== 'string' || cookieName.length < 1) {
return;
}
var existingValue = Cookies.get(cookieName);
// Return early if cookie is not set
if (existingValue === undefined) {
return;
}
// Re-set cookie with same values and new expiration date
Cookies.set(cookieName, existingValue, { expires: newExpiration });
}
const isDataDogUserAgent = () =>
navigator &&
navigator.userAgent &&
navigator.userAgent.indexOf('Datadog/Synthetics') !== -1;
const isDataDogSynthetics = () => window._DATADOG_SYNTHETICS_BROWSER === true;
export const isDataDog = () => isDataDogSynthetics() || isDataDogUserAgent();