libre.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. (function($) {
  2. var stickyHeader = $( '.site-header' );
  3. var body = $( 'body' );
  4. var adminBar = libreadminbar; //localized in functions.php
  5. var stickyHeaderOffset;
  6. var brandingWidth = $( '.site-branding' ).width();
  7. var titleWidth = $( '.site-title' ).width();
  8. var taglineWidth = $( '.site-description' ).width();
  9. if ( adminBar > 0 ) {
  10. stickyHeaderOffset = stickyHeader.offset().top - 32;
  11. } else {
  12. stickyHeaderOffset = stickyHeader.offset().top;
  13. }
  14. var stickyTime = function() {
  15. if( $(window).scrollTop() > stickyHeaderOffset ) {
  16. body.addClass( 'sticking' );
  17. } else {
  18. body.removeClass( 'sticking' );
  19. }
  20. }
  21. /* Remove border from linked images */
  22. function linkedImages() {
  23. var imgs = $( '.entry-content img' );
  24. for ( var i = 0, imgslength = imgs.length; i < imgslength; i++ ) {
  25. if ( '' !== $( imgs[i] ).closest( 'a' ) ) {
  26. $( imgs[i] ).closest( 'a' ).addClass( 'no-line' );
  27. }
  28. }
  29. }
  30. // Avoid stress cases with site title and tagline lengths.
  31. function brandingWidthMagic() {
  32. if ( ! body.hasClass( 'sticking' ) ) {
  33. if ( titleWidth || taglineWidth <= brandingWidth / 2 ) {
  34. $( '.site-description' ).css( { 'display': 'inline-block', 'margin-bottom': '0' } );
  35. }
  36. } else {
  37. $( '.site-description' ).removeAttr( 'style' );
  38. }
  39. }
  40. // After window loads
  41. $( window ).load( function() {
  42. linkedImages();
  43. stickyTime();
  44. brandingWidthMagic();
  45. } );
  46. // After scrolling
  47. $( window ).scroll( function() {
  48. stickyTime();
  49. brandingWidthMagic();
  50. } );
  51. // After window is resized or infinite scroll loads new posts
  52. $( window ).on( 'resize post-load', function() {
  53. linkedImages();
  54. brandingWidthMagic();
  55. } );
  56. })(jQuery);