ruby-on-railscoffeescriptphotoswipe

PhotoSwipe, Rails, Coffee doesn't work at all


Can't understand why PhotoSwipe doesn't show anything when I'm trying to add it into Rails project

  1. Used this gem: https://github.com/skakri/photoswipe-rails
  2. Step by step reproduced manual: https://photoswipe.com/documentation/getting-started.html#init-add-pswp-to-dom
  3. Wrote 'click' handler But it shows nothing

Code I wrote:

<body>
  <!-- some Rails and other stuff -->
  <%= render 'shared/photoswipe' %> 
</body>

shared/_photoswipe.html.erb contains full copy of div class="pswp" from 2) Invisible div successfully added at the end of page

Added some coffee code for PhotoSwipe init on click handler

$ ->
  $PhotoContainer = $('#MainPhoto')
  $PhotoContainer.click ->
    $pswpElement = document.querySelectorAll('.pswp')[0]
    $items = []
    $('.photo-item').each ->
      $Img = $(@)
      $items.push( { src: getUrlFromImg($Img).bigImgUrl, w: 1000, h: 1000 } )

    $options = {
      history: false,
      focus: false,
      index: 0
    }
    $gallery = new PhotoSwipe( $pswpElement, PhotoSwipeUI_Default, $items, $options)
    $gallery.init()

When I click on #MainPhoto container event fired, $items array correctly fills by image urls and sizes and calls PhotoSwipe init() function, but nothing shows on screen


Solution

  • gem is improperly written should add

    @import "photoswipe/index";
    @import "photoswipe/photoswipe";
    @import "photoswipe/default-skin/default-skin";
    

    into application.scss