Skip to content

Commit b5f8ea8

Browse files
FIX: Calcom script blocks network (#589)
* Remove calcom * fix: Download calcom script async * add calcom section
1 parent f48505e commit b5f8ea8

File tree

1 file changed

+83
-82
lines changed

1 file changed

+83
-82
lines changed

apps/website/src/components/CalcomEmbedInline.astro

Lines changed: 83 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -26,94 +26,95 @@ const {
2626
hideEventTypeDetails,
2727
eventType,
2828
}}
29+
async
2930
>
30-
const loadCalEmbed = () => {
31-
(function (C, A, L) {
32-
let p = function (a, ar) {
33-
a.q.push(ar);
34-
};
35-
let d = C.document;
36-
C.Cal =
37-
C.Cal ||
38-
function () {
39-
let cal = C.Cal;
40-
let ar = arguments;
41-
if (!cal.loaded) {
42-
cal.ns = {};
43-
cal.q = cal.q || [];
44-
d.head.appendChild(d.createElement("script")).src = A;
45-
cal.loaded = true;
46-
}
47-
if (ar[0] === L) {
48-
const api = function () {
49-
p(api, arguments);
50-
};
51-
const namespace = ar[1];
52-
api.q = api.q || [];
53-
if (typeof namespace === "string") {
54-
cal.ns[namespace] = cal.ns[namespace] || api;
55-
p(cal.ns[namespace], ar);
56-
p(cal, ["initNamespace", namespace]);
57-
} else p(cal, ar);
58-
return;
59-
}
60-
p(cal, ar);
31+
const loadCalEmbed = () => {
32+
(function (C, A, L) {
33+
let p = function (a, ar) {
34+
a.q.push(ar);
6135
};
62-
})(window, "https://app.cal.com/embed/embed.js", "init");
63-
Cal("init", eventType, { origin: "https://cal.com" });
36+
let d = C.document;
37+
C.Cal =
38+
C.Cal ||
39+
function () {
40+
let cal = C.Cal;
41+
let ar = arguments;
42+
if (!cal.loaded) {
43+
cal.ns = {};
44+
cal.q = cal.q || [];
45+
d.head.appendChild(d.createElement("script")).src = A;
46+
cal.loaded = true;
47+
}
48+
if (ar[0] === L) {
49+
const api = function () {
50+
p(api, arguments);
51+
};
52+
const namespace = ar[1];
53+
api.q = api.q || [];
54+
if (typeof namespace === "string") {
55+
cal.ns[namespace] = cal.ns[namespace] || api;
56+
p(cal.ns[namespace], ar);
57+
p(cal, ["initNamespace", namespace]);
58+
} else p(cal, ar);
59+
return;
60+
}
61+
p(cal, ar);
62+
};
63+
})(window, "https://app.cal.com/embed/embed.js", "init");
64+
Cal("init", eventType, { origin: "https://cal.com" });
6465

65-
Cal.ns[eventType]("inline", {
66-
elementOrSelector,
67-
config: { layout, theme: "light" },
68-
calLink,
69-
});
66+
Cal.ns[eventType]("inline", {
67+
elementOrSelector,
68+
config: { layout, theme: "light" },
69+
calLink,
70+
});
7071

71-
Cal.ns[eventType]("ui", {
72-
styles: {
73-
body: {
74-
background: "transparent",
75-
},
76-
branding: {
77-
brandColor: "#FEB534",
78-
lightColor: "#494545",
79-
lighterColor: "#4c4848",
80-
lightestColor: "#7c7777",
81-
highlightColor: "#1E1A1A",
82-
medianColor: "#1E1A1A",
72+
Cal.ns[eventType]("ui", {
73+
styles: {
74+
body: {
75+
background: "transparent",
76+
},
77+
branding: {
78+
brandColor: "#FEB534",
79+
lightColor: "#494545",
80+
lighterColor: "#4c4848",
81+
lightestColor: "#7c7777",
82+
highlightColor: "#1E1A1A",
83+
medianColor: "#1E1A1A",
84+
},
85+
enabledDateButton: {
86+
backgroundColor: "rgba(254, 181, 52, 0.65)", //"rgba(254, 181, 52, 0.40)",
87+
},
88+
disabledDateButton: {
89+
backgroundColor: "rgba(232,232,232,0.30)",
90+
},
8391
},
84-
enabledDateButton: {
85-
backgroundColor: "rgba(254, 181, 52, 0.65)", //"rgba(254, 181, 52, 0.40)",
86-
},
87-
disabledDateButton: {
88-
backgroundColor: "rgba(232,232,232,0.30)",
89-
},
90-
},
91-
hideEventTypeDetails,
92-
layout,
93-
});
92+
hideEventTypeDetails,
93+
layout,
94+
});
9495

95-
Cal.ns[eventType]("on", {
96-
action: "bookingSuccessful",
97-
callback: (e) => {
98-
const {data, type, namespace} = e.detail;
99-
console.log("Booking successful:", {data, type, namespace});
100-
window.location.href = "/contact/success?src=calcom";
101-
}
102-
});
96+
Cal.ns[eventType]("on", {
97+
action: "bookingSuccessful",
98+
callback: (e) => {
99+
const { data, type, namespace } = e.detail;
100+
console.log("Booking successful:", { data, type, namespace });
101+
window.location.href = "/contact/success?src=calcom";
102+
},
103+
});
103104

104-
Cal("on", {
105-
action: "bookingSuccessful",
106-
callback: (e) => {
107-
const {data, type, namespace} = e.detail;
108-
console.log("Global booking successful:", {data, type, namespace});
109-
window.location.href = "/contact/success?src=calcom";
110-
}
111-
});
112-
}
105+
Cal("on", {
106+
action: "bookingSuccessful",
107+
callback: (e) => {
108+
const { data, type, namespace } = e.detail;
109+
console.log("Global booking successful:", { data, type, namespace });
110+
window.location.href = "/contact/success?src=calcom";
111+
},
112+
});
113+
};
113114

114-
if ("requestIdleCallback" in window) {
115-
requestIdleCallback(loadCalEmbed);
116-
} else {
117-
window.addEventListener("load", loadCalEmbed);
118-
}
115+
if ("requestIdleCallback" in window) {
116+
requestIdleCallback(loadCalEmbed);
117+
} else {
118+
window.addEventListener("load", loadCalEmbed);
119+
}
119120
</script>

0 commit comments

Comments
 (0)