Skip to content

Commit

Permalink
This should work, but doesn't
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Naessens committed Oct 26, 2022
1 parent ad216d5 commit e508cb3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/assets/javascripts/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,7 @@
});
break;
case "frame_state_change":
console.log("frame_state_change");
var A = document.getElementById(e.frameDivId)
, R = d && d.data
, U = R && R.frameState
Expand Down
14 changes: 13 additions & 1 deletion app/javascript/src/freshdesk/chat_widget_setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,22 @@ function flushFreshchat() {
delete window.history.replaceState
}

// Before page is cached
// Navigating to another page
document.addEventListener("turbolinks:visit", function() {
if(window.fcWidget) {
window.fcWidget.destroy()
} else {
console.warn("No widget found!")
}
})

document.addEventListener("turbolinks:before-cache", function() {
const scriptTag = document.getElementById(freshChatScriptTagId)
scriptTag.parentNode.removeChild(scriptTag)

// Remove css that will be re-added when loading the widget
document.querySelectorAll('link[href*="widget.css"]').forEach(l => l.parentNode.removeChild(l))
document.querySelectorAll('link[href*="cb.css"]').forEach(l => l.parentNode.removeChild(l))
})

// After turbolinks loaded
Expand Down

0 comments on commit e508cb3

Please sign in to comment.