2020-04-07 13:03:04 +00:00
|
|
|
/**
|
|
|
|
* Theme Customizer enhancements for a better user experience.
|
|
|
|
*
|
|
|
|
* Contains handlers to make Theme Customizer preview reload changes asynchronously.
|
|
|
|
*/
|
|
|
|
|
|
|
|
( function( $ ) {
|
|
|
|
// Container width
|
|
|
|
wp.customize( 'generate_settings[container_width]', function( value ) {
|
2021-07-25 23:25:02 +00:00
|
|
|
value.bind( function() {
|
|
|
|
if ( $( '.masonry-container' )[ 0 ] ) {
|
|
|
|
jQuery( '.masonry-container' ).imagesLoaded( function() {
|
|
|
|
$container = jQuery( '.masonry-container' );
|
|
|
|
if ( jQuery( $container ).length ) {
|
|
|
|
$container.masonry( {
|
2020-04-07 13:03:04 +00:00
|
|
|
columnWidth: '.grid-sizer',
|
|
|
|
itemSelector: '.masonry-post',
|
2021-07-25 23:25:02 +00:00
|
|
|
stamp: '.page-header',
|
|
|
|
} );
|
2020-04-07 13:03:04 +00:00
|
|
|
}
|
2021-07-25 23:25:02 +00:00
|
|
|
} );
|
2020-04-07 13:03:04 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
$( 'body' ).on( 'generate_spacing_updated', function() {
|
2021-07-25 23:25:02 +00:00
|
|
|
if ( $( '.masonry-container' )[ 0 ] ) {
|
|
|
|
jQuery( '.masonry-container' ).imagesLoaded( function() {
|
|
|
|
$container = jQuery( '.masonry-container' );
|
|
|
|
if ( jQuery( $container ).length ) {
|
|
|
|
$container.masonry( {
|
2020-04-07 13:03:04 +00:00
|
|
|
columnWidth: '.grid-sizer',
|
|
|
|
itemSelector: '.masonry-post',
|
2021-07-25 23:25:02 +00:00
|
|
|
stamp: '.page-header',
|
|
|
|
} );
|
2020-04-07 13:03:04 +00:00
|
|
|
}
|
2021-07-25 23:25:02 +00:00
|
|
|
} );
|
2020-04-07 13:03:04 +00:00
|
|
|
}
|
2021-07-25 23:25:02 +00:00
|
|
|
} );
|
2020-04-07 13:03:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The first infinite scroll load in the Customizer misses article classes if they've been
|
|
|
|
* added or removed in the previous refresh.
|
|
|
|
*
|
|
|
|
* This is totally hacky, but I'm just happy I finally got it working!
|
|
|
|
*/
|
2021-07-25 23:25:02 +00:00
|
|
|
var $container = $( '.infinite-scroll-item' ).first().parent();
|
|
|
|
$container.on( 'load.infiniteScroll', function( event, response ) {
|
|
|
|
var $posts = $( response ).find( 'article' );
|
|
|
|
if ( wp.customize.value( 'generate_blog_settings[column_layout]' )() ) {
|
2020-04-07 13:03:04 +00:00
|
|
|
$posts.addClass( 'generate-columns' );
|
|
|
|
$posts.addClass( 'grid-parent' );
|
2021-07-25 23:25:02 +00:00
|
|
|
$posts.addClass( 'grid-' + wp.customize.value( 'generate_blog_settings[columns]' )() );
|
2020-04-07 13:03:04 +00:00
|
|
|
$posts.addClass( 'tablet-grid-50' );
|
|
|
|
$posts.addClass( 'mobile-grid-100' );
|
|
|
|
} else {
|
|
|
|
$posts.removeClass( 'generate-columns' );
|
|
|
|
$posts.removeClass( 'grid-parent' );
|
2021-07-25 23:25:02 +00:00
|
|
|
$posts.removeClass( 'grid-' + wp.customize.value( 'generate_blog_settings[columns]' )() );
|
2020-04-07 13:03:04 +00:00
|
|
|
$posts.removeClass( 'tablet-grid-50' );
|
|
|
|
$posts.removeClass( 'mobile-grid-100' );
|
|
|
|
}
|
|
|
|
|
2021-07-25 23:25:02 +00:00
|
|
|
if ( wp.customize.value( 'generate_blog_settings[masonry]' )() ) {
|
2020-04-07 13:03:04 +00:00
|
|
|
$posts.addClass( 'masonry-post' );
|
|
|
|
} else {
|
|
|
|
$posts.removeClass( 'masonry-post' );
|
|
|
|
}
|
|
|
|
|
2021-07-25 23:25:02 +00:00
|
|
|
if ( ! wp.customize.value( 'generate_blog_settings[post_image_padding]' )() ) {
|
2020-04-07 13:03:04 +00:00
|
|
|
$posts.addClass( 'no-featured-image-padding' );
|
|
|
|
} else {
|
|
|
|
$posts.removeClass( 'no-featured-image-padding' );
|
|
|
|
}
|
2021-07-25 23:25:02 +00:00
|
|
|
} );
|
|
|
|
}( jQuery ) );
|