kenwheeler / slick

the last carousel you'll ever need
kenwheeler.github.io/slick
MIT License
28.34k stars 5.88k forks source link

event handler loss inside slides on breakpoints #3604

Open advanced-media opened 5 years ago

advanced-media commented 5 years ago

If you have direct bound event handlers inside slides (e.g. ajax-form at product-tiles in a product-carousel) and you use responsive configuration, the event handlers are wiped away.

===================================================================

Fiddle

https://jsfiddle.net/ntjovefz/

===================================================================

Steps to reproduce the problem

use slick v1.9.0 use responsive config hit a breakpoint

===================================================================

What is the expected behaviour?

event handlers inside slides are NOT removed

===================================================================

What is observed behaviour?

event handlers inside slides are removed

===================================================================

More Details

Slick.prototype.cleanUpRows()

Maybe it's a side effect of using .empty() as long as originalSlides are attached to the DOM:

To avoid memory leaks, jQuery removes other constructs such as data and event handlers from the child elements before removing the elements themselves. http://api.jquery.com/empty/

One can use .clone(true) or .detach() to build originalSlides collection. https://stackoverflow.com/a/40369879

DrezynSoft commented 4 days ago

Try to use events. Event init and breakpoint are things you need probably.