2020-04-07 13:03:04 +00:00
|
|
|
jQuery( document ).ready( function( $ ) {
|
|
|
|
var $masonry_container = $( '.masonry-container' );
|
|
|
|
var msnry = false;
|
|
|
|
|
|
|
|
if ( $masonry_container.length ) {
|
2020-08-13 14:53:39 +00:00
|
|
|
var $grid = $masonry_container.masonry( generateBlog.masonryInit );
|
2020-04-07 13:03:04 +00:00
|
|
|
|
|
|
|
msnry = $grid.data( 'masonry' );
|
|
|
|
|
|
|
|
$grid.imagesLoaded( function() {
|
|
|
|
$grid.masonry( 'layout' );
|
|
|
|
$grid.removeClass( 'are-images-unloaded' );
|
|
|
|
$( '.load-more' ).removeClass( 'are-images-unloaded' );
|
|
|
|
$( '#nav-below' ).css( 'opacity', '1' );
|
|
|
|
$grid.masonry( 'option', { itemSelector: '.masonry-post' });
|
|
|
|
var $items = $grid.find( '.masonry-post' );
|
|
|
|
$grid.masonry( 'appended', $items );
|
|
|
|
} );
|
|
|
|
|
|
|
|
$( '#nav-below' ).insertAfter( '.masonry-container' );
|
|
|
|
|
|
|
|
$( window ).on( "orientationchange", function( event ) {
|
|
|
|
$grid.masonry( 'layout' );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $( '.infinite-scroll' ).length && $( '.nav-links .next' ).length ) {
|
|
|
|
var $container = $( '#main article' ).first().parent();
|
|
|
|
var $button = $( '.load-more a' );
|
|
|
|
var svgIcon = '';
|
|
|
|
|
2020-08-13 14:53:39 +00:00
|
|
|
if ( generateBlog.icon ) {
|
|
|
|
svgIcon = generateBlog.icon;
|
2020-04-07 13:03:04 +00:00
|
|
|
}
|
|
|
|
|
2020-08-13 14:53:39 +00:00
|
|
|
var infiniteScrollInit = generateBlog.infiniteScrollInit;
|
|
|
|
|
|
|
|
infiniteScrollInit.outlayer = msnry;
|
|
|
|
|
|
|
|
$container.infiniteScroll( infiniteScrollInit );
|
2020-04-07 13:03:04 +00:00
|
|
|
|
|
|
|
$button.on( 'click', function( e ) {
|
2020-08-13 14:53:39 +00:00
|
|
|
document.activeElement.blur();
|
|
|
|
$( this ).html( svgIcon + generateBlog.loading ).addClass( 'loading' );
|
2020-04-07 13:03:04 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
$container.on( 'append.infiniteScroll', function( event, response, path, items ) {
|
|
|
|
if ( ! $( '.generate-columns-container' ).length ) {
|
|
|
|
$container.append( $button.parent() );
|
|
|
|
}
|
|
|
|
|
2020-08-13 14:53:39 +00:00
|
|
|
// Fix srcset images not loading in Safari.
|
|
|
|
// img.outerHTML = img.outerHTML isn't minified properly, so we need the extra var.
|
2020-04-07 13:03:04 +00:00
|
|
|
$( items ).find( 'img' ).each( function( index, img ) {
|
2020-08-13 14:53:39 +00:00
|
|
|
var imgOuterHTML = img.outerHTML;
|
|
|
|
img.outerHTML = imgOuterHTML;
|
2020-04-07 13:03:04 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
if ( $grid ) {
|
|
|
|
$grid.imagesLoaded( function() {
|
|
|
|
$grid.masonry( 'layout' );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2020-08-13 14:53:39 +00:00
|
|
|
$button.html( svgIcon + generateBlog.more ).removeClass( 'loading' );
|
2020-04-07 13:03:04 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
$container.on( 'last.infiniteScroll', function() {
|
|
|
|
$( '.load-more' ).hide();
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|