Skip to content

Commit

Permalink
In edge cases where Leopard is added after the DOM is loaded then sti…
Browse files Browse the repository at this point in the history
…ll inject it in production
  • Loading branch information
jolzee committed Mar 16, 2020
1 parent ccf34de commit e6c7711
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions public/static/embed-leopard.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,16 @@ document.documentElement.style.setProperty(
"".concat(leopardViewHeight, "px")
);

document.addEventListener('DOMContentLoaded', function () {
function loadLeopard() {
var leopardTargetElement = document.getElementById("leopardChatWindow");
if (leopardTargetElement) {
leopardTargetElement.innerHTML = leopardChatTemplate;
} else {
document.body.insertAdjacentHTML("afterbegin", leopardChatTemplate);
}
});
}

document.addEventListener('DOMContentLoaded', loadLeopard);

function checkLeopardButtonFocus() {
// class teneo-chat-button-widget
Expand Down Expand Up @@ -352,3 +354,10 @@ window.addEventListener(
leopardDebounce(updateLeopardVariables, 200, false),
false
);

if (document.readyState === "ready" || document.readyState === "complete") {
var leopardTargetElement = document.getElementById("leopardChatWindow");
if (!leopardTargetElement) {
loadLeopard();
}
}

0 comments on commit e6c7711

Please sign in to comment.