Skip to content
This repository was archived by the owner on Jul 28, 2018. It is now read-only.

Conversation

@Thibaut
Copy link
Collaborator

@Thibaut Thibaut commented May 17, 2015

Problem:

  • $(document).on 'page:update', ->
      $(document.body).on('click', '.selector', fn)
      $(document.body).find('.selector').click(fn2)

    … attaches duplicate event handlers on every partial replacement (since the body didn't change).

    Same with page:load.

  • Turbolinks.replace() doesn't trigger the page:load event, even though it's inserting new elements into the DOM (which people may want to transform the same way they do on normal page loads).

What this PR does:

  • Attach affected nodes to the page:before-unload, page:change and page:load events.

    The above snippet could be rewritten as follow:

    $(document).on 'page:update', (event) ->
      $(document.body).on('click', '.selector', fn) if event.data[0] == document.body
      $(event.data).find('.selector').click(fn2)
  • Fire page:load in Turbolinks.replace() (passing the loaded nodes).

Docs soon.

cc @dhh

@Thibaut
Copy link
Collaborator Author

Thibaut commented May 23, 2015

cc @rafaelfranca, would be great if you could take a quick look at this one as well.

@rafaelfranca
Copy link
Contributor

Patch looks good. Are you going to document it on this same PR?

Thibaut added a commit that referenced this pull request May 26, 2015
Attach affected nodes to lifecycle events
@Thibaut Thibaut merged commit 0fd9410 into turbolinks:master May 26, 2015
@Thibaut Thibaut deleted the partial-events branch May 26, 2015 02:51
@Thibaut
Copy link
Collaborator Author

Thibaut commented May 26, 2015

Thanks @rafaelfranca. I'll revamp the events docs this week-end in a separate PR.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants