global.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /**
  2. * global.js
  3. *
  4. * General JavaScript used throughout the theme.
  5. *
  6. */
  7. ( function( $ ) {
  8. /**
  9. *
  10. * Slideshow magic!
  11. *
  12. */
  13. var $slideCount = $(".slides").find("li").length;
  14. $( '#featured-slideshow .wrap .slideshow' ).flexslider( {
  15. animation: 'slide',
  16. directionNav: false,
  17. } );
  18. /* wrapping the dot nav in a div, and sticking the prev/next links in there for placement */
  19. $( '.flex-control-nav' ).wrap( '<div class="slideshow-navigation"></div>' );
  20. // make sure there's more than one slide before appending prev/next links
  21. if ( $slideCount > 1 ) {
  22. $( '.slideshow-navigation' ).append( '<span class="next-slide"><span class="screen-reader-text">' + toujours_script_strings.next_link + '</span></span>' );
  23. $( '.slideshow-navigation' ).prepend( '<span class="prev-slide"><span class="screen-reader-text">' + toujours_script_strings.previous_link + '</span></span>' );
  24. /* ... then add some click events to those new buttons */
  25. $( 'body' ).on( 'click', '.prev-slide', function() {
  26. $('#featured-slideshow .wrap .slideshow').flexslider('prev');
  27. } );
  28. $( 'body' ).on( 'click', '.next-slide', function() {
  29. $('#featured-slideshow .wrap .slideshow').flexslider('next');
  30. } );
  31. }
  32. /* Make it possible to click the whole slide to get ot the post */
  33. $( '.slide' ).each( function() {
  34. // make sure the page isn't loaded in an iframe, like in the Customizer
  35. if ( self == top ) {
  36. var $link = $( '.posted-on a', this ).attr( 'href' );
  37. $( this ).css( 'cursor', 'pointer' ).click( function(){
  38. window.location = $link;
  39. });
  40. }
  41. } );
  42. /**
  43. * Search
  44. * Adding some JS so the faux button has a hover state
  45. */
  46. $( '.search-submit' ).mouseenter( function() {
  47. $( this ).parent().addClass( 'hover-button' );
  48. } ).mouseleave( function() {
  49. $( this ).parent().removeClass( 'hover-button' );
  50. } );
  51. /**
  52. * Masonry for footer widgets
  53. */
  54. var ltr = true;
  55. if ( $( 'html' ).attr( 'dir' ) == 'rtl') {
  56. ltr = false;
  57. }
  58. function footerMasonry() {
  59. var $footerContainer = $( '#footer-widgets .grid-layout' );
  60. $footerContainer.imagesLoaded( function() {
  61. $footerContainer.masonry( {
  62. itemSelector: '.widget',
  63. columnWidth: '#footer-widgets aside',
  64. isOriginLeft: ltr,
  65. gutter: 30,
  66. } );
  67. } );
  68. }
  69. /**
  70. * Masonry for Guestbook template
  71. */
  72. function guestbookMasonry() {
  73. var $guestbookContainer = $( '.page-template-guestbook #comments .comment-list');
  74. $guestbookContainer.imagesLoaded( function() {
  75. $guestbookContainer.masonry( {
  76. itemSelector: '.comment',
  77. isOriginLeft: ltr,
  78. gutter: 30,
  79. } );
  80. } );
  81. }
  82. /**
  83. * Add class to tables to help make them responsive
  84. */
  85. $( 'table' ).addClass( 'table' );
  86. $( 'table' ).wrap( '<div class="table-responsive" />' );
  87. var infiniteCount = 0;
  88. $( document.body ).on( 'post-load', function() {
  89. infiniteCount = infiniteCount + 1;
  90. var infiniteItems = jQuery( '.infinite-wrap.infinite-view-' + infiniteCount );
  91. infiniteItems.find( 'table' ).addClass( 'table' ).wrap( '<div class="table-responsive" />' );
  92. });
  93. /* Functions to fire on pageload */
  94. $( window ).load( function() {
  95. guestbookMasonry();
  96. footerMasonry();
  97. // re-fire widgets after a delay, for widgets loaded via JS
  98. setTimeout( footerMasonry, 2500 );
  99. } );
  100. } )( jQuery );