-
Notifications
You must be signed in to change notification settings - Fork 114
/
gatsby-browser.js
82 lines (71 loc) · 2.27 KB
/
gatsby-browser.js
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
75
76
77
78
79
80
81
82
/**
* Implement Gatsby's Browser APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/browser-apis/
*/
import wrapPageElement from './gatsby/wrap-page-element';
const onInitialClientRender = () => {
function destyleMktoForm(mktoForm, options) {
const formEl = mktoForm.getFormElem()[0];
const arrayFrom = Function.prototype.call.bind(Array.prototype.slice);
options = options || {};
// remove element styles from <form> and children
if (!options.keepInline) {
const styledEls = arrayFrom(formEl.querySelectorAll('[style]')).concat(
formEl
);
styledEls.forEach(function (el) {
el.removeAttribute('style');
});
}
// disable remote stylesheets and local styles
if (!options.keepSheets) {
const styleSheets = arrayFrom(document.styleSheets);
styleSheets.forEach(function (ss) {
if (
// eslint-disable-next-line no-undef
[mktoForms2BaseStyle, mktoForms2ThemeStyle].indexOf(ss.ownerNode) !==
-1 ||
formEl.contains(ss.ownerNode)
) {
ss.disabled = true;
}
});
}
if (!options.moreStyles) {
formEl.setAttribute('data-styles-ready', 'true');
}
}
if (typeof window !== 'undefined' && window.MktoForms2) {
// eslint-disable-next-line no-undef
MktoForms2.whenRendered(function (form) {
destyleMktoForm(form);
});
}
};
const onClientEntry = () => {
// Expose both globals so that the NR1 docs can read it.
window.React = require('react');
window.ReactDOM = require('react-dom');
};
const shouldUpdateScroll = ({ routerProps: { location } }) => {
// Offset updates scroll to position beneath the I/O Banner on category/search change
const PAGE_OFFSET_HEIGHT = 310;
const IS_IO = location.pathname.includes('instant-observability');
// scrolls only after search query parameter on I/O site changes
if (IS_IO && location.search) {
window.setTimeout(() =>
window.scrollTo({ top: PAGE_OFFSET_HEIGHT, left: 0, behavior: 'smooth' })
);
// Does not update to default behavior to persist this change
return false;
}
// if we're not on I/O, update to default behavior
return true;
};
export {
wrapPageElement,
onInitialClientRender,
onClientEntry,
shouldUpdateScroll,
};