-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathintercom-facade.js
More file actions
213 lines (203 loc) · 6.83 KB
/
intercom-facade.js
File metadata and controls
213 lines (203 loc) · 6.83 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
document.addEventListener("DOMContentLoaded", function() {
var t = window.intercomSettings;
if (t !== undefined && t.app_id) {
var createDivElement = function(styles, id = null, innerHTML = null) {
var div = document.createElement("div");
Object.keys(styles).forEach(function(style) {
div.style[style] = styles[style];
});
if (id) {
div.setAttribute("id", id);
}
if (innerHTML) {
div.innerHTML = innerHTML;
}
return div;
};
var initializeIntercom = function(show) {
if (!window.Intercom) {
var w = window, ic = w.Intercom;
if (typeof ic === "function") {
ic("reattach_activator");
ic("update", w.intercomSettings);
} else {
var d = document, i = function() {
i.c(arguments);
};
i.q = [];
i.c = function(args) {
i.q.push(args);
};
w.Intercom = i;
var l = function() {
var s = d.createElement("script");
s.type = "text/javascript";
s.async = true;
s.src = "https://widget.intercom.io/widget/brxsww1a";
var x = d.getElementsByTagName("script")[0];
x.parentNode.insertBefore(s, x);
};
if (w.attachEvent) {
w.attachEvent("onload", l);
} else {
w.addEventListener("load", l, false);
}
}
}
if (show) {
if (document.querySelector("#intercom-facade-btn")) {
document.querySelector("#intercom-facade-btn").remove();
}
window.Intercom("show");
}
var attempt = 0, maxAttempts = 10, interval = 1000;
var checkIntercomBooted = setInterval(function() {
attempt++;
if (window.Intercom.booted) {
var facadeBtn = document.querySelector("#intercom-facade-btn");
if (facadeBtn) {
facadeBtn.remove();
}
clearInterval(checkIntercomBooted);
} else if (attempt >= maxAttempts) {
clearInterval(checkIntercomBooted);
}
}, interval);
};
var o = createDivElement({
display: "flex",
WebkitBoxAlign: "center",
alignItems: "center",
WebkitBoxPack: "center",
justifyContent: "center",
position: "absolute",
top: "0px",
bottom: "0px",
width: "100%",
transform: "rotate(0deg) scale(1)",
transition: "transform 0.16s linear 0s, opacity 0.08s linear 0s"
}, null, `
<svg
height="32px"
width="28px"
focusable="false"
aria-hidden="true"
viewBox="0 0 28 32">
<path
fill="rgb(255, 255, 255)"
d="M28,32 C28,32 23.2863266,30.1450667 19.4727818,28.6592 L3.43749107,28.6592 C1.53921989,28.6592 0,27.0272 0,25.0144 L0,3.6448 C0,1.632 1.53921989,0 3.43749107,0 L24.5615088,0 C26.45978,0 27.9989999,1.632 27.9989999,3.6448 L27.9989999,22.0490667 L28,22.0490667 L28,32 Z M23.8614088,20.0181333 C23.5309223,19.6105242 22.9540812,19.5633836 22.5692242,19.9125333 C22.5392199,19.9392 19.5537934,22.5941333 13.9989999,22.5941333 C8.51321617,22.5941333 5.48178311,19.9584 5.4277754,19.9104 C5.04295119,19.5629428 4.46760991,19.6105095 4.13759108,20.0170667 C3.97913051,20.2124916 3.9004494,20.4673395 3.91904357,20.7249415 C3.93763774,20.9825435 4.05196575,21.2215447 4.23660523,21.3888 C4.37862552,21.5168 7.77411059,24.5386667 13.9989999,24.5386667 C20.2248893,24.5386667 23.6203743,21.5168 23.7623946,21.3888 C23.9467342,21.2215726 24.0608642,20.9827905 24.0794539,20.7254507 C24.0980436,20.4681109 24.0195551,20.2135019 23.8614088,20.0181333 Z"
/>
</svg>
`);
var i = createDivElement({
display: "flex",
WebkitBoxAlign: "center",
alignItems: "center",
WebkitBoxPack: "center",
justifyContent: "center",
position: "absolute",
top: "0px",
bottom: "0px",
width: "100%",
transition: "transform 0.16s linear 0s, opacity 0.08s linear 0s",
opacity: "0",
transform: "rotate(-30deg)"
}, null, `
<svg focusable="false" viewBox="0 0 16 14" width="28" height="25" style="width: 16px;">
<path
fill="rgb(255, 255, 255)"
fillRule="evenodd"
clipRule="evenodd"
d="M.116 4.884l1.768-1.768L8 9.232l6.116-6.116 1.768 1.768L8 12.768.116 4.884z"
/>
</svg>
`);
var a = createDivElement({
position: "absolute",
top: "0px",
left: "0px",
width: "60px",
height: "60px",
borderRadius: "50%",
cursor: "pointer",
transformOrigin: "center",
overflowX: "hidden",
overflowY: "hidden",
WebkitBackfaceVisibility: "hidden",
WebkitFontSmoothing: "antialiased"
});
var r = createDivElement({
fontFamily: "intercom-font, 'Helvetica Neue', 'Apple Color Emoji', Helvetica, Arial, sans-serif",
fontSize: "100%",
fontStyle: "normal",
letterSpacing: "normal",
fontStretch: "normal",
fontVariantLigatures: "normal",
fontVariantCaps: "normal",
fontVariantEastAsian: "normal",
fontVariantPosition: "normal",
fontWeight: "normal",
textAlign: "left",
textDecorationLine: "none",
textDecorationStyle: "initial",
textDecorationColor: "initial",
textDecoration: "none",
textIndent: "0px",
textShadow: "none",
textTransform: "none",
boxSizing: "content-box",
WebkitTextEmphasisStyle: "none",
WebkitTextEmphasisColor: "initial",
WebkitFontSmoothing: "antialiased",
lineHeight: 1
});
var l = createDivElement({
zIndex: 2147483004,
position: "fixed",
bottom: "20px",
display: "block",
right: "20px",
width: "60px",
height: "60px",
borderRadius: "50%",
boxShadow: "rgba(0, 0, 0, 0.0588235) 0px 1px 6px 0px, rgba(0, 0, 0, 0.156863) 0px 2px 32px 0px",
backgroundColor: "#333333"
}, "intercom-facade-btn");
if (a && o && i) {
a.append(o);
a.append(i);
} else {
console.error('Failed to create elements a, o, or i.');
}
if (r && a) {
r.append(a);
r.addEventListener("click", function() {
initializeIntercom(true);
});
r.addEventListener("mouseenter", function() {
initializeIntercom(false);
});
} else {
console.error('Failed to create elements r or a.');
}
if (l && r) {
l.append(r);
var body = document.querySelector("body");
if (body) {
body.append(l);
} else {
console.error('Failed to append to body. Body element does not exist.');
}
} else {
console.error('Failed to create elements l or r.');
}
if (t.custom_launcher_selector !== undefined) {
document.querySelectorAll(t.custom_launcher_selector).forEach(function(element) {
element.addEventListener("click", function(event) {
event.preventDefault();
initializeIntercom(true);
});
});
}
}
});