scripts.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*!
  2. * Script for Rebalance
  3. */
  4. ( function( $ ) {
  5. // Determine if our site is RTL (Right-To-Left)
  6. var ltr = true;
  7. if ( 1 == Rebalance.is_rtl ) {
  8. ltr = false;
  9. }
  10. // Code inside here fires when the DOM is loaded.
  11. $( document ).ready( function() {
  12. /**
  13. * Set variables
  14. */
  15. var $container = $( '#infinite-wrap' ),
  16. $wrapper = $( '.js body' );
  17. /**
  18. * Append HTML to masonry wrapper for responsive sizing
  19. * - see: http://masonry.desandro.com/options.html#columnwidth
  20. */
  21. $container.append(
  22. '<div class="grid-sizer"></div>\
  23. <div class="grid-item"></div>\
  24. <div class="grid-item grid-item--width2"></div>'
  25. );
  26. /**
  27. * Move Jetpack sharing and post flair into the entry-footer
  28. */
  29. $( '.entry-footer' ).append( $( '#jp-post-flair' ).detach() );
  30. /*
  31. * Fade in page
  32. * - only if js is enabled
  33. */
  34. $wrapper.animate({
  35. opacity: 1,
  36. }, 30);
  37. /**
  38. * Initiate Masonry
  39. */
  40. $( function() {
  41. $container.imagesLoaded( function() {
  42. $container.masonry({
  43. columnWidth: '.grid-sizer',
  44. gutter: 0,
  45. percentPosition: true,
  46. itemSelector: '.card',
  47. transitionDuration: 0,
  48. isFitWidth: false,
  49. isOriginLeft: ltr
  50. });
  51. });
  52. // Fade blocks in after images are ready (prevents jumping and re-rendering)
  53. $container.find( '.card' ).animate( {
  54. 'opacity' : 1
  55. } );
  56. });
  57. });
  58. // Handle new items appended by infinite scroll
  59. $( document ).on( 'post-load', function() {
  60. /**
  61. * Set variables
  62. */
  63. var $container = $( '#infinite-wrap' );
  64. $container.imagesLoaded( function() {
  65. $container.masonry( 'reloadItems').masonry( 'layout' );
  66. // Fade in cards
  67. $container.find( '.card' ).animate( {
  68. 'opacity' : 1
  69. });
  70. });
  71. });
  72. } )( jQuery );