Skip to content

Instantly share code, notes, and snippets.

@schmolzp
Last active October 5, 2020 19:22
Show Gist options
  • Select an option

  • Save schmolzp/918bac81b1b8d8cc8710d01e1451588f to your computer and use it in GitHub Desktop.

Select an option

Save schmolzp/918bac81b1b8d8cc8710d01e1451588f to your computer and use it in GitHub Desktop.
Livechat Focus
<style>
.skipto {
position: absolute;
top: -10000px;
padding: .5rem 1em;
background-color: #000;
color: #fff;
z-index: 1000;
}
.skipto:focus {
position: fixed;
top: 25px;
left: 25px;
}
</style>
<script>
var createSkipToChatElem = document.createElement('a'),
linkText = document.createTextNode("Go to live chat"),
skipToContentElem = document.querySelector('#skiptocontent');
createSkipToChatElem.appendChild(linkText);
createSkipToChatElem.href = "javascript:void(0)";
createSkipToChatElem.classList.add('skipto', 'mod-chat');
window.addEventListener("load", function() {
var liveChatElem = document.getElementById('chat-widget-container');
liveChatElem.tabIndex = 0;
if(liveChatElem) {
skipToContentElem.after(createSkipToChatElem);
var skipToChatElem = document.querySelector('.skipto.mod-chat');
skipToChatElem.addEventListener('click', function(e) {
e.preventDefault();
LC_API.open_chat_window();
setTimeout(function(){
liveChatElem.focus();
}, 500);
});
document.addEventListener('keyup', function(event) {
if(keycode==13 || keycode==32) {
LC_API.on_chat_window_minimized = function() {
returnFocus();
};
LC_API.on_chat_ended = function() {
returnFocus();
};
}
});
}
function returnFocus() {
skipToChatElem.focus();
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment