1

So I am using this rails gem: https://github.com/kyparn/fancybox2-rails

  • Using BackboneJS for frontend and instantiating fancybox in the View

Fancybox works perfectly locally but on staging and production, images are opened in a new window. I checked chrome console and made sure that fancybox was present, and it is.

Not entirely sure how to resolve this / go about debugging this.

This is how I have images setup:

   <a class="fancybox-image" data-fancybox="image" href="image_url">
   <img src="image_url" data-js="activate-img-modal">
   </a>

I am instantiating fancybox setup in the Backbone View where each image is in.

  setupFancyBox: function() {
     var options = {
       helpers: {
         overlay: {
           locked: false
         }
        }
      };
      this.$("[data-fancybox='image']").fancybox(options);
  }
  • This function is called in the View's render method.
algorhythm
  • 8,530
  • 3
  • 35
  • 47
Jayem
  • 215
  • 2
  • 9
  • most likely another js error (hoisting, jQuery version conflicts, etc.) is preventing fancybox from working ... but without any code or jsfiddle is just a guess – JFK Oct 28 '14 at 18:40
  • Console brings up no JS errors. – Jayem Oct 28 '14 at 19:27
  • I am not very familiar with BackboneJS, but what mean "this" in last line? Maybe it should by without this keyword, just $("[data-fancybox='image']").fancybox(options); – dpa Oct 28 '14 at 20:56

2 Answers2

2

So locally there were extensions on my images (.jpg/.png) like so:

 <a class="fancybox-image" data-fancybox="image" href="path/to/image1.png">
   <img src="path/to/image1.png" data-js="activate-img-modal">
 </a>

But on production/live there were no image extensions:

 <a class="fancybox-image" data-fancybox="image" href="path/to/image1.">
   <img src="path/to/image1." data-js="activate-img-modal">
 </a>

Missing the extension, caused fancybox not to activate for me.

A Fix would be taken from here (Fancybox urls without .jpg opens not in box):

  $(".fancybox").fancybox({
    type: 'image'
  });
Community
  • 1
  • 1
Jayem
  • 215
  • 2
  • 9
0

Check javascript console, if appears some javascript error it can prevent from further javascript code execution. Next step try initialize fancybox in console, simply run this code (of course use your own selector)

$("a.fancybox").fancybox();
dpa
  • 427
  • 4
  • 16