Comments (4)
Do you still face that issue? If yes, can you drop a mail at [email protected] ?
from turbolinks-compatibility.
AFAIK, Rails I18N will not cause the widget to reload several times.
from turbolinks-compatibility.
@TehraniX: HappyFox Chat is one of the very few live chat tool that supports Rails Turbolinks.
To prevent widget reloading please refer https://support.happyfoxchat.com/kb/article/608-turbolinks-support-in-happyfox-chat
Option A: Installs widget in all the pages:
NOTE: This script should be added inside <head>
of the document.
<head>
...
...
<!--Start of HappyFox Live Chat Turbolink Script-->
<script>
document.addEventListener('turbolinks:load', function () {
try {
window.HFCHAT_META.digested = false;
} catch (error) {}
window.HFCHAT_CONFIG = {
EMBED_TOKEN: "<Your Embed Token>",
ACCESS_TOKEN: "<Your Access Token>",
HOST_URL: "<Host URL>",
ASSETS_URL: "<Assets URL>"
};
(function() {
var scriptTag = document.createElement('script');
scriptTag.type = 'text/javascript';
scriptTag.async = true;
scriptTag.src = window.HFCHAT_CONFIG.ASSETS_URL + '/js/widget-loader.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(scriptTag, s);
})();
});
</script>
<!--End of HappyFox Live Chat Turbolink Script-->
</head>
Option B - Install widget only in specific pages:
NOTE: This script should be added inside <body>
of the document.
<body>
...
...
<script>
try {
window.HFCHAT_META.digested = false;
} catch (error) {}
</script>
<script>
if (!document.getElementById('hfc-frame')) {
window.HFCHAT_CONFIG = {
EMBED_TOKEN: "<Your Embed Token>",
ACCESS_TOKEN: "<Your Access Token>",
HOST_URL: "<Host URL>",
ASSETS_URL: "<Assets URL>"
};
(function() {
var scriptTag = document.createElement('script');
scriptTag.type = 'text/javascript';
scriptTag.async = true;
scriptTag.src = window.HFCHAT_CONFIG.ASSETS_URL + '/js/widget-loader.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(scriptTag, s);
})();
}
</script>
</body>
from turbolinks-compatibility.
I was searching on happyFoxChat and ended here. and found this still open.
make a global flag on 'window' so the code runs once per pagelaod.
this is what I have done for many kind of external scripts that I use in React:
// notice the flag: 'HFC__INITIALIZED':
// you can call addHappyFoxChat(chatToken, assetUrl); infinite times now :)
you might customise the flag with md5 hashing for different languages.
const addScriptTag = (d, t) => {
const script = d.createElement('script');
script.async = true;
// script.src = s; <-- use this for refering to other libraries.
script.innerHTML = t;
return script;
};
const injectScript = (t, s) => {
const script = `
window.HFCHAT_CONFIG = {
EMBED_TOKEN: '${t}',
ASSETS_URL: '${s}',
};
(() => {
var scriptTag = document.createElement('script');
scriptTag.type = 'text/javascript';
scriptTag.async = true;
scriptTag.src = window.HFCHAT_CONFIG.ASSETS_URL + '/js/widget-loader.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(scriptTag, s);
})()`;
return script;
};
const addHappyFoxChat = (t, s) => {
if (window.HFC__INITIALIZED) return;
const hfcText = injectScript(t, s);
const lazyScript = addScriptTag(document, hfcText);
document.body.appendChild(lazyScript);
window.HFC__INITIALIZED = true;
};
from turbolinks-compatibility.
Related Issues (20)
- Turbolinks not working with google ads or LiveHelpNow
- Google Tag Manager HOT 5
- Facebook like/share button still disappearing HOT 1
- Marketo munchkin tracker integration request
- Integration with Google TagManager HOT 4
- Can't find a way to change Facebook language HOT 1
- Loading Javascripts Problem HOT 1
- React Native HOT 1
- Turbolinks 5 compatibility HOT 8
- Should the solutions propose both coffee script and standart js version?
- Segment.com HOT 1
- Olark Hummingbird theme
- New Sharethis implementation and Turbolinks' incompatibility HOT 3
- owlCarousel not Loaded
- Zendesk old and new tab displayed HOT 2
- Turbolink 5 and Google DFP not working
- LiveZilla Compatability
- Using the Freshdesk/Freshdesk Widget with Turbolinks HOT 4
- SaleForce Widget with turbolinks
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from turbolinks-compatibility.