-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathdub-support.js
More file actions
50 lines (43 loc) · 1.52 KB
/
dub-support.js
File metadata and controls
50 lines (43 loc) · 1.52 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
(function () {
"use strict";
const ALLOWED_ORIGIN = "https://app.dub.co";
const EMBED_URL = `${ALLOWED_ORIGIN}/embed/support-chat?variant=bubble`;
const BUBBLE_SIZE = 100;
const PANEL_WIDTH = 580;
const PANEL_HEIGHT = 700;
function init() {
if (document.getElementById("dub-support-iframe")) return;
const iframe = document.createElement("iframe");
iframe.id = "dub-support-iframe";
iframe.src = EMBED_URL;
iframe.title = "Dub Support Chat";
iframe.setAttribute("allowtransparency", "true");
iframe.setAttribute("allow", "same-origin");
iframe.style.cssText =
"position:fixed;bottom:0;right:0;z-index:2147483646;" +
"width:" +
BUBBLE_SIZE +
"px;height:" +
BUBBLE_SIZE +
"px;" +
"border:none;background:transparent;color-scheme:auto;" +
"transition:width 0.2s ease,height 0.2s ease;";
window.addEventListener("message", function (e) {
if (e.origin !== ALLOWED_ORIGIN) return;
if (!e.data || e.data.type !== "dub-support-chat") return;
if (e.data.isOpen) {
iframe.style.width = Math.min(PANEL_WIDTH, window.innerWidth) + "px";
iframe.style.height = Math.min(PANEL_HEIGHT, window.innerHeight) + "px";
} else {
iframe.style.width = BUBBLE_SIZE + "px";
iframe.style.height = BUBBLE_SIZE + "px";
}
});
document.body.appendChild(iframe);
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", init);
} else {
setTimeout(init, 100);
}
})();