forked from akiran/react-slick
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdots.js
More file actions
75 lines (66 loc) · 2.05 KB
/
Copy pathdots.js
File metadata and controls
75 lines (66 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"use strict";
import React from "react";
import classnames from "classnames";
var getDotCount = function(spec) {
var dots;
if (spec.infinite) {
dots = Math.ceil(spec.slideCount / spec.slidesToScroll);
} else {
dots =
Math.ceil((spec.slideCount - spec.slidesToShow) / spec.slidesToScroll) +
1;
}
return dots;
};
export class Dots extends React.PureComponent {
clickHandler(options, e) {
// In Autoplay the focus stays on clicked button even after transition
// to next slide. That only goes away by click somewhere outside
e.preventDefault();
this.props.clickHandler(options);
}
render() {
var dotCount = getDotCount({
slideCount: this.props.slideCount,
slidesToScroll: this.props.slidesToScroll,
slidesToShow: this.props.slidesToShow,
infinite: this.props.infinite
});
// Apply join & split to Array to pre-fill it for IE8
//
// Credit: http://stackoverflow.com/a/13735425/1849458
const { onMouseEnter, onMouseOver, onMouseLeave } = this.props;
const mouseEvents = { onMouseEnter, onMouseOver, onMouseLeave };
var dots = Array.apply(
null,
Array(dotCount + 1)
.join("0")
.split("")
).map((x, i) => {
var leftBound = i * this.props.slidesToScroll;
var rightBound =
i * this.props.slidesToScroll + (this.props.slidesToScroll - 1);
var className = classnames({
"slick-active":
this.props.currentSlide >= leftBound &&
this.props.currentSlide <= rightBound
});
var dotOptions = {
message: "dots",
index: i,
slidesToScroll: this.props.slidesToScroll,
currentSlide: this.props.currentSlide
};
var onClick = this.clickHandler.bind(this, dotOptions);
return (
<li key={i} className={className}>
{React.cloneElement(this.props.customPaging(i), { onClick })}
</li>
);
});
return React.cloneElement(this.props.appendDots(dots), {
className: this.props.dotsClass,
...mouseEvents
});
}
}