inner-slider.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.default = void 0;
  7. var _vue = require("vue");
  8. var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
  9. var _debounce = _interopRequireDefault(require("lodash/debounce"));
  10. var _resizeObserverPolyfill = _interopRequireDefault(require("resize-observer-polyfill"));
  11. var _classNames = _interopRequireDefault(require("../_util/classNames"));
  12. var _BaseMixin = _interopRequireDefault(require("../_util/BaseMixin"));
  13. var _defaultProps = _interopRequireDefault(require("./default-props"));
  14. var _initialState = _interopRequireDefault(require("./initial-state"));
  15. var _innerSliderUtils = require("./utils/innerSliderUtils");
  16. var _track = _interopRequireDefault(require("./track"));
  17. var _dots = _interopRequireDefault(require("./dots"));
  18. var _arrows = require("./arrows");
  19. var _supportsPassive = _interopRequireDefault(require("../_util/supportsPassive"));
  20. var __rest = void 0 && (void 0).__rest || function (s, e) {
  21. var t = {};
  22. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
  23. if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  24. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
  25. }
  26. return t;
  27. };
  28. function noop() {}
  29. var _default = exports.default = {
  30. name: 'InnerSlider',
  31. mixins: [_BaseMixin.default],
  32. inheritAttrs: false,
  33. props: (0, _extends2.default)({}, _defaultProps.default),
  34. data() {
  35. this.preProps = (0, _extends2.default)({}, this.$props);
  36. this.list = null;
  37. this.track = null;
  38. this.callbackTimers = [];
  39. this.clickable = true;
  40. this.debouncedResize = null;
  41. const ssrState = this.ssrInit();
  42. return (0, _extends2.default)((0, _extends2.default)((0, _extends2.default)({}, _initialState.default), {
  43. currentSlide: this.initialSlide,
  44. slideCount: this.children.length
  45. }), ssrState);
  46. },
  47. watch: {
  48. autoplay(newValue, oldValue) {
  49. if (!oldValue && newValue) {
  50. this.handleAutoPlay('playing');
  51. } else if (newValue) {
  52. this.handleAutoPlay('update');
  53. } else {
  54. this.pause('paused');
  55. }
  56. },
  57. __propsSymbol__() {
  58. const nextProps = this.$props;
  59. const spec = (0, _extends2.default)((0, _extends2.default)({
  60. listRef: this.list,
  61. trackRef: this.track
  62. }, nextProps), this.$data);
  63. let setTrackStyle = false;
  64. for (const key of Object.keys(this.preProps)) {
  65. if (!nextProps.hasOwnProperty(key)) {
  66. setTrackStyle = true;
  67. break;
  68. }
  69. if (typeof nextProps[key] === 'object' || typeof nextProps[key] === 'function' || typeof nextProps[key] === 'symbol') {
  70. continue;
  71. }
  72. if (nextProps[key] !== this.preProps[key]) {
  73. setTrackStyle = true;
  74. break;
  75. }
  76. }
  77. this.updateState(spec, setTrackStyle, () => {
  78. if (this.currentSlide >= nextProps.children.length) {
  79. this.changeSlide({
  80. message: 'index',
  81. index: nextProps.children.length - nextProps.slidesToShow,
  82. currentSlide: this.currentSlide
  83. });
  84. }
  85. if (!this.preProps.autoplay && nextProps.autoplay) {
  86. this.handleAutoPlay('playing');
  87. } else if (nextProps.autoplay) {
  88. this.handleAutoPlay('update');
  89. } else {
  90. this.pause('paused');
  91. }
  92. });
  93. this.preProps = (0, _extends2.default)({}, nextProps);
  94. }
  95. },
  96. mounted() {
  97. this.__emit('init');
  98. if (this.lazyLoad) {
  99. const slidesToLoad = (0, _innerSliderUtils.getOnDemandLazySlides)((0, _extends2.default)((0, _extends2.default)({}, this.$props), this.$data));
  100. if (slidesToLoad.length > 0) {
  101. this.setState(prevState => ({
  102. lazyLoadedList: prevState.lazyLoadedList.concat(slidesToLoad)
  103. }));
  104. this.__emit('lazyLoad', slidesToLoad);
  105. }
  106. }
  107. this.$nextTick(() => {
  108. const spec = (0, _extends2.default)({
  109. listRef: this.list,
  110. trackRef: this.track,
  111. children: this.children
  112. }, this.$props);
  113. this.updateState(spec, true, () => {
  114. this.adaptHeight();
  115. this.autoplay && this.handleAutoPlay('playing');
  116. });
  117. if (this.lazyLoad === 'progressive') {
  118. this.lazyLoadTimer = setInterval(this.progressiveLazyLoad, 1000);
  119. }
  120. this.ro = new _resizeObserverPolyfill.default(() => {
  121. if (this.animating) {
  122. this.onWindowResized(false); // don't set trackStyle hence don't break animation
  123. this.callbackTimers.push(setTimeout(() => this.onWindowResized(), this.speed));
  124. } else {
  125. this.onWindowResized();
  126. }
  127. });
  128. this.ro.observe(this.list);
  129. document.querySelectorAll && Array.prototype.forEach.call(document.querySelectorAll('.slick-slide'), slide => {
  130. slide.onfocus = this.$props.pauseOnFocus ? this.onSlideFocus : null;
  131. slide.onblur = this.$props.pauseOnFocus ? this.onSlideBlur : null;
  132. });
  133. if (window.addEventListener) {
  134. window.addEventListener('resize', this.onWindowResized);
  135. } else {
  136. window.attachEvent('onresize', this.onWindowResized);
  137. }
  138. });
  139. },
  140. beforeUnmount() {
  141. var _a;
  142. if (this.animationEndCallback) {
  143. clearTimeout(this.animationEndCallback);
  144. }
  145. if (this.lazyLoadTimer) {
  146. clearInterval(this.lazyLoadTimer);
  147. }
  148. if (this.callbackTimers.length) {
  149. this.callbackTimers.forEach(timer => clearTimeout(timer));
  150. this.callbackTimers = [];
  151. }
  152. if (window.addEventListener) {
  153. window.removeEventListener('resize', this.onWindowResized);
  154. } else {
  155. window.detachEvent('onresize', this.onWindowResized);
  156. }
  157. if (this.autoplayTimer) {
  158. clearInterval(this.autoplayTimer);
  159. }
  160. (_a = this.ro) === null || _a === void 0 ? void 0 : _a.disconnect();
  161. },
  162. updated() {
  163. this.checkImagesLoad();
  164. this.__emit('reInit');
  165. if (this.lazyLoad) {
  166. const slidesToLoad = (0, _innerSliderUtils.getOnDemandLazySlides)((0, _extends2.default)((0, _extends2.default)({}, this.$props), this.$data));
  167. if (slidesToLoad.length > 0) {
  168. this.setState(prevState => ({
  169. lazyLoadedList: prevState.lazyLoadedList.concat(slidesToLoad)
  170. }));
  171. this.__emit('lazyLoad');
  172. }
  173. }
  174. // if (this.props.onLazyLoad) {
  175. // this.props.onLazyLoad([leftMostSlide])
  176. // }
  177. this.adaptHeight();
  178. },
  179. methods: {
  180. listRefHandler(ref) {
  181. this.list = ref;
  182. },
  183. trackRefHandler(ref) {
  184. this.track = ref;
  185. },
  186. adaptHeight() {
  187. if (this.adaptiveHeight && this.list) {
  188. const elem = this.list.querySelector(`[data-index="${this.currentSlide}"]`);
  189. this.list.style.height = (0, _innerSliderUtils.getHeight)(elem) + 'px';
  190. }
  191. },
  192. onWindowResized(setTrackStyle) {
  193. if (this.debouncedResize) this.debouncedResize.cancel();
  194. this.debouncedResize = (0, _debounce.default)(() => this.resizeWindow(setTrackStyle), 50);
  195. this.debouncedResize();
  196. },
  197. resizeWindow() {
  198. let setTrackStyle = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  199. const isTrackMounted = Boolean(this.track);
  200. if (!isTrackMounted) return;
  201. const spec = (0, _extends2.default)((0, _extends2.default)({
  202. listRef: this.list,
  203. trackRef: this.track,
  204. children: this.children
  205. }, this.$props), this.$data);
  206. this.updateState(spec, setTrackStyle, () => {
  207. if (this.autoplay) {
  208. this.handleAutoPlay('update');
  209. } else {
  210. this.pause('paused');
  211. }
  212. });
  213. // animating state should be cleared while resizing, otherwise autoplay stops working
  214. this.setState({
  215. animating: false
  216. });
  217. clearTimeout(this.animationEndCallback);
  218. delete this.animationEndCallback;
  219. },
  220. updateState(spec, setTrackStyle, callback) {
  221. const updatedState = (0, _innerSliderUtils.initializedState)(spec);
  222. spec = (0, _extends2.default)((0, _extends2.default)((0, _extends2.default)({}, spec), updatedState), {
  223. slideIndex: updatedState.currentSlide
  224. });
  225. const targetLeft = (0, _innerSliderUtils.getTrackLeft)(spec);
  226. spec = (0, _extends2.default)((0, _extends2.default)({}, spec), {
  227. left: targetLeft
  228. });
  229. const trackStyle = (0, _innerSliderUtils.getTrackCSS)(spec);
  230. if (setTrackStyle || this.children.length !== spec.children.length) {
  231. updatedState['trackStyle'] = trackStyle;
  232. }
  233. this.setState(updatedState, callback);
  234. },
  235. ssrInit() {
  236. const children = this.children;
  237. if (this.variableWidth) {
  238. let trackWidth = 0;
  239. let trackLeft = 0;
  240. const childrenWidths = [];
  241. const preClones = (0, _innerSliderUtils.getPreClones)((0, _extends2.default)((0, _extends2.default)((0, _extends2.default)({}, this.$props), this.$data), {
  242. slideCount: children.length
  243. }));
  244. const postClones = (0, _innerSliderUtils.getPostClones)((0, _extends2.default)((0, _extends2.default)((0, _extends2.default)({}, this.$props), this.$data), {
  245. slideCount: children.length
  246. }));
  247. children.forEach(child => {
  248. var _a, _b;
  249. const childWidth = ((_b = (_a = child.props.style) === null || _a === void 0 ? void 0 : _a.width) === null || _b === void 0 ? void 0 : _b.split('px')[0]) || 0;
  250. childrenWidths.push(childWidth);
  251. trackWidth += childWidth;
  252. });
  253. for (let i = 0; i < preClones; i++) {
  254. trackLeft += childrenWidths[childrenWidths.length - 1 - i];
  255. trackWidth += childrenWidths[childrenWidths.length - 1 - i];
  256. }
  257. for (let i = 0; i < postClones; i++) {
  258. trackWidth += childrenWidths[i];
  259. }
  260. for (let i = 0; i < this.currentSlide; i++) {
  261. trackLeft += childrenWidths[i];
  262. }
  263. const trackStyle = {
  264. width: trackWidth + 'px',
  265. left: -trackLeft + 'px'
  266. };
  267. if (this.centerMode) {
  268. const currentWidth = `${childrenWidths[this.currentSlide]}px`;
  269. trackStyle.left = `calc(${trackStyle.left} + (100% - ${currentWidth}) / 2 ) `;
  270. }
  271. return {
  272. trackStyle
  273. };
  274. }
  275. const childrenCount = children.length;
  276. const spec = (0, _extends2.default)((0, _extends2.default)((0, _extends2.default)({}, this.$props), this.$data), {
  277. slideCount: childrenCount
  278. });
  279. const slideCount = (0, _innerSliderUtils.getPreClones)(spec) + (0, _innerSliderUtils.getPostClones)(spec) + childrenCount;
  280. const trackWidth = 100 / this.slidesToShow * slideCount;
  281. const slideWidth = 100 / slideCount;
  282. let trackLeft = -slideWidth * ((0, _innerSliderUtils.getPreClones)(spec) + this.currentSlide) * trackWidth / 100;
  283. if (this.centerMode) {
  284. trackLeft += (100 - slideWidth * trackWidth / 100) / 2;
  285. }
  286. const trackStyle = {
  287. width: trackWidth + '%',
  288. left: trackLeft + '%'
  289. };
  290. return {
  291. slideWidth: slideWidth + '%',
  292. trackStyle
  293. };
  294. },
  295. checkImagesLoad() {
  296. const images = this.list && this.list.querySelectorAll && this.list.querySelectorAll('.slick-slide img') || [];
  297. const imagesCount = images.length;
  298. let loadedCount = 0;
  299. Array.prototype.forEach.call(images, image => {
  300. const handler = () => ++loadedCount && loadedCount >= imagesCount && this.onWindowResized();
  301. if (!image.onclick) {
  302. image.onclick = () => image.parentNode.focus();
  303. } else {
  304. const prevClickHandler = image.onclick;
  305. image.onclick = () => {
  306. prevClickHandler();
  307. image.parentNode.focus();
  308. };
  309. }
  310. if (!image.onload) {
  311. if (this.$props.lazyLoad) {
  312. image.onload = () => {
  313. this.adaptHeight();
  314. this.callbackTimers.push(setTimeout(this.onWindowResized, this.speed));
  315. };
  316. } else {
  317. image.onload = handler;
  318. image.onerror = () => {
  319. handler();
  320. this.__emit('lazyLoadError');
  321. };
  322. }
  323. }
  324. });
  325. },
  326. progressiveLazyLoad() {
  327. const slidesToLoad = [];
  328. const spec = (0, _extends2.default)((0, _extends2.default)({}, this.$props), this.$data);
  329. for (let index = this.currentSlide; index < this.slideCount + (0, _innerSliderUtils.getPostClones)(spec); index++) {
  330. if (this.lazyLoadedList.indexOf(index) < 0) {
  331. slidesToLoad.push(index);
  332. break;
  333. }
  334. }
  335. for (let index = this.currentSlide - 1; index >= -(0, _innerSliderUtils.getPreClones)(spec); index--) {
  336. if (this.lazyLoadedList.indexOf(index) < 0) {
  337. slidesToLoad.push(index);
  338. break;
  339. }
  340. }
  341. if (slidesToLoad.length > 0) {
  342. this.setState(state => ({
  343. lazyLoadedList: state.lazyLoadedList.concat(slidesToLoad)
  344. }));
  345. this.__emit('lazyLoad', slidesToLoad);
  346. } else {
  347. if (this.lazyLoadTimer) {
  348. clearInterval(this.lazyLoadTimer);
  349. delete this.lazyLoadTimer;
  350. }
  351. }
  352. },
  353. slideHandler(index) {
  354. let dontAnimate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  355. const {
  356. asNavFor,
  357. beforeChange,
  358. speed,
  359. afterChange
  360. } = this.$props;
  361. const {
  362. state,
  363. nextState
  364. } = (0, _innerSliderUtils.slideHandler)((0, _extends2.default)((0, _extends2.default)((0, _extends2.default)({
  365. index
  366. }, this.$props), this.$data), {
  367. trackRef: this.track,
  368. useCSS: this.useCSS && !dontAnimate
  369. }));
  370. if (!state) return;
  371. beforeChange && beforeChange(this.currentSlide, state.currentSlide);
  372. const slidesToLoad = state.lazyLoadedList.filter(value => this.lazyLoadedList.indexOf(value) < 0);
  373. if (this.$attrs.onLazyLoad && slidesToLoad.length > 0) {
  374. this.__emit('lazyLoad', slidesToLoad);
  375. }
  376. if (!this.$props.waitForAnimate && this.animationEndCallback) {
  377. clearTimeout(this.animationEndCallback);
  378. afterChange && afterChange(this.currentSlide);
  379. delete this.animationEndCallback;
  380. }
  381. this.setState(state, () => {
  382. if (asNavFor && this.asNavForIndex !== index) {
  383. this.asNavForIndex = index;
  384. asNavFor.innerSlider.slideHandler(index);
  385. }
  386. if (!nextState) return;
  387. this.animationEndCallback = setTimeout(() => {
  388. const {
  389. animating
  390. } = nextState,
  391. firstBatch = __rest(nextState, ["animating"]);
  392. this.setState(firstBatch, () => {
  393. this.callbackTimers.push(setTimeout(() => this.setState({
  394. animating
  395. }), 10));
  396. afterChange && afterChange(state.currentSlide);
  397. delete this.animationEndCallback;
  398. });
  399. }, speed);
  400. });
  401. },
  402. changeSlide(options) {
  403. let dontAnimate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  404. const spec = (0, _extends2.default)((0, _extends2.default)({}, this.$props), this.$data);
  405. const targetSlide = (0, _innerSliderUtils.changeSlide)(spec, options);
  406. if (targetSlide !== 0 && !targetSlide) return;
  407. if (dontAnimate === true) {
  408. this.slideHandler(targetSlide, dontAnimate);
  409. } else {
  410. this.slideHandler(targetSlide);
  411. }
  412. this.$props.autoplay && this.handleAutoPlay('update');
  413. if (this.$props.focusOnSelect) {
  414. const nodes = this.list.querySelectorAll('.slick-current');
  415. nodes[0] && nodes[0].focus();
  416. }
  417. },
  418. clickHandler(e) {
  419. if (this.clickable === false) {
  420. e.stopPropagation();
  421. e.preventDefault();
  422. }
  423. this.clickable = true;
  424. },
  425. keyHandler(e) {
  426. const dir = (0, _innerSliderUtils.keyHandler)(e, this.accessibility, this.rtl);
  427. dir !== '' && this.changeSlide({
  428. message: dir
  429. });
  430. },
  431. selectHandler(options) {
  432. this.changeSlide(options);
  433. },
  434. disableBodyScroll() {
  435. const preventDefault = e => {
  436. e = e || window.event;
  437. if (e.preventDefault) e.preventDefault();
  438. e.returnValue = false;
  439. };
  440. window.ontouchmove = preventDefault;
  441. },
  442. enableBodyScroll() {
  443. window.ontouchmove = null;
  444. },
  445. swipeStart(e) {
  446. if (this.verticalSwiping) {
  447. this.disableBodyScroll();
  448. }
  449. const state = (0, _innerSliderUtils.swipeStart)(e, this.swipe, this.draggable);
  450. state !== '' && this.setState(state);
  451. },
  452. swipeMove(e) {
  453. const state = (0, _innerSliderUtils.swipeMove)(e, (0, _extends2.default)((0, _extends2.default)((0, _extends2.default)({}, this.$props), this.$data), {
  454. trackRef: this.track,
  455. listRef: this.list,
  456. slideIndex: this.currentSlide
  457. }));
  458. if (!state) return;
  459. if (state['swiping']) {
  460. this.clickable = false;
  461. }
  462. this.setState(state);
  463. },
  464. swipeEnd(e) {
  465. const state = (0, _innerSliderUtils.swipeEnd)(e, (0, _extends2.default)((0, _extends2.default)((0, _extends2.default)({}, this.$props), this.$data), {
  466. trackRef: this.track,
  467. listRef: this.list,
  468. slideIndex: this.currentSlide
  469. }));
  470. if (!state) return;
  471. const triggerSlideHandler = state['triggerSlideHandler'];
  472. delete state['triggerSlideHandler'];
  473. this.setState(state);
  474. if (triggerSlideHandler === undefined) return;
  475. this.slideHandler(triggerSlideHandler);
  476. if (this.$props.verticalSwiping) {
  477. this.enableBodyScroll();
  478. }
  479. },
  480. touchEnd(e) {
  481. this.swipeEnd(e);
  482. this.clickable = true;
  483. },
  484. slickPrev() {
  485. // this and fellow methods are wrapped in setTimeout
  486. // to make sure initialize setState has happened before
  487. // any of such methods are called
  488. this.callbackTimers.push(setTimeout(() => this.changeSlide({
  489. message: 'previous'
  490. }), 0));
  491. },
  492. slickNext() {
  493. this.callbackTimers.push(setTimeout(() => this.changeSlide({
  494. message: 'next'
  495. }), 0));
  496. },
  497. slickGoTo(slide) {
  498. let dontAnimate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  499. slide = Number(slide);
  500. if (isNaN(slide)) return '';
  501. this.callbackTimers.push(setTimeout(() => this.changeSlide({
  502. message: 'index',
  503. index: slide,
  504. currentSlide: this.currentSlide
  505. }, dontAnimate), 0));
  506. },
  507. play() {
  508. let nextIndex;
  509. if (this.rtl) {
  510. nextIndex = this.currentSlide - this.slidesToScroll;
  511. } else {
  512. if ((0, _innerSliderUtils.canGoNext)((0, _extends2.default)((0, _extends2.default)({}, this.$props), this.$data))) {
  513. nextIndex = this.currentSlide + this.slidesToScroll;
  514. } else {
  515. return false;
  516. }
  517. }
  518. this.slideHandler(nextIndex);
  519. },
  520. handleAutoPlay(playType) {
  521. if (this.autoplayTimer) {
  522. clearInterval(this.autoplayTimer);
  523. }
  524. const autoplaying = this.autoplaying;
  525. if (playType === 'update') {
  526. if (autoplaying === 'hovered' || autoplaying === 'focused' || autoplaying === 'paused') {
  527. return;
  528. }
  529. } else if (playType === 'leave') {
  530. if (autoplaying === 'paused' || autoplaying === 'focused') {
  531. return;
  532. }
  533. } else if (playType === 'blur') {
  534. if (autoplaying === 'paused' || autoplaying === 'hovered') {
  535. return;
  536. }
  537. }
  538. this.autoplayTimer = setInterval(this.play, this.autoplaySpeed + 50);
  539. this.setState({
  540. autoplaying: 'playing'
  541. });
  542. },
  543. pause(pauseType) {
  544. if (this.autoplayTimer) {
  545. clearInterval(this.autoplayTimer);
  546. this.autoplayTimer = null;
  547. }
  548. const autoplaying = this.autoplaying;
  549. if (pauseType === 'paused') {
  550. this.setState({
  551. autoplaying: 'paused'
  552. });
  553. } else if (pauseType === 'focused') {
  554. if (autoplaying === 'hovered' || autoplaying === 'playing') {
  555. this.setState({
  556. autoplaying: 'focused'
  557. });
  558. }
  559. } else {
  560. // pauseType is 'hovered'
  561. if (autoplaying === 'playing') {
  562. this.setState({
  563. autoplaying: 'hovered'
  564. });
  565. }
  566. }
  567. },
  568. onDotsOver() {
  569. this.autoplay && this.pause('hovered');
  570. },
  571. onDotsLeave() {
  572. this.autoplay && this.autoplaying === 'hovered' && this.handleAutoPlay('leave');
  573. },
  574. onTrackOver() {
  575. this.autoplay && this.pause('hovered');
  576. },
  577. onTrackLeave() {
  578. this.autoplay && this.autoplaying === 'hovered' && this.handleAutoPlay('leave');
  579. },
  580. onSlideFocus() {
  581. this.autoplay && this.pause('focused');
  582. },
  583. onSlideBlur() {
  584. this.autoplay && this.autoplaying === 'focused' && this.handleAutoPlay('blur');
  585. },
  586. customPaging(_ref) {
  587. let {
  588. i
  589. } = _ref;
  590. return (0, _vue.createVNode)("button", null, [i + 1]);
  591. },
  592. appendDots(_ref2) {
  593. let {
  594. dots
  595. } = _ref2;
  596. return (0, _vue.createVNode)("ul", {
  597. "style": {
  598. display: 'block'
  599. }
  600. }, [dots]);
  601. }
  602. },
  603. render() {
  604. const className = (0, _classNames.default)('slick-slider', this.$attrs.class, {
  605. 'slick-vertical': this.vertical,
  606. 'slick-initialized': true
  607. });
  608. const spec = (0, _extends2.default)((0, _extends2.default)({}, this.$props), this.$data);
  609. let 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', 'targetSlide', 'useCSS']);
  610. const {
  611. pauseOnHover
  612. } = this.$props;
  613. trackProps = (0, _extends2.default)((0, _extends2.default)({}, trackProps), {
  614. focusOnSelect: this.focusOnSelect && this.clickable ? this.selectHandler : null,
  615. ref: this.trackRefHandler,
  616. onMouseleave: pauseOnHover ? this.onTrackLeave : noop,
  617. onMouseover: pauseOnHover ? this.onTrackOver : noop
  618. });
  619. let dots;
  620. if (this.dots === true && this.slideCount >= this.slidesToShow) {
  621. let dotProps = (0, _innerSliderUtils.extractObject)(spec, ['dotsClass', 'slideCount', 'slidesToShow', 'currentSlide', 'slidesToScroll', 'clickHandler', 'children', 'infinite', 'appendDots']);
  622. dotProps.customPaging = this.customPaging;
  623. dotProps.appendDots = this.appendDots;
  624. const {
  625. customPaging,
  626. appendDots
  627. } = this.$slots;
  628. if (customPaging) {
  629. dotProps.customPaging = customPaging;
  630. }
  631. if (appendDots) {
  632. dotProps.appendDots = appendDots;
  633. }
  634. const {
  635. pauseOnDotsHover
  636. } = this.$props;
  637. dotProps = (0, _extends2.default)((0, _extends2.default)({}, dotProps), {
  638. clickHandler: this.changeSlide,
  639. onMouseover: pauseOnDotsHover ? this.onDotsOver : noop,
  640. onMouseleave: pauseOnDotsHover ? this.onDotsLeave : noop
  641. });
  642. dots = (0, _vue.createVNode)(_dots.default, dotProps, null);
  643. }
  644. let prevArrow, nextArrow;
  645. const arrowProps = (0, _innerSliderUtils.extractObject)(spec, ['infinite', 'centerMode', 'currentSlide', 'slideCount', 'slidesToShow']);
  646. arrowProps.clickHandler = this.changeSlide;
  647. const {
  648. prevArrow: prevArrowCustom,
  649. nextArrow: nextArrowCustom
  650. } = this.$slots;
  651. if (prevArrowCustom) {
  652. arrowProps.prevArrow = prevArrowCustom;
  653. }
  654. if (nextArrowCustom) {
  655. arrowProps.nextArrow = nextArrowCustom;
  656. }
  657. if (this.arrows) {
  658. prevArrow = (0, _vue.createVNode)(_arrows.PrevArrow, arrowProps, null);
  659. nextArrow = (0, _vue.createVNode)(_arrows.NextArrow, arrowProps, null);
  660. }
  661. let verticalHeightStyle = null;
  662. if (this.vertical) {
  663. verticalHeightStyle = {
  664. height: typeof this.listHeight === 'number' ? `${this.listHeight}px` : this.listHeight
  665. };
  666. }
  667. let centerPaddingStyle = null;
  668. if (this.vertical === false) {
  669. if (this.centerMode === true) {
  670. centerPaddingStyle = {
  671. padding: '0px ' + this.centerPadding
  672. };
  673. }
  674. } else {
  675. if (this.centerMode === true) {
  676. centerPaddingStyle = {
  677. padding: this.centerPadding + ' 0px'
  678. };
  679. }
  680. }
  681. const listStyle = (0, _extends2.default)((0, _extends2.default)({}, verticalHeightStyle), centerPaddingStyle);
  682. const touchMove = this.touchMove;
  683. let listProps = {
  684. ref: this.listRefHandler,
  685. class: 'slick-list',
  686. style: listStyle,
  687. onClick: this.clickHandler,
  688. onMousedown: touchMove ? this.swipeStart : noop,
  689. onMousemove: this.dragging && touchMove ? this.swipeMove : noop,
  690. onMouseup: touchMove ? this.swipeEnd : noop,
  691. onMouseleave: this.dragging && touchMove ? this.swipeEnd : noop,
  692. [_supportsPassive.default ? 'onTouchstartPassive' : 'onTouchstart']: touchMove ? this.swipeStart : noop,
  693. [_supportsPassive.default ? 'onTouchmovePassive' : 'onTouchmove']: this.dragging && touchMove ? this.swipeMove : noop,
  694. onTouchend: touchMove ? this.touchEnd : noop,
  695. onTouchcancel: this.dragging && touchMove ? this.swipeEnd : noop,
  696. onKeydown: this.accessibility ? this.keyHandler : noop
  697. };
  698. let innerSliderProps = {
  699. class: className,
  700. dir: 'ltr',
  701. style: this.$attrs.style
  702. };
  703. if (this.unslick) {
  704. listProps = {
  705. class: 'slick-list',
  706. ref: this.listRefHandler
  707. };
  708. innerSliderProps = {
  709. class: className
  710. };
  711. }
  712. return (0, _vue.createVNode)("div", innerSliderProps, [!this.unslick ? prevArrow : '', (0, _vue.createVNode)("div", listProps, [(0, _vue.createVNode)(_track.default, trackProps, {
  713. default: () => [this.children]
  714. })]), !this.unslick ? nextArrow : '', !this.unslick ? dots : '']);
  715. }
  716. };