forked from newrelic/developer-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-browser.js
58 lines (51 loc) · 1.63 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
/**
* 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');
};
export { wrapPageElement, onInitialClientRender, onClientEntry };