Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

3 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.InnerSlider = void 0;
  6. var _react = _interopRequireDefault(require("react"));
  7. var _reactDom = _interopRequireDefault(require("react-dom"));
  8. var _initialState = _interopRequireDefault(require("./initial-state"));
  9. var _lodash = _interopRequireDefault(require("lodash.debounce"));
  10. var _classnames = _interopRequireDefault(require("classnames"));
  11. var _innerSliderUtils = require("./utils/innerSliderUtils");
  12. var _track = require("./track");
  13. var _dots = require("./dots");
  14. var _arrows = require("./arrows");
  15. var _resizeObserverPolyfill = _interopRequireDefault(require("resize-observer-polyfill"));
  16. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  17. function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
  18. function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
  19. function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
  20. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  21. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
  22. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  23. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  24. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  25. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  26. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  27. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  28. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  29. var InnerSlider =
  30. /*#__PURE__*/
  31. function (_React$Component) {
  32. _inherits(InnerSlider, _React$Component);
  33. function InnerSlider(props) {
  34. var _this;
  35. _classCallCheck(this, InnerSlider);
  36. _this = _possibleConstructorReturn(this, _getPrototypeOf(InnerSlider).call(this, props));
  37. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "listRefHandler", function (ref) {
  38. return _this.list = ref;
  39. });
  40. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "trackRefHandler", function (ref) {
  41. return _this.track = ref;
  42. });
  43. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "adaptHeight", function () {
  44. if (_this.props.adaptiveHeight && _this.list) {
  45. var elem = _this.list.querySelector("[data-index=\"".concat(_this.state.currentSlide, "\"]"));
  46. _this.list.style.height = (0, _innerSliderUtils.getHeight)(elem) + "px";
  47. }
  48. });
  49. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "componentWillMount", function () {
  50. _this.ssrInit();
  51. _this.props.onInit && _this.props.onInit();
  52. if (_this.props.lazyLoad) {
  53. var slidesToLoad = (0, _innerSliderUtils.getOnDemandLazySlides)(_objectSpread({}, _this.props, _this.state));
  54. if (slidesToLoad.length > 0) {
  55. _this.setState(function (prevState) {
  56. return {
  57. lazyLoadedList: prevState.lazyLoadedList.concat(slidesToLoad)
  58. };
  59. });
  60. if (_this.props.onLazyLoad) {
  61. _this.props.onLazyLoad(slidesToLoad);
  62. }
  63. }
  64. }
  65. });
  66. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "componentDidMount", function () {
  67. var spec = _objectSpread({
  68. listRef: _this.list,
  69. trackRef: _this.track
  70. }, _this.props);
  71. _this.updateState(spec, true, function () {
  72. _this.adaptHeight();
  73. _this.props.autoplay && _this.autoPlay("update");
  74. });
  75. if (_this.props.lazyLoad === "progressive") {
  76. _this.lazyLoadTimer = setInterval(_this.progressiveLazyLoad, 1000);
  77. }
  78. _this.ro = new _resizeObserverPolyfill.default(function () {
  79. if (_this.state.animating) {
  80. _this.onWindowResized(false); // don't set trackStyle hence don't break animation
  81. _this.callbackTimers.push(setTimeout(function () {
  82. return _this.onWindowResized();
  83. }, _this.props.speed));
  84. } else {
  85. _this.onWindowResized();
  86. }
  87. });
  88. _this.ro.observe(_this.list);
  89. Array.prototype.forEach.call(document.querySelectorAll(".slick-slide"), function (slide) {
  90. slide.onfocus = _this.props.pauseOnFocus ? _this.onSlideFocus : null;
  91. slide.onblur = _this.props.pauseOnFocus ? _this.onSlideBlur : null;
  92. }); // To support server-side rendering
  93. if (!window) {
  94. return;
  95. }
  96. if (window.addEventListener) {
  97. window.addEventListener("resize", _this.onWindowResized);
  98. } else {
  99. window.attachEvent("onresize", _this.onWindowResized);
  100. }
  101. });
  102. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "componentWillUnmount", function () {
  103. if (_this.animationEndCallback) {
  104. clearTimeout(_this.animationEndCallback);
  105. }
  106. if (_this.lazyLoadTimer) {
  107. clearInterval(_this.lazyLoadTimer);
  108. }
  109. if (_this.callbackTimers.length) {
  110. _this.callbackTimers.forEach(function (timer) {
  111. return clearTimeout(timer);
  112. });
  113. _this.callbackTimers = [];
  114. }
  115. if (window.addEventListener) {
  116. window.removeEventListener("resize", _this.onWindowResized);
  117. } else {
  118. window.detachEvent("onresize", _this.onWindowResized);
  119. }
  120. if (_this.autoplayTimer) {
  121. clearInterval(_this.autoplayTimer);
  122. }
  123. });
  124. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "componentWillReceiveProps", function (nextProps) {
  125. var spec = _objectSpread({
  126. listRef: _this.list,
  127. trackRef: _this.track
  128. }, nextProps, _this.state);
  129. var setTrackStyle = false;
  130. var _arr = Object.keys(_this.props);
  131. for (var _i = 0; _i < _arr.length; _i++) {
  132. var key = _arr[_i];
  133. if (!nextProps.hasOwnProperty(key)) {
  134. setTrackStyle = true;
  135. break;
  136. }
  137. if (_typeof(nextProps[key]) === "object" || typeof nextProps[key] === "function") {
  138. continue;
  139. }
  140. if (nextProps[key] !== _this.props[key]) {
  141. setTrackStyle = true;
  142. break;
  143. }
  144. }
  145. _this.updateState(spec, setTrackStyle, function () {
  146. if (_this.state.currentSlide >= _react.default.Children.count(nextProps.children)) {
  147. _this.changeSlide({
  148. message: "index",
  149. index: _react.default.Children.count(nextProps.children) - nextProps.slidesToShow,
  150. currentSlide: _this.state.currentSlide
  151. });
  152. }
  153. if (nextProps.autoplay) {
  154. _this.autoPlay("update");
  155. } else {
  156. _this.pause("paused");
  157. }
  158. });
  159. });
  160. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "componentDidUpdate", function () {
  161. _this.checkImagesLoad();
  162. _this.props.onReInit && _this.props.onReInit();
  163. if (_this.props.lazyLoad) {
  164. var slidesToLoad = (0, _innerSliderUtils.getOnDemandLazySlides)(_objectSpread({}, _this.props, _this.state));
  165. if (slidesToLoad.length > 0) {
  166. _this.setState(function (prevState) {
  167. return {
  168. lazyLoadedList: prevState.lazyLoadedList.concat(slidesToLoad)
  169. };
  170. });
  171. if (_this.props.onLazyLoad) {
  172. _this.props.onLazyLoad(slidesToLoad);
  173. }
  174. }
  175. } // if (this.props.onLazyLoad) {
  176. // this.props.onLazyLoad([leftMostSlide])
  177. // }
  178. _this.adaptHeight();
  179. });
  180. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "onWindowResized", function (setTrackStyle) {
  181. if (_this.debouncedResize) _this.debouncedResize.cancel();
  182. _this.debouncedResize = (0, _lodash.default)(function () {
  183. return _this.resizeWindow(setTrackStyle);
  184. }, 50);
  185. _this.debouncedResize();
  186. });
  187. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "resizeWindow", function () {
  188. var setTrackStyle = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  189. if (!_reactDom.default.findDOMNode(_this.track)) return;
  190. var spec = _objectSpread({
  191. listRef: _this.list,
  192. trackRef: _this.track
  193. }, _this.props, _this.state);
  194. _this.updateState(spec, setTrackStyle, function () {
  195. if (_this.props.autoplay) _this.autoPlay("update");else _this.pause("paused");
  196. }); // animating state should be cleared while resizing, otherwise autoplay stops working
  197. _this.setState({
  198. animating: false
  199. });
  200. clearTimeout(_this.animationEndCallback);
  201. delete _this.animationEndCallback;
  202. });
  203. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "updateState", function (spec, setTrackStyle, callback) {
  204. var updatedState = (0, _innerSliderUtils.initializedState)(spec);
  205. spec = _objectSpread({}, spec, updatedState, {
  206. slideIndex: updatedState.currentSlide
  207. });
  208. var targetLeft = (0, _innerSliderUtils.getTrackLeft)(spec);
  209. spec = _objectSpread({}, spec, {
  210. left: targetLeft
  211. });
  212. var trackStyle = (0, _innerSliderUtils.getTrackCSS)(spec);
  213. if (setTrackStyle || _react.default.Children.count(_this.props.children) !== _react.default.Children.count(spec.children)) {
  214. updatedState["trackStyle"] = trackStyle;
  215. }
  216. _this.setState(updatedState, callback);
  217. });
  218. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "ssrInit", function () {
  219. if (_this.props.variableWidth) {
  220. var _trackWidth = 0,
  221. _trackLeft = 0;
  222. var childrenWidths = [];
  223. var preClones = (0, _innerSliderUtils.getPreClones)(_objectSpread({}, _this.props, _this.state, {
  224. slideCount: _this.props.children.length
  225. }));
  226. var postClones = (0, _innerSliderUtils.getPostClones)(_objectSpread({}, _this.props, _this.state, {
  227. slideCount: _this.props.children.length
  228. }));
  229. _this.props.children.forEach(function (child) {
  230. childrenWidths.push(child.props.style.width);
  231. _trackWidth += child.props.style.width;
  232. });
  233. for (var i = 0; i < preClones; i++) {
  234. _trackLeft += childrenWidths[childrenWidths.length - 1 - i];
  235. _trackWidth += childrenWidths[childrenWidths.length - 1 - i];
  236. }
  237. for (var _i2 = 0; _i2 < postClones; _i2++) {
  238. _trackWidth += childrenWidths[_i2];
  239. }
  240. for (var _i3 = 0; _i3 < _this.state.currentSlide; _i3++) {
  241. _trackLeft += childrenWidths[_i3];
  242. }
  243. var _trackStyle = {
  244. width: _trackWidth + "px",
  245. left: -_trackLeft + "px"
  246. };
  247. if (_this.props.centerMode) {
  248. var currentWidth = "".concat(childrenWidths[_this.state.currentSlide], "px");
  249. _trackStyle.left = "calc(".concat(_trackStyle.left, " + (100% - ").concat(currentWidth, ") / 2 ) ");
  250. }
  251. _this.setState({
  252. trackStyle: _trackStyle
  253. });
  254. return;
  255. }
  256. var childrenCount = _react.default.Children.count(_this.props.children);
  257. var spec = _objectSpread({}, _this.props, _this.state, {
  258. slideCount: childrenCount
  259. });
  260. var slideCount = (0, _innerSliderUtils.getPreClones)(spec) + (0, _innerSliderUtils.getPostClones)(spec) + childrenCount;
  261. var trackWidth = 100 / _this.props.slidesToShow * slideCount;
  262. var slideWidth = 100 / slideCount;
  263. var trackLeft = -slideWidth * ((0, _innerSliderUtils.getPreClones)(spec) + _this.state.currentSlide) * trackWidth / 100;
  264. if (_this.props.centerMode) {
  265. trackLeft += (100 - slideWidth * trackWidth / 100) / 2;
  266. }
  267. var trackStyle = {
  268. width: trackWidth + "%",
  269. left: trackLeft + "%"
  270. };
  271. _this.setState({
  272. slideWidth: slideWidth + "%",
  273. trackStyle: trackStyle
  274. });
  275. });
  276. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "checkImagesLoad", function () {
  277. var images = document.querySelectorAll(".slick-slide img");
  278. var imagesCount = images.length,
  279. loadedCount = 0;
  280. Array.prototype.forEach.call(images, function (image) {
  281. var handler = function handler() {
  282. return ++loadedCount && loadedCount >= imagesCount && _this.onWindowResized();
  283. };
  284. if (!image.onclick) {
  285. image.onclick = function () {
  286. return image.parentNode.focus();
  287. };
  288. } else {
  289. var prevClickHandler = image.onclick;
  290. image.onclick = function () {
  291. prevClickHandler();
  292. image.parentNode.focus();
  293. };
  294. }
  295. if (!image.onload) {
  296. if (_this.props.lazyLoad) {
  297. image.onload = function () {
  298. _this.adaptHeight();
  299. _this.callbackTimers.push(setTimeout(_this.onWindowResized, _this.props.speed));
  300. };
  301. } else {
  302. image.onload = handler;
  303. image.onerror = function () {
  304. handler();
  305. _this.props.onLazyLoadError && _this.props.onLazyLoadError();
  306. };
  307. }
  308. }
  309. });
  310. });
  311. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "progressiveLazyLoad", function () {
  312. var slidesToLoad = [];
  313. var spec = _objectSpread({}, _this.props, _this.state);
  314. for (var index = _this.state.currentSlide; index < _this.state.slideCount + (0, _innerSliderUtils.getPostClones)(spec); index++) {
  315. if (_this.state.lazyLoadedList.indexOf(index) < 0) {
  316. slidesToLoad.push(index);
  317. break;
  318. }
  319. }
  320. for (var _index = _this.state.currentSlide - 1; _index >= -(0, _innerSliderUtils.getPreClones)(spec); _index--) {
  321. if (_this.state.lazyLoadedList.indexOf(_index) < 0) {
  322. slidesToLoad.push(_index);
  323. break;
  324. }
  325. }
  326. if (slidesToLoad.length > 0) {
  327. _this.setState(function (state) {
  328. return {
  329. lazyLoadedList: state.lazyLoadedList.concat(slidesToLoad)
  330. };
  331. });
  332. if (_this.props.onLazyLoad) {
  333. _this.props.onLazyLoad(slidesToLoad);
  334. }
  335. } else {
  336. if (_this.lazyLoadTimer) {
  337. clearInterval(_this.lazyLoadTimer);
  338. delete _this.lazyLoadTimer;
  339. }
  340. }
  341. });
  342. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "slideHandler", function (index) {
  343. var dontAnimate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  344. var _this$props = _this.props,
  345. asNavFor = _this$props.asNavFor,
  346. beforeChange = _this$props.beforeChange,
  347. onLazyLoad = _this$props.onLazyLoad,
  348. speed = _this$props.speed,
  349. afterChange = _this$props.afterChange; // capture currentslide before state is updated
  350. var currentSlide = _this.state.currentSlide;
  351. var _slideHandler = (0, _innerSliderUtils.slideHandler)(_objectSpread({
  352. index: index
  353. }, _this.props, _this.state, {
  354. trackRef: _this.track,
  355. useCSS: _this.props.useCSS && !dontAnimate
  356. })),
  357. state = _slideHandler.state,
  358. nextState = _slideHandler.nextState;
  359. if (!state) return;
  360. beforeChange && beforeChange(currentSlide, state.currentSlide);
  361. var slidesToLoad = state.lazyLoadedList.filter(function (value) {
  362. return _this.state.lazyLoadedList.indexOf(value) < 0;
  363. });
  364. onLazyLoad && slidesToLoad.length > 0 && onLazyLoad(slidesToLoad);
  365. _this.setState(state, function () {
  366. asNavFor && asNavFor.innerSlider.state.currentSlide !== _this.state.currentSlide && asNavFor.innerSlider.slideHandler(index);
  367. if (!nextState) return;
  368. _this.animationEndCallback = setTimeout(function () {
  369. var animating = nextState.animating,
  370. firstBatch = _objectWithoutProperties(nextState, ["animating"]);
  371. _this.setState(firstBatch, function () {
  372. _this.callbackTimers.push(setTimeout(function () {
  373. return _this.setState({
  374. animating: animating
  375. });
  376. }, 10));
  377. afterChange && afterChange(state.currentSlide);
  378. delete _this.animationEndCallback;
  379. });
  380. }, speed);
  381. });
  382. });
  383. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "changeSlide", function (options) {
  384. var dontAnimate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  385. var spec = _objectSpread({}, _this.props, _this.state);
  386. var targetSlide = (0, _innerSliderUtils.changeSlide)(spec, options);
  387. if (targetSlide !== 0 && !targetSlide) return;
  388. if (dontAnimate === true) {
  389. _this.slideHandler(targetSlide, dontAnimate);
  390. } else {
  391. _this.slideHandler(targetSlide);
  392. }
  393. });
  394. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "clickHandler", function (e) {
  395. if (_this.clickable === false) {
  396. e.stopPropagation();
  397. e.preventDefault();
  398. }
  399. _this.clickable = true;
  400. });
  401. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "keyHandler", function (e) {
  402. var dir = (0, _innerSliderUtils.keyHandler)(e, _this.props.accessibility, _this.props.rtl);
  403. dir !== "" && _this.changeSlide({
  404. message: dir
  405. });
  406. });
  407. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "selectHandler", function (options) {
  408. _this.changeSlide(options);
  409. });
  410. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "disableBodyScroll", function () {
  411. var preventDefault = function preventDefault(e) {
  412. e = e || window.event;
  413. if (e.preventDefault) e.preventDefault();
  414. e.returnValue = false;
  415. };
  416. window.ontouchmove = preventDefault;
  417. });
  418. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "enableBodyScroll", function () {
  419. window.ontouchmove = null;
  420. });
  421. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "swipeStart", function (e) {
  422. if (_this.props.verticalSwiping) {
  423. _this.disableBodyScroll();
  424. }
  425. var state = (0, _innerSliderUtils.swipeStart)(e, _this.props.swipe, _this.props.draggable);
  426. state !== "" && _this.setState(state);
  427. });
  428. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "swipeMove", function (e) {
  429. var state = (0, _innerSliderUtils.swipeMove)(e, _objectSpread({}, _this.props, _this.state, {
  430. trackRef: _this.track,
  431. listRef: _this.list,
  432. slideIndex: _this.state.currentSlide
  433. }));
  434. if (!state) return;
  435. if (state["swiping"]) {
  436. _this.clickable = false;
  437. }
  438. _this.setState(state);
  439. });
  440. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "swipeEnd", function (e) {
  441. var state = (0, _innerSliderUtils.swipeEnd)(e, _objectSpread({}, _this.props, _this.state, {
  442. trackRef: _this.track,
  443. listRef: _this.list,
  444. slideIndex: _this.state.currentSlide
  445. }));
  446. if (!state) return;
  447. var triggerSlideHandler = state["triggerSlideHandler"];
  448. delete state["triggerSlideHandler"];
  449. _this.setState(state);
  450. if (triggerSlideHandler === undefined) return;
  451. _this.slideHandler(triggerSlideHandler);
  452. if (_this.props.verticalSwiping) {
  453. _this.enableBodyScroll();
  454. }
  455. });
  456. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "slickPrev", function () {
  457. // this and fellow methods are wrapped in setTimeout
  458. // to make sure initialize setState has happened before
  459. // any of such methods are called
  460. _this.callbackTimers.push(setTimeout(function () {
  461. return _this.changeSlide({
  462. message: "previous"
  463. });
  464. }, 0));
  465. });
  466. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "slickNext", function () {
  467. _this.callbackTimers.push(setTimeout(function () {
  468. return _this.changeSlide({
  469. message: "next"
  470. });
  471. }, 0));
  472. });
  473. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "slickGoTo", function (slide) {
  474. var dontAnimate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  475. slide = Number(slide);
  476. if (isNaN(slide)) return "";
  477. _this.callbackTimers.push(setTimeout(function () {
  478. return _this.changeSlide({
  479. message: "index",
  480. index: slide,
  481. currentSlide: _this.state.currentSlide
  482. }, dontAnimate);
  483. }, 0));
  484. });
  485. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "play", function () {
  486. var nextIndex;
  487. if (_this.props.rtl) {
  488. nextIndex = _this.state.currentSlide - _this.props.slidesToScroll;
  489. } else {
  490. if ((0, _innerSliderUtils.canGoNext)(_objectSpread({}, _this.props, _this.state))) {
  491. nextIndex = _this.state.currentSlide + _this.props.slidesToScroll;
  492. } else {
  493. return false;
  494. }
  495. }
  496. _this.slideHandler(nextIndex);
  497. });
  498. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "autoPlay", function (playType) {
  499. if (_this.autoplayTimer) {
  500. clearInterval(_this.autoplayTimer);
  501. }
  502. var autoplaying = _this.state.autoplaying;
  503. if (playType === "update") {
  504. if (autoplaying === "hovered" || autoplaying === "focused" || autoplaying === "paused") {
  505. return;
  506. }
  507. } else if (playType === "leave") {
  508. if (autoplaying === "paused" || autoplaying === "focused") {
  509. return;
  510. }
  511. } else if (playType === "blur") {
  512. if (autoplaying === "paused" || autoplaying === "hovered") {
  513. return;
  514. }
  515. }
  516. _this.autoplayTimer = setInterval(_this.play, _this.props.autoplaySpeed + 50);
  517. _this.setState({
  518. autoplaying: "playing"
  519. });
  520. });
  521. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "pause", function (pauseType) {
  522. if (_this.autoplayTimer) {
  523. clearInterval(_this.autoplayTimer);
  524. _this.autoplayTimer = null;
  525. }
  526. var autoplaying = _this.state.autoplaying;
  527. if (pauseType === "paused") {
  528. _this.setState({
  529. autoplaying: "paused"
  530. });
  531. } else if (pauseType === "focused") {
  532. if (autoplaying === "hovered" || autoplaying === "playing") {
  533. _this.setState({
  534. autoplaying: "focused"
  535. });
  536. }
  537. } else {
  538. // pauseType is 'hovered'
  539. if (autoplaying === "playing") {
  540. _this.setState({
  541. autoplaying: "hovered"
  542. });
  543. }
  544. }
  545. });
  546. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "onDotsOver", function () {
  547. return _this.props.autoplay && _this.pause("hovered");
  548. });
  549. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "onDotsLeave", function () {
  550. return _this.props.autoplay && _this.state.autoplaying === "hovered" && _this.autoPlay("leave");
  551. });
  552. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "onTrackOver", function () {
  553. return _this.props.autoplay && _this.pause("hovered");
  554. });
  555. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "onTrackLeave", function () {
  556. return _this.props.autoplay && _this.state.autoplaying === "hovered" && _this.autoPlay("leave");
  557. });
  558. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "onSlideFocus", function () {
  559. return _this.props.autoplay && _this.pause("focused");
  560. });
  561. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "onSlideBlur", function () {
  562. return _this.props.autoplay && _this.state.autoplaying === "focused" && _this.autoPlay("blur");
  563. });
  564. _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "render", function () {
  565. var className = (0, _classnames.default)("slick-slider", _this.props.className, {
  566. "slick-vertical": _this.props.vertical,
  567. "slick-initialized": true
  568. });
  569. var spec = _objectSpread({}, _this.props, _this.state);
  570. var trackProps = (0, _innerSliderUtils.extractObject)(spec, ["fade", "cssEase", "speed", "infinite", "centerMode", "focusOnSelect", "currentSlide", "lazyLoad", "lazyLoadedList", "rtl", "slideWidth", "slideHeight", "listHeight", "vertical", "slidesToShow", "slidesToScroll", "slideCount", "trackStyle", "variableWidth", "unslick", "centerPadding"]);
  571. var pauseOnHover = _this.props.pauseOnHover;
  572. trackProps = _objectSpread({}, trackProps, {
  573. onMouseEnter: pauseOnHover ? _this.onTrackOver : null,
  574. onMouseLeave: pauseOnHover ? _this.onTrackLeave : null,
  575. onMouseOver: pauseOnHover ? _this.onTrackOver : null,
  576. focusOnSelect: _this.props.focusOnSelect ? _this.selectHandler : null
  577. });
  578. var dots;
  579. if (_this.props.dots === true && _this.state.slideCount >= _this.props.slidesToShow) {
  580. var dotProps = (0, _innerSliderUtils.extractObject)(spec, ["dotsClass", "slideCount", "slidesToShow", "currentSlide", "slidesToScroll", "clickHandler", "children", "customPaging", "infinite", "appendDots"]);
  581. var pauseOnDotsHover = _this.props.pauseOnDotsHover;
  582. dotProps = _objectSpread({}, dotProps, {
  583. clickHandler: _this.changeSlide,
  584. onMouseEnter: pauseOnDotsHover ? _this.onDotsLeave : null,
  585. onMouseOver: pauseOnDotsHover ? _this.onDotsOver : null,
  586. onMouseLeave: pauseOnDotsHover ? _this.onDotsLeave : null
  587. });
  588. dots = _react.default.createElement(_dots.Dots, dotProps);
  589. }
  590. var prevArrow, nextArrow;
  591. var arrowProps = (0, _innerSliderUtils.extractObject)(spec, ["infinite", "centerMode", "currentSlide", "slideCount", "slidesToShow", "prevArrow", "nextArrow"]);
  592. arrowProps.clickHandler = _this.changeSlide;
  593. if (_this.props.arrows) {
  594. prevArrow = _react.default.createElement(_arrows.PrevArrow, arrowProps);
  595. nextArrow = _react.default.createElement(_arrows.NextArrow, arrowProps);
  596. }
  597. var verticalHeightStyle = null;
  598. if (_this.props.vertical) {
  599. verticalHeightStyle = {
  600. height: _this.state.listHeight
  601. };
  602. }
  603. var centerPaddingStyle = null;
  604. if (_this.props.vertical === false) {
  605. if (_this.props.centerMode === true) {
  606. centerPaddingStyle = {
  607. padding: "0px " + _this.props.centerPadding
  608. };
  609. }
  610. } else {
  611. if (_this.props.centerMode === true) {
  612. centerPaddingStyle = {
  613. padding: _this.props.centerPadding + " 0px"
  614. };
  615. }
  616. }
  617. var listStyle = _objectSpread({}, verticalHeightStyle, centerPaddingStyle);
  618. var touchMove = _this.props.touchMove;
  619. var listProps = {
  620. className: "slick-list",
  621. style: listStyle,
  622. onClick: _this.clickHandler,
  623. onMouseDown: touchMove ? _this.swipeStart : null,
  624. onMouseMove: _this.state.dragging && touchMove ? _this.swipeMove : null,
  625. onMouseUp: touchMove ? _this.swipeEnd : null,
  626. onMouseLeave: _this.state.dragging && touchMove ? _this.swipeEnd : null,
  627. onTouchStart: touchMove ? _this.swipeStart : null,
  628. onTouchMove: _this.state.dragging && touchMove ? _this.swipeMove : null,
  629. onTouchEnd: touchMove ? _this.swipeEnd : null,
  630. onTouchCancel: _this.state.dragging && touchMove ? _this.swipeEnd : null,
  631. onKeyDown: _this.props.accessibility ? _this.keyHandler : null
  632. };
  633. var innerSliderProps = {
  634. className: className,
  635. dir: "ltr"
  636. };
  637. if (_this.props.unslick) {
  638. listProps = {
  639. className: "slick-list"
  640. };
  641. innerSliderProps = {
  642. className: className
  643. };
  644. }
  645. return _react.default.createElement("div", innerSliderProps, !_this.props.unslick ? prevArrow : "", _react.default.createElement("div", _extends({
  646. ref: _this.listRefHandler
  647. }, listProps), _react.default.createElement(_track.Track, _extends({
  648. ref: _this.trackRefHandler
  649. }, trackProps), _this.props.children)), !_this.props.unslick ? nextArrow : "", !_this.props.unslick ? dots : "");
  650. });
  651. _this.list = null;
  652. _this.track = null;
  653. _this.state = _objectSpread({}, _initialState.default, {
  654. currentSlide: _this.props.initialSlide,
  655. slideCount: _react.default.Children.count(_this.props.children)
  656. });
  657. _this.callbackTimers = [];
  658. _this.clickable = true;
  659. _this.debouncedResize = null;
  660. return _this;
  661. }
  662. return InnerSlider;
  663. }(_react.default.Component);
  664. exports.InnerSlider = InnerSlider;