Giter Site home page Giter Site logo

Comments (8)

davydotcom avatar davydotcom commented on July 17, 2024

I Know inline js shouldn't even be in there but we should support inline js execution if we can.

from turbolinks-classic.

davydotcom avatar davydotcom commented on July 17, 2024

No js in your response body will operate at all.

This requires keeping everything out of the view including an init function call.

This is due to the use of DOMParser. it appears DOMParser will not evaluate javascript. document.write, however, will evaluate js to a point.

from turbolinks-classic.

davydotcom avatar davydotcom commented on July 17, 2024

Heck, I might jus consider this a feature ! :)

from turbolinks-classic.

danbt79 avatar danbt79 commented on July 17, 2024

My inner arsehole tends to agree with you! This should be given thought though - is Rails' stance to simply not recommend doing this, or to prevent it working at all?

from turbolinks-classic.

davydotcom avatar davydotcom commented on July 17, 2024

Right its also a potential issue that inline js using document references will have the wrong doc reference until after the content is replaced into the main document. A potential option is to scan for script tags after replace and evaluate them.

On Oct 1, 2012, at 12:21 PM, Daniel Beattie [email protected] wrote:

My inner arsehole tends to agree with you! This be given thought though - is Rails' stance to simply not recommend doing this, or to prevent it working at all?


Reply to this email directly or view it on GitHub.

from turbolinks-classic.

danbt79 avatar danbt79 commented on July 17, 2024

That sounds potentially brittle to me - I'd leave that up to caveat empor and making the developer aware of how this works. If you're using .js in this way and relying on document references like that, there should be some pain! I think we should just make sure .js can actually execute, and leave implementation details up to the .js author, rather than hacking a solution upstream on this library.

from turbolinks-classic.

davydotcom avatar davydotcom commented on July 17, 2024

I got it to work by modifying changePage to get all script elements. I have not made a pull request yet, as i know @dhh is doing a major refactor. But this may be useful... document also gets the proper reference because they are not evaluated until after the fact.

changePage = (title, body) ->
  document.title = title
  document.documentElement.replaceChild body, document.body
  scripts = document.body.getElementsByTagName 'script'
  eval(script.innerHTML) for script in scripts
  currentState = historyState
  triggerEvent 'page:change'

from turbolinks-classic.

davydotcom avatar davydotcom commented on July 17, 2024

Fixed

from turbolinks-classic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.