portfolio-page.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * File portfolio-page.js
  3. *
  4. * JavaScript specific to the portfolio-page.php template.
  5. *
  6. * Loads Isotope, handles sorting and triggers lazy-loading for images
  7. */
  8. ( function( $ ) {
  9. // Define porfolio project wrapper
  10. $grid = $( '.portfolio-wrapper' );
  11. $( window ).load( function() {
  12. // Determine text direction
  13. var $ltr = true;
  14. if ( $('html' ).attr( 'dir' ) == 'rtl') {
  15. $ltr = false;
  16. }
  17. // Initialize Isotope
  18. $grid.isotope( {
  19. itemSelector: '.jetpack-portfolio',
  20. layoutMode: 'fitRows',
  21. animationEngine: 'best-available',
  22. originLeft: $ltr,
  23. columnWidth: $grid.width() / 2,
  24. resize: false
  25. } );
  26. } );
  27. // Portfolio Project filtering
  28. $( '.project-terms a' ).click( function( e ) {
  29. e.preventDefault();
  30. // Remove 'current-type' class from previously highlighted link
  31. $( '.project-terms a.current-type' ).removeClass( 'current-type' );
  32. // Add to link that was clicked
  33. $( this ).addClass( 'current-type' );
  34. // If the 'All' link was clicked, show all
  35. if ( $( this ).hasClass( 'types-all' ) ) {
  36. $grid.isotope( { filter: '*' } );
  37. // Otherwise, sort based on data attribute
  38. } else {
  39. // Returns format gettypeid-#### - we just want the numbers, so we split them off the end
  40. var $get_typeid = $(this).attr( 'data-get-typeid' ).split('-')[1];
  41. // Filter projects by class
  42. $grid.isotope( { filter: '.typeid-' + $get_typeid } );
  43. }
  44. // Make sure all the lazy loaded images are visible when filtering
  45. $( '.portfolio-featured-image' ).trigger( 'appear' );
  46. } );
  47. // Lazy load project images
  48. $(function() {
  49. $( '.portfolio-featured-image' ).lazyload( {
  50. effect: 'fadeIn',
  51. threshold: 200,
  52. } );
  53. } );
  54. } )( jQuery );