miromannino / Justified-Gallery

Javascript library to help creating high quality justified galleries of images. Used by thousands of websites as well as the photography community 500px.
http://miromannino.github.io/Justified-Gallery/
MIT License
1.69k stars 299 forks source link

One row and lastRow 'hide' #217

Open benoitongit opened 7 years ago

benoitongit commented 7 years ago

Hi,

Just wondering if there is a way to show the lastRow if there is only one row? Sometime I only have couple images, they fit in one row but they don't show.

Thanks! Benoit

biziclop commented 7 years ago

some idea from the source code:

$gallery.justifiedGallery().on('jg.complete jg.resize', function(e){
  controller = this.data('jg.controller');
  if( controller.rows === 1 ){
    this.justifiedGallery({ lastRow:'nojustify' });
  }
});
Elbatron commented 6 years ago

Hi there,

I'm using @biziclop's code with controller.rows === 0 and it kind of works but the only row is fading in so painfully slow my mac sounds like it's going to take off from the desk... Could you please point out the conflicting part?

Thank you.

Update: Besides the resource hog it seems that captions don't work.

biziclop commented 6 years ago

… did you say Mac?

Apple 1 Infinite Loop Cupertino, CA 95014

That's exactly what I made! Let's fix it:

$gallery.justifiedGallery().on('jg.complete jg.resize', function(e){
  controller = this.data('jg.controller');
  if( controller.rows === 1 && controller.lastRow !== 'nojustify' ){
    this.justifiedGallery({ lastRow:'nojustify' });
  }
});
Elbatron commented 6 years ago

Thanks. Where should I use the snippet? I tried using it in the jQuery plugin section and getting Maximum call stack size exceeded error in console; calling it the from a separate JS file (after justifedGallery.js) gives a $gallery not defined error.

biziclop commented 6 years ago

Mmmkay.

Go to here: http://miromannino.github.io/Justified-Gallery/options-and-events/

Maybe resize window, fiddle with options

Open your browser's Console and paste this:

var $gallery = $('#endless-gallery, #liveDemo');
$gallery.justifiedGallery();
var controller = $gallery.data('jg.controller');
var wantedLastRowValue = 'justify'; // or 'nojustify'

function checkIfSingleRowIsJustified(){
  if(
    // controller.rows === 1 && // uncomment this
     controller.settings.lastRow !== wantedLastRowValue
   ){
    $gallery.justifiedGallery({ lastRow: wantedLastRowValue });
  }
}

$gallery.justifiedGallery().on('jg.complete jg.resize', checkIfSingleRowIsJustified );
checkIfSingleRowIsJustified();
dscafati commented 4 years ago

For those who still have this problem, this is working for me as of today:

var $gallery = $('yourCssSelector');
$gallery.justifiedGallery({ ...yourOptions... }).on('jg.complete jg.resize', function(e){
    var $this = jQuery(this);
    var controller = $this.data('jg.controller');
    if( controller.rows === 0){
        $this.justifiedGallery({ lastRow: 'justify' });
    }else{
         $this.justifiedGallery({ lastRow: 'hide' });
     }
 });