Функція Turbolinks перехоплює всі натискання посилань, які направляють на сторінку в програмі, і натомість робить запит через AJAX, замінюючи тіло отриманим вмістом. Це запобіжить появі віджета чату під час перемикання між сторінками, тому вам потрібно буде повторно ініціалізувати його за допомогою методу reinitHelpcrunchWidget.
<script type="text/javascript">
(function(w,d){
w.HelpCrunch=function(){w.HelpCrunch.q.push(arguments)};w.HelpCrunch.q=[];
function r(){var s=document.createElement('script');s.id='helpcrunch-widget-script';s.async=1;s.type='text/javascript';s.src='https://widget.helpcrunch.com/';(d.body||d.head).appendChild(s);}
w.helpcrunchInitWidget = r;
if(w.attachEvent){w.attachEvent('onload',r)}else{w.addEventListener('load',r,false)}
})(window, document);
function runHelpCrunchMethods() {
HelpCrunch('init', 'YOUR_ORGANIZATION_NAME', {
applicationId: YOUR_APPLICATION_ID,
applicationSecret: 'YOUR_APPLICATION_SECRET'});
HelpCrunch('showChatWidget');
}
runHelpCrunchMethods();
function reinitHelpcrunchWidget() {
var helpcrunchWidgetScript = document.getElementById("helpcrunch-widget-script");
var helpcrunchIframeWrapper = document.querySelector('.helpcrunch-iframe-wrapper');
if (helpcrunchWidgetScript && !helpcrunchIframeWrapper) {
helpcrunchWidgetScript.parentNode.removeChild(helpcrunchWidgetScript);
}
if (!helpcrunchIframeWrapper) {
helpcrunchInitWidget();
setTimeout(function() {
runHelpCrunchMethods();
}, 500);
}
}
</script>