Always trigger page:before-change on visit or replace + passing Scroll param from server to Javascript #588
Conversation
Hi @vizo, Thank you for your contributions, can you also update the tests of Turbolinks? Have a good day, |
Hi @tortuetorche, you are welcome. Now is passing. |
…th data-turbolinks-temporary attribute Prevent error when calling "change" with parent element of element with data-turbolinks-temporary attribute. Before there was duplication of elements to be changed.
Could you open separate PRs for each change and add tests please. |
I can make separate PRs, but i don't know how, sorry. But it's time to learn :) Google said that i must do new branch with each change and then request PR on each branch? Is that correct? About tests, i am also new ... but i think there should be just few new tests, so i can try. |
|
There are two more things:
|
Please open a new PR with a test case.
This is intended.
You can use the |
Ok clear. But as i know |
Why are you trying to prevent it? |
I want to prevent it if form is dirty and user clicks cancel in confirmation box ("Your changes will be lost. Continue?"). Use case:
|
In my opinion this is too much of an edge case to justify the additional complexity in Turbolinks (if we add a new event). You can probably achieve the same behavior by checking which link was clicked and/or the URL (or just showing the confirmation box all the time). |
I accept you opinion but it's sad because this data is already available, just not passed to an event. Believe me i tried a lot of workarounds before I made PR. I agree that you can do it with click events on all other links, but not all links are navigating away to other page in real application (some have just js events, also sometimes they are not links, just elements with click events, also canceled events and so on...). It becomes messy. Another problem is binding as a first event to trigger, before others (ugly workarounds to insert it as first, source: google). Also it doesn't cover if user press back button. page:before-change covers it all and it's right place to cancel or allow page changes (like it is), But my opinion is, we should really know what changes will be made in DOM, so we can decide smart (to allow or not). I guess that's why event.preventDefault() is available? But how can we decide smart just with URL (i also use multilingual URLs for SEO in my app)? From my point of view, URL information on client side is useless in real application (unless you use client side router). Correct me if i am wrong. Imagine keypress event without telling you which key was pressed. I feel the same :) Also i don't see a reason why not all Turbolinks could be very good substitute of other client side frameworks. |
At the time that If you called If you really care about this, it's easy to patch Turbolinks to do what you want: originalVisit = Turbolinks.visit
Turbolinks.visit = (url, options) ->
return if # fire new event with options.change and check if prevented
originalVisit() |
In my PR i moved I don't call it manually. I made patch before, but there you don't know all elements that will be changed (just listed). I must write logic for temp and keep and so on, so this is far from DRY. I can't use turbolinks logic out of the box. Looks like i will need to use my fork then. |
Always trigger page:before-change and provide also nodesToChange in event.data.
Passing scroll param from server to Javascript.