functions.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* global textBookSearchToggleText */
  2. ( function( $ ) {
  3. var $window = $( window ),
  4. testimonials = $( '.testimonials-carousel' ),
  5. wrapper = $( '.js body' );
  6. // Search toggle.
  7. $( '.search-toggle' ).on( 'click.textbook', function( event ) {
  8. var that = $( this ),
  9. wrapper = $( '#search-container' ),
  10. container = that.find( 'a' );
  11. event.preventDefault();
  12. that.toggleClass( 'active' );
  13. wrapper.toggleClass( 'show' );
  14. wrapper.parent().find('div').first().toggleClass( 'hide' );
  15. if ( that.hasClass( 'active' ) ) {
  16. container.attr( 'aria-expanded', 'true' );
  17. that.find( 'span' ).html( textBookSearchToggleText.close );
  18. } else {
  19. container.attr( 'aria-expanded', 'false' );
  20. that.find( 'span' ).html( textBookSearchToggleText.search );
  21. }
  22. if ( that.is( '.active' ) || $( '.search-toggle .screen-reader-text' )[0] === event.target ) {
  23. wrapper.find( '.search-field' ).focus();
  24. }
  25. } );
  26. // Move Jetpack sharing and post flair into the entry-footer
  27. $( '.entry-footer' ).after( jQuery( '#jp-post-flair, .geo-post, .entry-content > .sharedaddy' ).detach() );
  28. // On Load
  29. $( document ).ready( function() {
  30. // Init Testimonials Carousel
  31. testimonials.flexslider({
  32. // options
  33. animation: "slide",
  34. selector: ".slides > div",
  35. smoothHeight: true,
  36. slideshow: false,
  37. rtl: true,
  38. prevText: '<span class="screen-reader-text">Previous</span><svg version="1.1" id="previous-icon" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 16 16" xml:space="preserve"><polygon points="8,12.7 1.3,6 2.7,4.6 8,9.9 13.3,4.6 14.7,6 "/></svg>',
  39. nextText: '<span class="screen-reader-text">Next</span><svg version="1.1" id="next-icon" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 16 16" xml:space="preserve"><polygon points="8,12.7 1.3,6 2.7,4.6 8,9.9 13.3,4.6 14.7,6 "/></svg>'
  40. });
  41. // Fade in body
  42. wrapper.animate({
  43. opacity: 1,
  44. }, 30);
  45. // Triggers resize event to make sure video widgets in the footer maintain the correct aspect ratio
  46. setTimeout( function(){
  47. if ( typeof( Event ) === 'function' ) {
  48. window.dispatchEvent( new Event( 'resize' ) );
  49. } else {
  50. var event = window.document.createEvent( 'UIEvents' );
  51. event.initUIEvent( 'resize', true, false, window, 0 );
  52. window.dispatchEvent( event );
  53. }
  54. } );
  55. } );
  56. } )( jQuery );