Completed
Push — master ( c4765e...785c00 )
by Davide
15:46 queued 08:12
created

testimonials.js ➔ createCarouselTestimonial   A

Complexity

Conditions 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 12
rs 9.9
cc 1
1
2
3
// Create carousel 
4
    function createCarouselTestimonial(numberOfSlides){
5
        jQuery('.testimonialsList').not('.slick-initialized').slick({
6
            dots: true,
7
            arrows: true,
8
            infinite: true,
9
            slidesToShow: numberOfSlides,
10
            slidesToScroll: 1,
11
            autoplay: true,
12
  			autoplaySpeed: 6000,
13
  			pauseOnHover: true
14
        });
15
	}
16
17
// Calculate number of slides to show
18
	function calculateNumberOfSlidesToShowTestimonial(){
19
		var carouselWidth = jQuery(".testimonialsList").width();
20
		var numberOfSlides = 0;
21
      	switch (true) {
22
		    case (carouselWidth < 767):
23
		        numberOfSlides = 1;
24
		        break;
25
		    case (carouselWidth < 991):
26
		        numberOfSlides = 2;
27
		        break;
28
		    case (carouselWidth < 1199):
29
		        numberOfSlides = 3;
30
		        break;
31
		    case (carouselWidth > 1200):
32
		        numberOfSlides = 3;
33
		        break;
34
		}
35
36
		return numberOfSlides;
37
	}
38
39
// Reload Carousel on browser resize (to make it responsible)
40
41
    function reloadCarouselTestimonial () {
42
      	jQuery('.testimonialsList').slick('unslick');
43
      	numberOfSlides = calculateNumberOfSlidesToShowTestimonial();
0 ignored issues
show
Bug introduced by
The variable numberOfSlides seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.numberOfSlides.
Loading history...
44
	    createCarouselTestimonial(numberOfSlides);
45
    }
46
47
// Call updateMaxHeight when browser resize event fires
48
    jQuery(window).on("resize", reloadCarouselTestimonial);
49
50
51
52
jQuery(document).ready(function () {
53
	// Start carousel
54
	    if (jQuery(".testimonialsList").length) {
55
	        setTimeout(function () {
56
	        	numberOfSlides = calculateNumberOfSlidesToShowTestimonial();
0 ignored issues
show
Bug introduced by
The variable numberOfSlides seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.numberOfSlides.
Loading history...
57
	            createCarouselTestimonial(numberOfSlides);
58
	        }, 300);
59
	    }
60
61
62
});
63