Skip to content

Commit

Permalink
experimenting
Browse files Browse the repository at this point in the history
  • Loading branch information
pratyushbh committed Jun 30, 2023
1 parent edfe540 commit e574c9c
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 9 deletions.
1 change: 1 addition & 0 deletions examples/AutoPlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function AutoPlay() {
autoplay: true,
speed: 2000,
autoplaySpeed: 2000,
pauseOnFocus: true,
cssEase: "linear"
};
return (
Expand Down
4 changes: 2 additions & 2 deletions examples/MultipleItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function MultipleItems() {
<div>
<h3>4</h3>
</div>
<div>
{/* <div>
<h3>5</h3>
</div>
<div>
Expand All @@ -39,7 +39,7 @@ function MultipleItems() {
</div>
<div>
<h3>9</h3>
</div>
</div> */}
</Slider>
</div>
);
Expand Down
1 change: 1 addition & 0 deletions examples/SimpleSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function SimpleSlider(props) {
speed: 500,
slidesToShow: 1,
slidesToScroll: 1,
initialSlide: 5,
...props
};
return (
Expand Down
10 changes: 10 additions & 0 deletions src/dots.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import React from "react";
import classnames from "classnames";
import { dotClicked, initializedState } from "./utils/innerSliderUtils";
import { clamp } from "./utils/innerSliderUtils";

const getDotCount = spec => {
Expand All @@ -24,6 +25,11 @@ export class Dots extends React.PureComponent {
// to next slide. That only goes away by click somewhere outside
e.preventDefault();
this.props.clickHandler(options);
document.activeElement.addEventListener("blur", event => {
if (!dotClicked()) {
this.props.autoPlayHandler("play");
}
});
}
render() {
const {
Expand All @@ -34,6 +40,8 @@ export class Dots extends React.PureComponent {
slidesToScroll,
slidesToShow,
slideCount,
autoplay,
autoplaying,
currentSlide
} = this.props;
let dotCount = getDotCount({
Expand Down Expand Up @@ -65,6 +73,8 @@ export class Dots extends React.PureComponent {
message: "dots",
index: i,
slidesToScroll,
autoplay,
autoplaying,
currentSlide
};

Expand Down
29 changes: 23 additions & 6 deletions src/inner-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ import {
getPreClones,
getPostClones,
getTrackLeft,
getTrackCSS
getTrackCSS,
getActiveElementTagName,
getActiveParentTagName,
getActiveParentClassnames,
getActiveElementClassnames,
dotClicked
} from "./utils/innerSliderUtils";

import { Track } from "./track";
Expand Down Expand Up @@ -96,6 +101,7 @@ export class InnerSlider extends React.Component {
slide.onblur = this.props.pauseOnFocus ? this.onSlideBlur : null;
}
);
console.log(this.props.pauseOnFocus);
if (window.addEventListener) {
window.addEventListener("resize", this.onWindowResized);
} else {
Expand Down Expand Up @@ -166,10 +172,11 @@ export class InnerSlider extends React.Component {
}
}
}
// if (this.props.onLazyLoad) {
// this.props.onLazyLoad([leftMostSlide])
// }
this.adaptHeight();
document.querySelectorAll &&
// if (this.props.onLazyLoad) {
// this.props.onLazyLoad([leftMostSlide])
// }
this.adaptHeight();
let spec = {
listRef: this.list,
trackRef: this.track,
Expand Down Expand Up @@ -438,6 +445,11 @@ export class InnerSlider extends React.Component {
const nodes = this.list.querySelectorAll(".slick-current");
nodes[0] && nodes[0].focus();
}
window.addEventListener("click", event => {
if (this.props.autoplay && dotClicked()) {
this.pause("paused");
}
});
};
clickHandler = e => {
if (this.clickable === false) {
Expand Down Expand Up @@ -669,11 +681,16 @@ export class InnerSlider extends React.Component {
"children",
"customPaging",
"infinite",
"appendDots"
"appendDots",
"autoplay",
"autoplaying",
"autoplaySpeed"
]);
const { pauseOnDotsHover } = this.props;
dotProps = {
...dotProps,
autoPlayHandler: this.autoPlay,
pauseHandler: this.pause,
clickHandler: this.changeSlide,
onMouseEnter: pauseOnDotsHover ? this.onDotsLeave : null,
onMouseOver: pauseOnDotsHover ? this.onDotsOver : null,
Expand Down
23 changes: 22 additions & 1 deletion src/utils/innerSliderUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,28 @@ export const siblingDirection = spec => {
return "left";
}
};

export const getActiveElementClassnames = () => {
return document.activeElement.parentElement.classList.value.toString();
};
export const getActiveParentTagName = () => {
return document.activeElement.parentElement.tagName;
};
export const getActiveParentClassnames = () => {
return document.activeElement.parentElement.classList.value.toString();
};
export const getActiveElementTagName = () => {
return document.activeElement.tagName;
};
export const dotClicked = () => {
if (
getActiveParentTagName() === "LI" &&
getActiveParentClassnames() === "slick-active"
) {
return true;
} else {
return false;
}
};
export const slidesOnRight = ({
slidesToShow,
centerMode,
Expand Down

0 comments on commit e574c9c

Please sign in to comment.