mathiasbynens / jquery-details

World’s first <details>/<summary> polyfill™
https://mths.be/details
GNU General Public License v2.0
121 stars 34 forks source link

Make sure click handler on summary element is only bound once. #14

Open tobiashm opened 11 years ago

tobiashm commented 11 years ago

If you run something like $('details').details(); twice on a page, it will bind the click handler twice, causing the details element to both open and close when clicked, thus returning to its pre-click state. I.e. it looks like the nothing has happened. Added namespace to click event to avoid collision with other event handlers.

Startouf commented 8 years ago

Thank you savior ! I'm using rails and with turbolinks this was causing a lot of problems.

tchalvak commented 8 years ago

Why would you run $('details').details() twice, though? What situation other than improper script inclusion would cause such a situation?

Oh, wait, this PR is also from 2013.

Startouf commented 8 years ago

Turbolinks is a framework that load the next pages in AJAX and replaces the DOM contents accordingly. Because of that, the DOM javascript isn't reloaded completely, and I need to run this function again to make sure the <details> of the next page are tweaked correctly. $(document).ready doesn't work and must be substituted by $(document).on('ready turbolinks:load').

tchalvak commented 8 years ago

Fair enough.

tobiashm commented 8 years ago

Basically any situation where new content might be injected into the page, which could include <details> tags, especially if you don't have full control over exactly which part of the page is updated, and with what.

tchalvak commented 8 years ago

Yeah, loading of page subsections, makes sense.

On May 10, 2016, at 8:14 AM, Tobias H. Michaelsen notifications@github.com wrote:

Basically any situation where new content might be injected into the page, which could include

tags, especially if you don't have full control over exactly which part of the page is updated, and with what.

— You are receiving this because you commented. Reply to this email directly or view it on GitHub