Skip to content

Instantly share code, notes, and snippets.

@DeskWOW
Last active January 16, 2018 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DeskWOW/f55682bdf382a4080ea7 to your computer and use it in GitHub Desktop.
Save DeskWOW/f55682bdf382a4080ea7 to your computer and use it in GitHub Desktop.
Custom Desk.com Chat Widget Embed Code
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<style>
.chat-link-container {
display: none;
}
a.chat-link {
display: block;
box-sizing: border-box;
color: white;
padding: 10px 20px;
position: fixed;
bottom: -2px;
right: 0;
margin: 0 20px 0 0;
background: #3498db;
text-shadow: 1px 1px black;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
font-family: sans-serif;
font-size: 0.9em;
text-decoration: none;
box-shadow: inset 1px 1px rgba(255, 255, 255, 0.15);
border: 1px solid #2180C0;
}
a.chat-link:hover {
text-decoration: none;
}
.chat-container {
display: none;
padding: 0;
overflow: hidden;
width: 450px;
height: 375px;
position: fixed;
bottom: 10px;
right: 10px;
z-index: 1000;
border: 2px solid #2C97DE;
border-radius: 4px;
box-shadow: 0 0 25px rgba(0,0,0,.25);
background: #eee;
}
.chat {
width: 100%;
height: 100%;
}
.chat-close {
position: absolute;
top: -4px;
left: -4px;
background: rgb(245, 64, 64);
padding: 2px 4px;
display: block;
color: rgba(165, 16, 16, 1);
border-radius: 100%;
font-size: 14px;
font-weight: bold;
text-shadow: 1px 1px rgba(255, 255, 255, 0.33);
line-height: 13px;
font-family: sans-serif;
box-shadow: inset 1px 1px rgba(255, 255, 255, 0.25), 1px 1px rgba(0, 0, 0, 0.25);
border: 1px solid rgb(255, 74, 74);
}
.chat-close:hover {
background: rgb(255, 74, 74);
color: rgba(165, 16, 16, 1);
text-decoration: none;
box-shadow: inset 1px 1px rgba(255, 255, 255, 0.33), 1px 1px rgba(0, 0, 0, 0.25);
}
.chat-minimize {
position: absolute;
top: -4px;
left: 15px;
padding: 2px 4px;
background: rgb(245, 174, 0);
display: block;
color: rgba(219, 105, 0, 1);
border-radius: 100%;
font-size: 14px;
font-weight: bold;
text-shadow: 1px 1px rgba(255, 255, 255, 0.33);
line-height: 13px;
font-family: sans-serif;
box-shadow: inset 1px 1px rgba(255, 255, 255, 0.25), 1px 1px rgba(0, 0, 0, 0.25);
border: 1px solid rgb(255, 143, 0);
}
.chat-minimize:hover {
background: rgb(255, 184, 0);
color: rgba(219, 105, 0, 1);
text-decoration: none;
box-shadow: inset 1px 1px rgba(255, 255, 255, 0.33), 1px 1px rgba(0, 0, 0, 0.25);
}
</style>
<div class="chat-container">
<a class="chat-close" href="#">x</a>
<a class="chat-minimize" href="#">&ndash;</a>
<iframe class="chat" frameborder="0"></iframe>
</div>
<div class="chat-link-container">
<a class="chat-link" href="#">Start chat</a>
<hr>
</div>
<script>
function getCookie(name) {
match = document.cookie.match(new RegExp(name + '=([^;]+)'));
if (match) return match[1];
}
function revealChat() {
chat_id = getCookie("chat_id");
if (chat_id) {
$(".chat-container").show();
} else {
revealChatLink();
}
}
function revealChatLink() {
$.ajax({
url: '//your-site.desk.com/customer/agent_online_check',
dataType: 'jsonp'
}).done(function(data) {
if (data.routing_agents > 0) {
$(".chat-link-container").show();
}
});
}
$(function() {
chat_id = getCookie("chat_id");
if (chat_id) {
$(".chat").prop("src", "//your-site.desk.com/customer/widget/chats/" + chat_id);
var iframe = $(".chat")[0];
if (iframe.attachEvent){
iframe.attachEvent("onload", function(){
revealChat()
});
} else {
iframe.onload = function(){
revealChat()
};
}
} else {
revealChatLink();
}
$(".chat-link").click(function() {
$(".chat-link-container").hide();
$(".chat-container").show();
chat_id = getCookie("chat_id");
if (chat_id) {
$(".chat").prop("src", "//your-site.desk.com/customer/widget/chats/" + chat_id);
} else {
$(".chat").prop("src", "//your-site.desk.com/customer/widget/chats/new");
}
return false;
});
$(".chat-close").click(function() {
document.cookie="chat_id=;expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/;domain=.desk.com;";
chat_id = false;
$(".chat").prop("src","");
$(".chat-container").hide();
$(".chat-link-container").show();
return false;
});
$(".chat-minimize").click(function() {
$(".chat-container").hide();
$(".chat-link-container").show();
return false;
});
});
</script>
Normal page content goes here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment