Skip to content

Make floating popup work with self-hosted instance #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions inc/class.embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private function embed($atts): string
$output .= '<script>var customCalUrl = "' . $atts['customCalInstance'] . '";</script>';
break;
case 3:
$output = $this->get_floating_popup_embed_script($atts['url'], $atts['text']);
$output = $this->get_floating_popup_embed_script($atts['url'], $atts['text'], $atts['customCalInstance']);
break;
default:
$output = '<div id="calcom-embed"></div>';
Expand Down Expand Up @@ -77,14 +77,22 @@ public function get_inline_embed_script($url, $custom_cal_url): string
*
* @param $url Booking link
* @param $text Button text
* @param $custom_cal_url Custom cal.com URL (if self-hosted instance is used)
* @return string
*/
public function get_floating_popup_embed_script($url, $text): string
public function get_floating_popup_embed_script($url, $text, $custom_cal_url): string
{
$button_text = strlen($text) > 0 ? '"buttonText":"' . $text . '"' : '';
$script = '<script>
var customCalUrl = "' . $custom_cal_url . '";
addEventListener("DOMContentLoaded", (event) => {
Cal("floatingButton", {"calLink":"' . $url . '"' . (strlen($button_text) == 0 ? "" : "," . $button_text) . '});
if(customCalUrl.length == 0) {
Cal("floatingButton", {"calLink":"' . $url . '"});
}
else {
Cal("floatingButton", {"calLink":"' . $url . '","calOrigin":customCalUrl});
}
});
</script>';

Expand Down