nnattawat / flip

A lightweight jQuery plugin to make 3D card flipping animation
Other
627 stars 312 forks source link

Not working after ajax refresh #40

Closed Zmove closed 9 years ago

Zmove commented 9 years ago

Hello,

The script stop working when you call it on ajaxComplete jquery event.

Here is my code

$(document).bind('ready ajaxComplete', function() { 
    $('.blog-post').flip();
});

Here is the error that is displayed when I click on my button that load more blog posts with ajax

Uncaught TypeError: Cannot read property 'axis' of undefined

Any ideas about that error ? My call seems very simple, and it works well unless I click on my load more button.

Zmove commented 9 years ago

Temporary fix is to comment the code below line 209 - 215 of jquery.flip.js

      if (options.axis !== undefined || options.reverse !== undefined){
        changeSettings.call(this,options,function(){
          $dom.trigger('flip:change');
          if (callback !== undefined){
            callback.call(this);
          }
        });
      }

I do not see drawback to this (probably because I have a very simple usage of the plugin).

JemarJones commented 9 years ago

What's going on here is that the element has already been instantiated and its being called as if to change some settings but no settings have been provided. The error message is a bit confusing though. What was your expected outcome? Perhaps you meant .flip("toggle");?

JemarJones commented 9 years ago

Taking a guess at how your application is structured here, it seems you've got a bunch of blog posts elements that you instantiate at some earlier point, you load some new ones, and then you try the above piece of code to instantiate them all. The problem with that is that you're trying to instantiate the old ones again, and thus you get this error. This actually shouldn't stop all the new elements from being instantiated and should have no effect on the old ones, so i would imagine everything actually works as you need it to. But it's messy and you should probably make sure that you only try to instantiate newly created elements.

There is an issue here of flip not giving a clear enough error message in this case though, so i'll add a clear error message in the next release.

Download commented 9 years ago

Should be fixed in release v1.0.16.