Comments (11)
How can I tell if it's working or not? What behavior is Turbolinks breaking?
from turbolinks-compatibility.
Turbolinks is breaking a javascript modal from loading.
Here's the expected behaviour (click the button on this page): http://jsfiddle.net/loganvolkers/xHxhf/
If a page is loaded by Turbolinks, then the button will not show the modal.
To test this, try loading this HTML via turbolinks.
<div class="container">
<div class="page-header">
<h1>Turbolinks demo</h1>
</div>
<section>
<p>
<div class="btn btn-primary squatchpop">This button should open a modal</div>
</p>
</section>
</div>
<script type='text/javascript'>//<![CDATA[
var _sqh = _sqh || [];
// Push user details for the user who is logged in to your SaaS app
_sqh.push(['init', {
tenant_alias: 'demo',
account_id: 'abcd',
user_id: '1234',
email: '[email protected]',
first_name: 'Bob',
last_name: 'Testerson'
}]);
// Autofill connects referral coupons to your payment form
_sqh.push(['autofill', '#my_coupon']);
// Include squatch.js
(function(){function l(){var s=document.createElement("script");s.type="text/javascript";s.async=true;s.src=location.protocol+"//d2rcp9ak152ke1.cloudfront.net/assets/javascripts/squatch.min.js";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(s,t)}if(window.attachEvent){window.attachEvent("onload",l)}else{window.addEventListener("load",l,false)}})();
//]]>
</script>
I believe this has something to do with our onload behaviour being dependant on document.ready, as per your docs, but just wanted to confirm.
Feature request -- would be cool if you had a jsFiddle-style testbed for testing arbitrary html/code snippets to see if they work with Turbolinks.
from turbolinks-compatibility.
Well it's far from ideal, but this seems to work:
<script data-turbolinks-eval="false">
// Include squatch.js
(function(){
function l(){
window._sqh = window._sqh || [];
// Push user details for the user who is logged in to your SaaS app
window._sqh.push(['init', {
tenant_alias: 'demo',
account_id: 'abcd',
user_id: '1234',
email: '[email protected]',
first_name: 'Bob',
last_name: 'Testerson'
}]);
// Autofill connects referral coupons to your payment form
window._sqh.push(['autofill', '#my_coupon']);
var s = document.createElement("script");
s.type = "text/javascript";
s.async=true;
s.src = location.protocol+"//d2rcp9ak152ke1.cloudfront.net/assets/javascripts/squatch.min.js";
var t = document.getElementsByTagName("script")[0];
t.parentNode.insertBefore(s,t)
}
if (window.attachEvent){
window.attachEvent("onload",l);
document.attachEvent('page:load',l);
}else{
window.addEventListener("load",l,false);
document.addEventListener('page:load',l,false)
}
})();
</script>
I don't think it'd be possible to implement your feature request, at least not in any meaningful way.
from turbolinks-compatibility.
Thanks for the workaround, Nick.
Do you have any suggestions for my developers to make our library more Turbolinks friendly? (besides what's listed here: http://reed.github.io/turbolinks-compatibility/)
from turbolinks-compatibility.
Hmm. Maybe separate loading from initialization, adding a function to the public api that will re-initialize a page without having to reload all of the scripts. Then anybody using turbolinks could just bind that method to the page:load event.
from turbolinks-compatibility.
Hey. I'm the "customer" Logan mentioned. Sadly, that solution doesn't work. The issue is that the init method both configures and adds the popup div to the body. @reed's suggestion is correct. There needs to be a separation of the configuration and rendering phase. When turbolinks is enabled, the configuration should only be loaded once but there needs to be a page:load event that injects the popup div into the page each time the page is loaded.
The workaround above wires up the page:load event but the issue is that when clicking on another link on the page, the injected div is no longer present so the squatch.js event fails as the div is not found.
Honestly, I'm simply buried right now or I'd take a stab at it.
from turbolinks-compatibility.
Are you sure it doesn't work? You're right about the issue, but it started working for me when I moved the _sqh configuration inside the l
function (and added data-turbolinks-eval="false"
to the script tag).
from turbolinks-compatibility.
I didn't noticed that you moved everything inside 1
. Thanks for the heads up. The popup is working but I'm now getting the following security warnings in the console:
XMLHttpRequest cannot load http://api.segment.io/v1/t. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://app.referralsaasquatch.com' is therefore not allowed access.
Any ideas?
from turbolinks-compatibility.
@ryanwood that's interesting. It would seem that Segment.io, a tool that we use inside of our widget, may have an error in the XDM headers. Any chance that you can push your update to staging so I can test the new code with the account you sent me?
from turbolinks-compatibility.
@loganvolkers Looks like it's working now. It may have been the location I was connecting from (a conference) or could have been an intermittent issue with Segment.io. Thanks to both of you.
from turbolinks-compatibility.
Glad I could help!
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
- Happyfox Chat loading problem after language change 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.