scratchpad.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**
  2. *
  3. * Custom JavaScript for the Scratchpad theme.
  4. *
  5. */
  6. ( function( $ ) {
  7. /**
  8. * Masonry for footer widgets
  9. */
  10. function widgetMasonry() {
  11. // Determine text direction
  12. var ltr = true;
  13. if ( $('html' ).attr( 'dir' ) == 'rtl') {
  14. ltr = false;
  15. }
  16. $( '.grid-container' ).masonry( {
  17. itemSelector: '.widget',
  18. isOriginLeft: ltr,
  19. } );
  20. }
  21. /**
  22. * Firing events
  23. */
  24. // Fire on load
  25. $( window ).on( 'load', function() {
  26. widgetMasonry();
  27. } );
  28. // Fire on document ready
  29. $( document ).ready(function(){
  30. // Set some min-heights to help improve Masonry's treatment of these widgets
  31. // Get Twitter widgets and set a min-height on parent elements
  32. $( 'a.twitter-timeline' ).each( function() {
  33. var thisHeight = $( this ).attr( 'height' );
  34. // Set the widget to have this height
  35. $( this ).parent().css( 'min-height', thisHeight + 'px' );
  36. } );
  37. // Get Facebook widgets and set a min-height on parent elements
  38. $( '.fb-page' ).each( function() {
  39. // Get some settings from the initial markup:
  40. var $set_height = $( this ).data( 'height' ),
  41. $hide_cover = $( this ).data( 'hide-cover' ),
  42. $show_facepile = $( this ).data( 'show-facepile' ),
  43. $show_posts = $( this ).data( 'show-posts' ), // AKA stream
  44. $min_height = $set_height; // set the default 'min-height'
  45. // These values are defaults from the FB widget.
  46. var $no_posts_no_faces = 130,
  47. $no_posts = 220;
  48. if ( $show_posts ) {
  49. // Showing posts; may also be showing faces and/or cover - the latter doesn't affect the height at all.
  50. $min_height = $set_height;
  51. } else if ( $show_facepile ) {
  52. // Showing facepile with or without cover image - both would be same height.
  53. // If the user selected height is lower than the no_posts height, we'll use that instead
  54. $min_height = ( $set_height < $no_posts ) ? $set_height : $no_posts;
  55. } else {
  56. // Either just showing cover, or nothing is selected (both are same height).
  57. // If the user selected height is lower than the no_posts_no_faces height, we'll use that instead
  58. $min_height = ( $set_height < $no_posts_no_faces ) ? $set_height : $no_posts_no_faces;
  59. }
  60. // apply min-height to .fb-page container
  61. $( this ).css( 'min-height', $min_height + 'px' );
  62. } );
  63. } );
  64. } )( jQuery );