Search code examples
javascriptjqueryhtmlruby-on-railsturbolinks

Fotorama jQuery Gallery with Rails 4.2.0 (Turbolinks issue)


I've got the Fotorama jQuery Slider working; however, it doesn't work with Turbolinks (and I'd rather not disable Turbolinks).

How can I make this jQuery slider load when the page that it's on is loaded through Turbolinks?

In application.js I've got the following code for dealing with Turbolinks:

var ready;
ready = function() {
  // JavaScript to be triggered by Turbolinks/page:load event
};

$(document).ready(ready);
$(document).on('page:load', ready);

Can I add a function to this section of JavaScript to load the Fotorama slider?

Any ideas/feedback appreciated.

Thanks in advance.


Solution

  • Yes.

    I have never used this Fotorama slider but looking at its docs i think you can do this

    $(document).on('ready page:load',function(){
       $('.fotorama').fotorama();
    });