/** * custom-scripts.js * * Custom scripts for this theme. */ ( function( $ ) { var $body; // Tip39 - Overhanging Images. Adds a .size-big class to a large image and caption that has width >= 900px and was inserted as size-full. function bigImageClass() { if ( $body.hasClass( 'page' ) || $body.hasClass( 'search' ) || $body.hasClass( 'single-attachment' ) || $body.hasClass( 'error404' ) ) { return; } var entryContent = $( '.entry-content' ); entryContent.find( 'img.size-full' ).each( function() { var img = $( this ), caption = img.closest( 'figure' ), newImg = new Image(); newImg.src = img.attr( 'src' ); $( newImg ).load( function() { var imgWidth = newImg.width; if ( 900 <= imgWidth ) { img.addClass( 'size-big' ); } if ( caption.hasClass( 'wp-caption' ) && 900 <= imgWidth ) { caption.addClass( 'caption-big' ); caption.removeAttr( 'style' ); } } ); } ); } $( document ).ready( function() { $body = $( document.body ); bigImageClass(); } ); } )( jQuery );