Comments (6)
Would this work?
$(document).bind 'page:load', ->
$.getScript $('.stripe-button').attr 'src'
I can't answer your question about whether or not Turbolinks should handle external scripts, but if so, this could possibly be a way to handle it:
executeScriptTags = ->
for script in document.body.getElementsByTagName 'script' when script.type in ['', 'text/javascript']
if script.src? and not script.getAttribute('data-turbolinks-evaluated')?
copy = document.createElement 'script'
copy.setAttribute attr.name, attr.value for attr in script.attributes
copy.setAttribute 'data-turbolinks-evaluated', ''
parent = script.parentNode
parent.removeChild script
parent.insertBefore copy, parent.childNodes[0]
else
eval(script.innerHTML)
from turbolinks-classic.
Thanks for your help Nick! I forked Turbolinks and tried your second solution and it almost worked. I display three buttons on the page, one for each plan. That's what it looks like on a fresh page load and that's what it looks like with Turbolinks when I apply your patch.
I read the JS source code of the Stripe Button and what the script does basically is take all the script elements with the class "stripe-button" and insert the button after the last one. This works on a fresh load since the script is not delayed and everything after the script tag has not yet been loaded. This won't work with Turbolinks though since the page has been fully loaded when the scripts are executed.
I guess there is not much we can do about that. For now, I just disabled Turbolinks for that specific page but I will contact Stripe support (they have great support!) to see if they could think of another way of doing this.
I still think your patch would be helpful. Maybe you could suggest a pull request?
from turbolinks-classic.
I didn't think to test multiple buttons on the same page, but now that I have, I see what you're seeing. It is certainly a bit unorthodox the way the Stripe button JS works, and I completely agree with your assessment on how to proceed from here. Since Stripe's Button feature is still in beta (according to their documentation), this is something I would think their support team would be willing to consider fixing.
Thanks for your opinion on my patch. I'm going to submit a pull request for it in a few minutes.
from turbolinks-classic.
I've fixed this on Stripe's side. Should be deployed soonish.
from turbolinks-classic.
Hello,
I'm getting the error with turbolinks (Uncaught error: StripeCheckout is not defined). Removing turbolinks fixes the issue.
Is there something I'm missing ? Can't I get turbolinks & stripe ?
from turbolinks-classic.
Getting the same error with turbolinks and checkout.js "Uncaught ReferenceError: StripeCheckout is not defined"
from turbolinks-classic.
Related Issues (20)
- Page does not always scroll to the top when DOM loads too fast
- SVG anchors not working with turbolinks
- Turbolinks.visit, partial replacement & relative urls (& IE11)
- Not correctly inferring protocol with SSL, unless force_ssl is set HOT 2
- Redirect and reload full page HOT 1
- JavaScript part of turbolinks on npm HOT 11
- Enable Turbolinks on a-tags after adding content over AJAX HOT 1
- File type blacklist instead of whitelist
- Scroll position of data-turbolinks-permanent elements lost on navigation. HOT 3
- Webpage without title, after turbolink has title of undefined HOT 1
- Problems with JS HOT 1
- Rails 5 deprecations
- Would you please tell me how to add your library or whether it's necessary to add this library?
- Sorry for duplicate
- Progress bar causing capybara tests to fail
- Documentation does not explain how to install current turbolinks-classic version HOT 1
- temporary inside permanent
- Clicking browser back button from an error page to a non-error page, retains the styles of the error page
- Turbolinks.enableProgressBar() returns undefined
- How to binding "page:load" cache-preview
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-classic.