metafizzy / flickity

:leaves: Touch, responsive, flickable carousels
https://flickity.metafizzy.co
7.5k stars 604 forks source link

createMethods not working in v3.0.0 #1262

Open aaronstezycki opened 1 year ago

aaronstezycki commented 1 year ago

Currently, using V3 and applying some older techniques to Flickity results in some console errors. I am using the equal cells size height hack which is a "extra" on this page: https://flickity.metafizzy.co/extras.html.

The console error comes from this line:

Flickity.createMethods.push('_createResizeClass');

Obviously, this worked in version 2.3, and now doesn't on v3. Just wondering what the code is now to continue pushing custom methods to Flickity?

Test Case : Just change Flickity version to use v3 instead of v2: https://codepen.io/desandro/pen/ZXEGVq

aaronstezycki commented 1 year ago

Ah, have just seen #1210, not sure if you can pin that to the top :)

Hopefully my issue is of future help to you with regards to updating documentation and examples. :)

desandro commented 1 year ago

Ah, sorry about that. I'm going to add a fix to add backwards compatibility for that createMethods API.

For future reference. here is old v2 code...

// v2
Flickity.prototype._createResizeClass = function() {
  this.element.classList.add('flickity-resize');
};

Flickity.createMethods.push('_createResizeClass');

In Flickity, v3, you attach the method to Flickity.create instead. No push needed.

// v3
Flickity.create._createResizeClass = function() {
  this.element.classList.add('flickity-resize');
};