portfolio.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. ( function( $ ) {
  2. /*
  3. * Resize portfolio-wrapper for full width on small screens.
  4. */
  5. function calc() {
  6. $( '.portfolio-wrapper' ).each( function() {
  7. if( $( window ).width() < 768 ) {
  8. $( this ).css( 'width', '100%' ).css( 'width', '+=40px' );
  9. if ( $( 'body' ).hasClass( 'rtl' ) ) {
  10. $( this ).css( 'margin-right', '-20px' );
  11. } else {
  12. $( this ).css( 'margin-left', '-20px' );
  13. }
  14. } else if( $( window ).width() < 960 ) {
  15. $( this ).css( 'width', '100%' ).css( 'width', '+=120px' );
  16. if ( $( 'body' ).hasClass( 'rtl' ) ) {
  17. $( this ).css( 'margin-right', '-60px' );
  18. } else {
  19. $( this ).css( 'margin-left', '-60px' );
  20. }
  21. } else {
  22. $( this ).css( {
  23. 'width': '',
  24. 'margin-right': '',
  25. 'margin-left': ''
  26. } );
  27. }
  28. } );
  29. }
  30. $( window ).load( function() {
  31. /*
  32. * Wrap portfolio-featured-image in a div.
  33. */
  34. $( '.portfolio-featured-image' ).each( function() {
  35. $( this ).wrap( '<div class="portfolio-thumbnail" />' );
  36. } );
  37. calc();
  38. } );
  39. $( document ).ready( function() {
  40. var portfolio_wrapper = $( '.portfolio-wrapper, .jetpack-portfolio-shortcode' );
  41. portfolio_wrapper.imagesLoaded( function() {
  42. if ( $( 'body' ).hasClass( 'rtl' ) ) {
  43. portfolio_wrapper.masonry( {
  44. columnWidth: 1,
  45. itemSelector: '.portfolio-entry',
  46. transitionDuration: 0,
  47. isOriginLeft: false
  48. } );
  49. } else {
  50. portfolio_wrapper.masonry( {
  51. columnWidth: 1,
  52. itemSelector: '.portfolio-entry',
  53. transitionDuration: 0
  54. } );
  55. }
  56. // Show the blocks
  57. $( '.portfolio-entry' ).animate( {
  58. 'opacity' : 1
  59. }, 250 );
  60. } );
  61. $( window ).resize( function () {
  62. // Force layout correction after 1500 milliseconds
  63. setTimeout( function () {
  64. calc();
  65. portfolio_wrapper.masonry();
  66. }, 1500 );
  67. } );
  68. // Layout posts that arrive via infinite scroll
  69. $( document.body ).on( 'post-load', function () {
  70. var new_items = $( '.infinite-wrap .portfolio-entry' );
  71. portfolio_wrapper.append( new_items );
  72. portfolio_wrapper.masonry( 'appended', new_items );
  73. // Force layout correction after 1500 milliseconds
  74. setTimeout( function () {
  75. portfolio_wrapper.masonry();
  76. // Show the blocks
  77. $( '.portfolio-entry' ).animate( {
  78. 'opacity' : 1
  79. }, 250 );
  80. }, 1500 );
  81. } );
  82. } );
  83. } )( jQuery );