1

I successfully set up Photoswipe and also Justified Gallery in my Rails project. Both of them work very nicely alone but I have trouble making them work together.

In my current (default) setup Photoswipe expects a tag hierarchy as follows:

<figure>
  <a href="...>
    <img src=".../>
  </a>

Justified Gallery is configured by default to recognize a container with any number of <a> tags with a nested <img> tag within like this:

<div id="mygallery" >
    <a href="...>
        <img src=".../>
    </a>
    <a href="...>
        <img src=".../>
    </a>
    <!-- other images... -->
</div>

So I would need to have Justified Gallery recognizing that <figure> tag. In their documentation it says you just have to add the following option:

selector: 'figure, div:not(.spinner)'

This part seems to work fine but it is also mentioned that it is necessary to extend the CSS rules and this is where I'm stuck. I would expect that prepending all or some > a selectors with a > figure selector should do the job but no. These are the rules that come with Justified Gallery:

.justified-gallery {
  width: 100%;
  position: relative;
  overflow: hidden;
}
.justified-gallery > a,
.justified-gallery > div {
  position: absolute;
  display: inline-block;
  overflow: hidden;
  opacity: 0;
  filter: alpha(opacity=0);
  /* IE8 or Earlier */
}
.justified-gallery > a > img,
.justified-gallery > div > img,
.justified-gallery > a > a > img,
.justified-gallery > div > a > img {
  position: absolute;
  top: 50%;
  left: 50%;
  margin: 0;
  padding: 0;
  border: none;
}
.justified-gallery > a > .caption,
.justified-gallery > div > .caption {
  display: none;
  position: absolute;
  bottom: 0;
  padding: 5px;
  background-color: #000000;
  left: 0;
  right: 0;
  margin: 0;
  color: white;
  font-size: 12px;
  font-weight: 300;
  font-family: sans-serif;
}
.justified-gallery > a > .caption.caption-visible,
.justified-gallery > div > .caption.caption-visible {
  display: initial;
  opacity: 0.7;
  filter: "alpha(opacity=70)";
  /* IE8 or Earlier */
  -webkit-animation: justified-gallery-show-caption-animation 500ms 0 ease;
  -moz-animation: justified-gallery-show-caption-animation 500ms 0 ease;
  -ms-animation: justified-gallery-show-caption-animation 500ms 0 ease;
}
.justified-gallery > .entry-visible {
  opacity: 1.0;
  filter: alpha(opacity=100);
  /* IE8 or Earlier */
  -webkit-animation: justified-gallery-show-entry-animation 500ms 0 ease;
  -moz-animation: justified-gallery-show-entry-animation 500ms 0 ease;
  -ms-animation: justified-gallery-show-entry-animation 500ms 0 ease;
}
.justified-gallery > .jg-filtered {
  display: none;
}
.justified-gallery > .spinner {
  position: absolute;
  bottom: 0;
  margin-left: -24px;
  padding: 10px 0 10px 0;
  left: 50%;
  opacity: initial;
  filter: initial;
  overflow: initial;
}
.justified-gallery > .spinner > span {
  display: inline-block;
  opacity: 0;
  filter: alpha(opacity=0);
  /* IE8 or Earlier */
  width: 8px;
  height: 8px;
  margin: 0 4px 0 4px;
  background-color: #000;
  border-top-left-radius: 6px;
  border-top-right-radius: 6px;
  border-bottom-right-radius: 6px;
  border-bottom-left-radius: 6px;
}

I have been playing around with this for quite a while but I can't make this work. Also I haven't been able to find a good example on the net.

Anyone has done this before or knows how to solve it?

loxosceles
  • 347
  • 5
  • 21

2 Answers2

0

I managed to fix this exact problem by using:

selector: 'a, figure:not(.spinner)'

in the options and by replacing all the div selectors in the css with figure. So

.justified-gallery > div > img,

Would become:

.justified-gallery > figure > img,
duvigneau
  • 201
  • 1
  • 5
0

Using Justified Gallery v3.7.0 and PhotoSwipe v4.1.3 one only needs to replace the default selector by

'figure, > div:not(.spinner)'

Hence, for <div id="mygallery"> one gets:

$('#mygallery').justifiedGallery({
    selector: 'figure, > div:not(.spinner)'
}).on('jg.complete', function () {
    initPhotoSwipeFromDOM('#mygallery');
});
streof
  • 145
  • 3
  • 8