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

resources/assets/js/testimonials.js   A

Complexity

Total Complexity 7
Complexity/F 1.4

Size

Lines of Code 59
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 38
c 0
b 0
f 0
dl 0
loc 59
rs 10
mnd 2
bc 2
fnc 5
bpm 0.4
cpm 1.4
noi 2

2 Functions

Rating   Name   Duplication   Size   Complexity  
A testimonials.js ➔ reloadCarouselTestimonial 0 5 1
A testimonials.js ➔ calculateNumberOfSlidesToShowTestimonial 0 20 2
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