1/** 2 * Facts Carousel driven by Slick.js 3 * 4 * @author Damon Cook 5 */ 6window.FactsCarousel = {}; 7( function( window, $, that ) { 8 9 // Constructor. 10 that.init = function() { 11 that.cache(); 12 13 if ( that.meetsRequirements() ) { 14 that.bindEvents(); 15 } 16 }; 17 18 // Cache all the things. 19 that.cache = function() { 20 that.$c = { 21 window: $(window), 22 factsCarousel: $( '.facts-carousel' ), 23 }; 24 }; 25 26 // Combine all events. 27 that.bindEvents = function() { 28 that.$c.window.on( 'load', that.initiateCarousel ); 29 30 // Moments before a slide changes 31 that.$c.factsCarousel.on( 'beforeChange', that.beforeSlideChange ); 32 33 // Moments after a slide changes 34 that.$c.factsCarousel.on( 'afterChange', that.afterSlideChange ); 35 }; 36 37 // Do we meet the requirements? 38 that.meetsRequirements = function() { 39 return that.$c.factsCarousel.length; 40 }; 41 42 // Initiate the Slick.js fueled carousel 43 that.initiateCarousel = function() { 44 that.$c.factsCarousel.slick({ 45 arrows: true, 46 centerMode: true, 47 dots: true, 48 slidesToShow: 5, 49 variableWidth: true, 50 zIndex: 1, 51 responsive: [ 52 { 53 breakpoint: 360, 54 settings: { 55 slidesToShow: 3, 56 } 57 }, 58 ] 59 }); 60 61 // Add a class to the slide to the left of current slide 62 $( '.facts-carousel .slick-current' ).prev( '.slick-slide' ).addClass( 'current-slide-left' ); 63 64 // Add a class to the slide to the right of current slide 65 $( '.facts-carousel .slick-current' ).next( '.slick-slide' ).addClass( 'current-slide-right' ); 66 }; 67 68 // Do some stuff immediately before slide changes 69 that.beforeSlideChange = function( event, slick, currentSlide, nextSlide ) { 70 $( '.facts-carousel .slick-slide' ).removeClass( 'current-slide-right current-slide-left' ); 71 }; 72 73 // Do some stuff after the slide changes 74 that.afterSlideChange = function( event, slick, currentSlide ) { 75 // Add a class to the slide to the left of current slide 76 $( '.facts-carousel .slick-current' ).prev( '.slick-slide' ).addClass( 'current-slide-left' ); 77 // Add a class to the slide to the right of current slide 78 $( '.facts-carousel .slick-current' ).next( '.slick-slide' ).addClass( 'current-slide-right' ); 79 }; 80 81 // Engage! 82 $( that.init ); 83 84})( window, jQuery, window.FactsCarousel );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.