You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2996 lines
86 KiB

[MIG] web_widget_slick: Migrate to v10 * Add local slick files to use instead of CDN * Override CSS to display widget correctly * Adjust arrow button size/placement * Bump version * Rename __openerp__.py -> __manifest__.py * Rename widget_slick.js -> web_widget_slick.js * Update copyright, license (AGPL -> LGPL) * Update readme * Correct eslint errors * Change module name in various places for consistency * Improve styling of widget arrows, dots * Change css -> less * Remove unneeded slick files * Copyright 2017 -> 2016-2017 * Add OCA to authors * Use OCA icon * Fix readme * Clean up assets * Fix file permissions * Update readme with reference to example module * Fix formatting error, incorrect link * Add javascript tests * Add note to readme about functional testing with example module * Fix/cleanup javascript * Fix destroy_content() method * Move slide navigation out of slide addition loop * Remove unused variables * Remove unneeded DOM append * Reorganize files/directories * Adjust template tags (templates -> template) * Add slick-field class to field template instead of using jQuery * Misc cleanup * Adjust breakpoint settings to show fewer images by default * Enable adaptiveHeight by default * Add .img and .img-responsive classes to images * Fix dragging issues by preventing default mousedown and touchstart event behavior * Set swipeToSlide default to true * Change how slick slides are populated to allow grid mode * Fix issue causing carousel images to display improperly in some situations * Add better functional testing instructions to readme * Add roadmap to readme * Make minor styling changes * Fix issue with template loading w/ PhantomJS * Clean up template, use css class provided by widget * Remove unneeded dependency from tests * Break up render_value method * Break up destroy_content method * Add unslicking to destroy_content, add test * Clean up qweb template formatting * Fix indentation * Change widget name * Add Slick copyright information * Add padding left/right, move arrows in to avoid clipping when widget not in a sheet tag * Apply dot and arrow styles only when needed * Add _resizeCarousel() and related methods to ensure accurate carousel sizing in various views * Resize carousel on core.bus resize * Account for differences in group layouts and labels, sheet/no-sheet layouts * Adjust, clean up less * Clean up js
7 years ago
  1. /* Copyright 2013-2016 Ken Wheeler
  2. * Version 1.7.1
  3. * License MIT (https://opensource.org/licenses/MIT) */
  4. /*
  5. _ _ _ _
  6. ___| (_) ___| | __ (_)___
  7. / __| | |/ __| |/ / | / __|
  8. \__ \ | | (__| < _ | \__ \
  9. |___/_|_|\___|_|\_(_)/ |___/
  10. |__/
  11. Version: 1.7.1
  12. Author: Ken Wheeler
  13. Website: http://kenwheeler.github.io
  14. Docs: http://kenwheeler.github.io/slick
  15. Repo: http://github.com/kenwheeler/slick
  16. Issues: http://github.com/kenwheeler/slick/issues
  17. */
  18. /* global window, document, define, jQuery, setInterval, clearInterval */
  19. ;(function(factory) {
  20. 'use strict';
  21. if (typeof define === 'function' && define.amd) {
  22. define(['jquery'], factory);
  23. } else if (typeof exports !== 'undefined') {
  24. module.exports = factory(require('jquery'));
  25. } else {
  26. factory(jQuery);
  27. }
  28. }(function($) {
  29. 'use strict';
  30. var Slick = window.Slick || {};
  31. Slick = (function() {
  32. var instanceUid = 0;
  33. function Slick(element, settings) {
  34. var _ = this, dataSettings;
  35. _.defaults = {
  36. accessibility: true,
  37. adaptiveHeight: false,
  38. appendArrows: $(element),
  39. appendDots: $(element),
  40. arrows: true,
  41. asNavFor: null,
  42. prevArrow: '<button class="slick-prev" aria-label="Previous" type="button">Previous</button>',
  43. nextArrow: '<button class="slick-next" aria-label="Next" type="button">Next</button>',
  44. autoplay: false,
  45. autoplaySpeed: 3000,
  46. centerMode: false,
  47. centerPadding: '50px',
  48. cssEase: 'ease',
  49. customPaging: function(slider, i) {
  50. return $('<button type="button" />').text(i + 1);
  51. },
  52. dots: false,
  53. dotsClass: 'slick-dots',
  54. draggable: true,
  55. easing: 'linear',
  56. edgeFriction: 0.35,
  57. fade: false,
  58. focusOnSelect: false,
  59. infinite: true,
  60. initialSlide: 0,
  61. lazyLoad: 'ondemand',
  62. mobileFirst: false,
  63. pauseOnHover: true,
  64. pauseOnFocus: true,
  65. pauseOnDotsHover: false,
  66. respondTo: 'window',
  67. responsive: null,
  68. rows: 1,
  69. rtl: false,
  70. slide: '',
  71. slidesPerRow: 1,
  72. slidesToShow: 1,
  73. slidesToScroll: 1,
  74. speed: 500,
  75. swipe: true,
  76. swipeToSlide: false,
  77. touchMove: true,
  78. touchThreshold: 5,
  79. useCSS: true,
  80. useTransform: true,
  81. variableWidth: false,
  82. vertical: false,
  83. verticalSwiping: false,
  84. waitForAnimate: true,
  85. zIndex: 1000
  86. };
  87. _.initials = {
  88. animating: false,
  89. dragging: false,
  90. autoPlayTimer: null,
  91. currentDirection: 0,
  92. currentLeft: null,
  93. currentSlide: 0,
  94. direction: 1,
  95. $dots: null,
  96. listWidth: null,
  97. listHeight: null,
  98. loadIndex: 0,
  99. $nextArrow: null,
  100. $prevArrow: null,
  101. scrolling: false,
  102. slideCount: null,
  103. slideWidth: null,
  104. $slideTrack: null,
  105. $slides: null,
  106. sliding: false,
  107. slideOffset: 0,
  108. swipeLeft: null,
  109. swiping: false,
  110. $list: null,
  111. touchObject: {},
  112. transformsEnabled: false,
  113. unslicked: false
  114. };
  115. $.extend(_, _.initials);
  116. _.activeBreakpoint = null;
  117. _.animType = null;
  118. _.animProp = null;
  119. _.breakpoints = [];
  120. _.breakpointSettings = [];
  121. _.cssTransitions = false;
  122. _.focussed = false;
  123. _.interrupted = false;
  124. _.hidden = 'hidden';
  125. _.paused = true;
  126. _.positionProp = null;
  127. _.respondTo = null;
  128. _.rowCount = 1;
  129. _.shouldClick = true;
  130. _.$slider = $(element);
  131. _.$slidesCache = null;
  132. _.transformType = null;
  133. _.transitionType = null;
  134. _.visibilityChange = 'visibilitychange';
  135. _.windowWidth = 0;
  136. _.windowTimer = null;
  137. dataSettings = $(element).data('slick') || {};
  138. _.options = $.extend({}, _.defaults, settings, dataSettings);
  139. _.currentSlide = _.options.initialSlide;
  140. _.originalSettings = _.options;
  141. if (typeof document.mozHidden !== 'undefined') {
  142. _.hidden = 'mozHidden';
  143. _.visibilityChange = 'mozvisibilitychange';
  144. } else if (typeof document.webkitHidden !== 'undefined') {
  145. _.hidden = 'webkitHidden';
  146. _.visibilityChange = 'webkitvisibilitychange';
  147. }
  148. _.autoPlay = $.proxy(_.autoPlay, _);
  149. _.autoPlayClear = $.proxy(_.autoPlayClear, _);
  150. _.autoPlayIterator = $.proxy(_.autoPlayIterator, _);
  151. _.changeSlide = $.proxy(_.changeSlide, _);
  152. _.clickHandler = $.proxy(_.clickHandler, _);
  153. _.selectHandler = $.proxy(_.selectHandler, _);
  154. _.setPosition = $.proxy(_.setPosition, _);
  155. _.swipeHandler = $.proxy(_.swipeHandler, _);
  156. _.dragHandler = $.proxy(_.dragHandler, _);
  157. _.keyHandler = $.proxy(_.keyHandler, _);
  158. _.instanceUid = instanceUid++;
  159. // A simple way to check for HTML strings
  160. // Strict HTML recognition (must start with <)
  161. // Extracted from jQuery v1.11 source
  162. _.htmlExpr = /^(?:\s*(<[\w\W]+>)[^>]*)$/;
  163. _.registerBreakpoints();
  164. _.init(true);
  165. }
  166. return Slick;
  167. }());
  168. Slick.prototype.activateADA = function() {
  169. var _ = this;
  170. _.$slideTrack.find('.slick-active').attr({
  171. 'aria-hidden': 'false'
  172. }).find('a, input, button, select').attr({
  173. 'tabindex': '0'
  174. });
  175. };
  176. Slick.prototype.addSlide = Slick.prototype.slickAdd = function(markup, index, addBefore) {
  177. var _ = this;
  178. if (typeof(index) === 'boolean') {
  179. addBefore = index;
  180. index = null;
  181. } else if (index < 0 || (index >= _.slideCount)) {
  182. return false;
  183. }
  184. _.unload();
  185. if (typeof(index) === 'number') {
  186. if (index === 0 && _.$slides.length === 0) {
  187. $(markup).appendTo(_.$slideTrack);
  188. } else if (addBefore) {
  189. $(markup).insertBefore(_.$slides.eq(index));
  190. } else {
  191. $(markup).insertAfter(_.$slides.eq(index));
  192. }
  193. } else {
  194. if (addBefore === true) {
  195. $(markup).prependTo(_.$slideTrack);
  196. } else {
  197. $(markup).appendTo(_.$slideTrack);
  198. }
  199. }
  200. _.$slides = _.$slideTrack.children(this.options.slide);
  201. _.$slideTrack.children(this.options.slide).detach();
  202. _.$slideTrack.append(_.$slides);
  203. _.$slides.each(function(index, element) {
  204. $(element).attr('data-slick-index', index);
  205. });
  206. _.$slidesCache = _.$slides;
  207. _.reinit();
  208. };
  209. Slick.prototype.animateHeight = function() {
  210. var _ = this;
  211. if (_.options.slidesToShow === 1 && _.options.adaptiveHeight === true && _.options.vertical === false) {
  212. var targetHeight = _.$slides.eq(_.currentSlide).outerHeight(true);
  213. _.$list.animate({
  214. height: targetHeight
  215. }, _.options.speed);
  216. }
  217. };
  218. Slick.prototype.animateSlide = function(targetLeft, callback) {
  219. var animProps = {},
  220. _ = this;
  221. _.animateHeight();
  222. if (_.options.rtl === true && _.options.vertical === false) {
  223. targetLeft = -targetLeft;
  224. }
  225. if (_.transformsEnabled === false) {
  226. if (_.options.vertical === false) {
  227. _.$slideTrack.animate({
  228. left: targetLeft
  229. }, _.options.speed, _.options.easing, callback);
  230. } else {
  231. _.$slideTrack.animate({
  232. top: targetLeft
  233. }, _.options.speed, _.options.easing, callback);
  234. }
  235. } else {
  236. if (_.cssTransitions === false) {
  237. if (_.options.rtl === true) {
  238. _.currentLeft = -(_.currentLeft);
  239. }
  240. $({
  241. animStart: _.currentLeft
  242. }).animate({
  243. animStart: targetLeft
  244. }, {
  245. duration: _.options.speed,
  246. easing: _.options.easing,
  247. step: function(now) {
  248. now = Math.ceil(now);
  249. if (_.options.vertical === false) {
  250. animProps[_.animType] = 'translate(' +
  251. now + 'px, 0px)';
  252. _.$slideTrack.css(animProps);
  253. } else {
  254. animProps[_.animType] = 'translate(0px,' +
  255. now + 'px)';
  256. _.$slideTrack.css(animProps);
  257. }
  258. },
  259. complete: function() {
  260. if (callback) {
  261. callback.call();
  262. }
  263. }
  264. });
  265. } else {
  266. _.applyTransition();
  267. targetLeft = Math.ceil(targetLeft);
  268. if (_.options.vertical === false) {
  269. animProps[_.animType] = 'translate3d(' + targetLeft + 'px, 0px, 0px)';
  270. } else {
  271. animProps[_.animType] = 'translate3d(0px,' + targetLeft + 'px, 0px)';
  272. }
  273. _.$slideTrack.css(animProps);
  274. if (callback) {
  275. setTimeout(function() {
  276. _.disableTransition();
  277. callback.call();
  278. }, _.options.speed);
  279. }
  280. }
  281. }
  282. };
  283. Slick.prototype.getNavTarget = function() {
  284. var _ = this,
  285. asNavFor = _.options.asNavFor;
  286. if ( asNavFor && asNavFor !== null ) {
  287. asNavFor = $(asNavFor).not(_.$slider);
  288. }
  289. return asNavFor;
  290. };
  291. Slick.prototype.asNavFor = function(index) {
  292. var _ = this,
  293. asNavFor = _.getNavTarget();
  294. if ( asNavFor !== null && typeof asNavFor === 'object' ) {
  295. asNavFor.each(function() {
  296. var target = $(this).slick('getSlick');
  297. if(!target.unslicked) {
  298. target.slideHandler(index, true);
  299. }
  300. });
  301. }
  302. };
  303. Slick.prototype.applyTransition = function(slide) {
  304. var _ = this,
  305. transition = {};
  306. if (_.options.fade === false) {
  307. transition[_.transitionType] = _.transformType + ' ' + _.options.speed + 'ms ' + _.options.cssEase;
  308. } else {
  309. transition[_.transitionType] = 'opacity ' + _.options.speed + 'ms ' + _.options.cssEase;
  310. }
  311. if (_.options.fade === false) {
  312. _.$slideTrack.css(transition);
  313. } else {
  314. _.$slides.eq(slide).css(transition);
  315. }
  316. };
  317. Slick.prototype.autoPlay = function() {
  318. var _ = this;
  319. _.autoPlayClear();
  320. if ( _.slideCount > _.options.slidesToShow ) {
  321. _.autoPlayTimer = setInterval( _.autoPlayIterator, _.options.autoplaySpeed );
  322. }
  323. };
  324. Slick.prototype.autoPlayClear = function() {
  325. var _ = this;
  326. if (_.autoPlayTimer) {
  327. clearInterval(_.autoPlayTimer);
  328. }
  329. };
  330. Slick.prototype.autoPlayIterator = function() {
  331. var _ = this,
  332. slideTo = _.currentSlide + _.options.slidesToScroll;
  333. if ( !_.paused && !_.interrupted && !_.focussed ) {
  334. if ( _.options.infinite === false ) {
  335. if ( _.direction === 1 && ( _.currentSlide + 1 ) === ( _.slideCount - 1 )) {
  336. _.direction = 0;
  337. }
  338. else if ( _.direction === 0 ) {
  339. slideTo = _.currentSlide - _.options.slidesToScroll;
  340. if ( _.currentSlide - 1 === 0 ) {
  341. _.direction = 1;
  342. }
  343. }
  344. }
  345. _.slideHandler( slideTo );
  346. }
  347. };
  348. Slick.prototype.buildArrows = function() {
  349. var _ = this;
  350. if (_.options.arrows === true ) {
  351. _.$prevArrow = $(_.options.prevArrow).addClass('slick-arrow');
  352. _.$nextArrow = $(_.options.nextArrow).addClass('slick-arrow');
  353. if( _.slideCount > _.options.slidesToShow ) {
  354. _.$prevArrow.removeClass('slick-hidden').removeAttr('aria-hidden tabindex');
  355. _.$nextArrow.removeClass('slick-hidden').removeAttr('aria-hidden tabindex');
  356. if (_.htmlExpr.test(_.options.prevArrow)) {
  357. _.$prevArrow.prependTo(_.options.appendArrows);
  358. }
  359. if (_.htmlExpr.test(_.options.nextArrow)) {
  360. _.$nextArrow.appendTo(_.options.appendArrows);
  361. }
  362. if (_.options.infinite !== true) {
  363. _.$prevArrow
  364. .addClass('slick-disabled')
  365. .attr('aria-disabled', 'true');
  366. }
  367. } else {
  368. _.$prevArrow.add( _.$nextArrow )
  369. .addClass('slick-hidden')
  370. .attr({
  371. 'aria-disabled': 'true',
  372. 'tabindex': '-1'
  373. });
  374. }
  375. }
  376. };
  377. Slick.prototype.buildDots = function() {
  378. var _ = this,
  379. i, dot;
  380. if (_.options.dots === true) {
  381. _.$slider.addClass('slick-dotted');
  382. dot = $('<ul />').addClass(_.options.dotsClass);
  383. for (i = 0; i <= _.getDotCount(); i += 1) {
  384. dot.append($('<li />').append(_.options.customPaging.call(this, _, i)));
  385. }
  386. _.$dots = dot.appendTo(_.options.appendDots);
  387. _.$dots.find('li').first().addClass('slick-active');
  388. }
  389. };
  390. Slick.prototype.buildOut = function() {
  391. var _ = this;
  392. _.$slides =
  393. _.$slider
  394. .children( _.options.slide + ':not(.slick-cloned)')
  395. .addClass('slick-slide');
  396. _.slideCount = _.$slides.length;
  397. _.$slides.each(function(index, element) {
  398. $(element)
  399. .attr('data-slick-index', index)
  400. .data('originalStyling', $(element).attr('style') || '');
  401. });
  402. _.$slider.addClass('slick-slider');
  403. _.$slideTrack = (_.slideCount === 0) ?
  404. $('<div class="slick-track"/>').appendTo(_.$slider) :
  405. _.$slides.wrapAll('<div class="slick-track"/>').parent();
  406. _.$list = _.$slideTrack.wrap(
  407. '<div class="slick-list"/>').parent();
  408. _.$slideTrack.css('opacity', 0);
  409. if (_.options.centerMode === true || _.options.swipeToSlide === true) {
  410. _.options.slidesToScroll = 1;
  411. }
  412. $('img[data-lazy]', _.$slider).not('[src]').addClass('slick-loading');
  413. _.setupInfinite();
  414. _.buildArrows();
  415. _.buildDots();
  416. _.updateDots();
  417. _.setSlideClasses(typeof _.currentSlide === 'number' ? _.currentSlide : 0);
  418. if (_.options.draggable === true) {
  419. _.$list.addClass('draggable');
  420. }
  421. };
  422. Slick.prototype.buildRows = function() {
  423. var _ = this, a, b, c, newSlides, numOfSlides, originalSlides,slidesPerSection;
  424. newSlides = document.createDocumentFragment();
  425. originalSlides = _.$slider.children();
  426. if(_.options.rows > 1) {
  427. slidesPerSection = _.options.slidesPerRow * _.options.rows;
  428. numOfSlides = Math.ceil(
  429. originalSlides.length / slidesPerSection
  430. );
  431. for(a = 0; a < numOfSlides; a++){
  432. var slide = document.createElement('div');
  433. for(b = 0; b < _.options.rows; b++) {
  434. var row = document.createElement('div');
  435. for(c = 0; c < _.options.slidesPerRow; c++) {
  436. var target = (a * slidesPerSection + ((b * _.options.slidesPerRow) + c));
  437. if (originalSlides.get(target)) {
  438. row.appendChild(originalSlides.get(target));
  439. }
  440. }
  441. slide.appendChild(row);
  442. }
  443. newSlides.appendChild(slide);
  444. }
  445. _.$slider.empty().append(newSlides);
  446. _.$slider.children().children().children()
  447. .css({
  448. 'width':(100 / _.options.slidesPerRow) + '%',
  449. 'display': 'inline-block'
  450. });
  451. }
  452. };
  453. Slick.prototype.checkResponsive = function(initial, forceUpdate) {
  454. var _ = this,
  455. breakpoint, targetBreakpoint, respondToWidth, triggerBreakpoint = false;
  456. var sliderWidth = _.$slider.width();
  457. var windowWidth = window.innerWidth || $(window).width();
  458. if (_.respondTo === 'window') {
  459. respondToWidth = windowWidth;
  460. } else if (_.respondTo === 'slider') {
  461. respondToWidth = sliderWidth;
  462. } else if (_.respondTo === 'min') {
  463. respondToWidth = Math.min(windowWidth, sliderWidth);
  464. }
  465. if ( _.options.responsive &&
  466. _.options.responsive.length &&
  467. _.options.responsive !== null) {
  468. targetBreakpoint = null;
  469. for (breakpoint in _.breakpoints) {
  470. if (_.breakpoints.hasOwnProperty(breakpoint)) {
  471. if (_.originalSettings.mobileFirst === false) {
  472. if (respondToWidth < _.breakpoints[breakpoint]) {
  473. targetBreakpoint = _.breakpoints[breakpoint];
  474. }
  475. } else {
  476. if (respondToWidth > _.breakpoints[breakpoint]) {
  477. targetBreakpoint = _.breakpoints[breakpoint];
  478. }
  479. }
  480. }
  481. }
  482. if (targetBreakpoint !== null) {
  483. if (_.activeBreakpoint !== null) {
  484. if (targetBreakpoint !== _.activeBreakpoint || forceUpdate) {
  485. _.activeBreakpoint =
  486. targetBreakpoint;
  487. if (_.breakpointSettings[targetBreakpoint] === 'unslick') {
  488. _.unslick(targetBreakpoint);
  489. } else {
  490. _.options = $.extend({}, _.originalSettings,
  491. _.breakpointSettings[
  492. targetBreakpoint]);
  493. if (initial === true) {
  494. _.currentSlide = _.options.initialSlide;
  495. }
  496. _.refresh(initial);
  497. }
  498. triggerBreakpoint = targetBreakpoint;
  499. }
  500. } else {
  501. _.activeBreakpoint = targetBreakpoint;
  502. if (_.breakpointSettings[targetBreakpoint] === 'unslick') {
  503. _.unslick(targetBreakpoint);
  504. } else {
  505. _.options = $.extend({}, _.originalSettings,
  506. _.breakpointSettings[
  507. targetBreakpoint]);
  508. if (initial === true) {
  509. _.currentSlide = _.options.initialSlide;
  510. }
  511. _.refresh(initial);
  512. }
  513. triggerBreakpoint = targetBreakpoint;
  514. }
  515. } else {
  516. if (_.activeBreakpoint !== null) {
  517. _.activeBreakpoint = null;
  518. _.options = _.originalSettings;
  519. if (initial === true) {
  520. _.currentSlide = _.options.initialSlide;
  521. }
  522. _.refresh(initial);
  523. triggerBreakpoint = targetBreakpoint;
  524. }
  525. }
  526. // only trigger breakpoints during an actual break. not on initialize.
  527. if( !initial && triggerBreakpoint !== false ) {
  528. _.$slider.trigger('breakpoint', [_, triggerBreakpoint]);
  529. }
  530. }
  531. };
  532. Slick.prototype.changeSlide = function(event, dontAnimate) {
  533. var _ = this,
  534. $target = $(event.currentTarget),
  535. indexOffset, slideOffset, unevenOffset;
  536. // If target is a link, prevent default action.
  537. if($target.is('a')) {
  538. event.preventDefault();
  539. }
  540. // If target is not the <li> element (ie: a child), find the <li>.
  541. if(!$target.is('li')) {
  542. $target = $target.closest('li');
  543. }
  544. unevenOffset = (_.slideCount % _.options.slidesToScroll !== 0);
  545. indexOffset = unevenOffset ? 0 : (_.slideCount - _.currentSlide) % _.options.slidesToScroll;
  546. switch (event.data.message) {
  547. case 'previous':
  548. slideOffset = indexOffset === 0 ? _.options.slidesToScroll : _.options.slidesToShow - indexOffset;
  549. if (_.slideCount > _.options.slidesToShow) {
  550. _.slideHandler(_.currentSlide - slideOffset, false, dontAnimate);
  551. }
  552. break;
  553. case 'next':
  554. slideOffset = indexOffset === 0 ? _.options.slidesToScroll : indexOffset;
  555. if (_.slideCount > _.options.slidesToShow) {
  556. _.slideHandler(_.currentSlide + slideOffset, false, dontAnimate);
  557. }
  558. break;
  559. case 'index':
  560. var index = event.data.index === 0 ? 0 :
  561. event.data.index || $target.index() * _.options.slidesToScroll;
  562. _.slideHandler(_.checkNavigable(index), false, dontAnimate);
  563. $target.children().trigger('focus');
  564. break;
  565. default:
  566. return;
  567. }
  568. };
  569. Slick.prototype.checkNavigable = function(index) {
  570. var _ = this,
  571. navigables, prevNavigable;
  572. navigables = _.getNavigableIndexes();
  573. prevNavigable = 0;
  574. if (index > navigables[navigables.length - 1]) {
  575. index = navigables[navigables.length - 1];
  576. } else {
  577. for (var n in navigables) {
  578. if (index < navigables[n]) {
  579. index = prevNavigable;
  580. break;
  581. }
  582. prevNavigable = navigables[n];
  583. }
  584. }
  585. return index;
  586. };
  587. Slick.prototype.cleanUpEvents = function() {
  588. var _ = this;
  589. if (_.options.dots && _.$dots !== null) {
  590. $('li', _.$dots)
  591. .off('click.slick', _.changeSlide)
  592. .off('mouseenter.slick', $.proxy(_.interrupt, _, true))
  593. .off('mouseleave.slick', $.proxy(_.interrupt, _, false));
  594. if (_.options.accessibility === true) {
  595. _.$dots.off('keydown.slick', _.keyHandler);
  596. }
  597. }
  598. _.$slider.off('focus.slick blur.slick');
  599. if (_.options.arrows === true && _.slideCount > _.options.slidesToShow) {
  600. _.$prevArrow && _.$prevArrow.off('click.slick', _.changeSlide);
  601. _.$nextArrow && _.$nextArrow.off('click.slick', _.changeSlide);
  602. if (_.options.accessibility === true) {
  603. _.$prevArrow.off('keydown.slick', _.keyHandler);
  604. _.$nextArrow.off('keydown.slick', _.keyHandler);
  605. }
  606. }
  607. _.$list.off('touchstart.slick mousedown.slick', _.swipeHandler);
  608. _.$list.off('touchmove.slick mousemove.slick', _.swipeHandler);
  609. _.$list.off('touchend.slick mouseup.slick', _.swipeHandler);
  610. _.$list.off('touchcancel.slick mouseleave.slick', _.swipeHandler);
  611. _.$list.off('click.slick', _.clickHandler);
  612. $(document).off(_.visibilityChange, _.visibility);
  613. _.cleanUpSlideEvents();
  614. if (_.options.accessibility === true) {
  615. _.$list.off('keydown.slick', _.keyHandler);
  616. }
  617. if (_.options.focusOnSelect === true) {
  618. $(_.$slideTrack).children().off('click.slick', _.selectHandler);
  619. }
  620. $(window).off('orientationchange.slick.slick-' + _.instanceUid, _.orientationChange);
  621. $(window).off('resize.slick.slick-' + _.instanceUid, _.resize);
  622. $('[draggable!=true]', _.$slideTrack).off('dragstart', _.preventDefault);
  623. $(window).off('load.slick.slick-' + _.instanceUid, _.setPosition);
  624. };
  625. Slick.prototype.cleanUpSlideEvents = function() {
  626. var _ = this;
  627. _.$list.off('mouseenter.slick', $.proxy(_.interrupt, _, true));
  628. _.$list.off('mouseleave.slick', $.proxy(_.interrupt, _, false));
  629. };
  630. Slick.prototype.cleanUpRows = function() {
  631. var _ = this, originalSlides;
  632. if(_.options.rows > 1) {
  633. originalSlides = _.$slides.children().children();
  634. originalSlides.removeAttr('style');
  635. _.$slider.empty().append(originalSlides);
  636. }
  637. };
  638. Slick.prototype.clickHandler = function(event) {
  639. var _ = this;
  640. if (_.shouldClick === false) {
  641. event.stopImmediatePropagation();
  642. event.stopPropagation();
  643. event.preventDefault();
  644. }
  645. };
  646. Slick.prototype.destroy = function(refresh) {
  647. var _ = this;
  648. _.autoPlayClear();
  649. _.touchObject = {};
  650. _.cleanUpEvents();
  651. $('.slick-cloned', _.$slider).detach();
  652. if (_.$dots) {
  653. _.$dots.remove();
  654. }
  655. if ( _.$prevArrow && _.$prevArrow.length ) {
  656. _.$prevArrow
  657. .removeClass('slick-disabled slick-arrow slick-hidden')
  658. .removeAttr('aria-hidden aria-disabled tabindex')
  659. .css('display','');
  660. if ( _.htmlExpr.test( _.options.prevArrow )) {
  661. _.$prevArrow.remove();
  662. }
  663. }
  664. if ( _.$nextArrow && _.$nextArrow.length ) {
  665. _.$nextArrow
  666. .removeClass('slick-disabled slick-arrow slick-hidden')
  667. .removeAttr('aria-hidden aria-disabled tabindex')
  668. .css('display','');
  669. if ( _.htmlExpr.test( _.options.nextArrow )) {
  670. _.$nextArrow.remove();
  671. }
  672. }
  673. if (_.$slides) {
  674. _.$slides
  675. .removeClass('slick-slide slick-active slick-center slick-visible slick-current')
  676. .removeAttr('aria-hidden')
  677. .removeAttr('data-slick-index')
  678. .each(function(){
  679. $(this).attr('style', $(this).data('originalStyling'));
  680. });
  681. _.$slideTrack.children(this.options.slide).detach();
  682. _.$slideTrack.detach();
  683. _.$list.detach();
  684. _.$slider.append(_.$slides);
  685. }
  686. _.cleanUpRows();
  687. _.$slider.removeClass('slick-slider');
  688. _.$slider.removeClass('slick-initialized');
  689. _.$slider.removeClass('slick-dotted');
  690. _.unslicked = true;
  691. if(!refresh) {
  692. _.$slider.trigger('destroy', [_]);
  693. }
  694. };
  695. Slick.prototype.disableTransition = function(slide) {
  696. var _ = this,
  697. transition = {};
  698. transition[_.transitionType] = '';
  699. if (_.options.fade === false) {
  700. _.$slideTrack.css(transition);
  701. } else {
  702. _.$slides.eq(slide).css(transition);
  703. }
  704. };
  705. Slick.prototype.fadeSlide = function(slideIndex, callback) {
  706. var _ = this;
  707. if (_.cssTransitions === false) {
  708. _.$slides.eq(slideIndex).css({
  709. zIndex: _.options.zIndex
  710. });
  711. _.$slides.eq(slideIndex).animate({
  712. opacity: 1
  713. }, _.options.speed, _.options.easing, callback);
  714. } else {
  715. _.applyTransition(slideIndex);
  716. _.$slides.eq(slideIndex).css({
  717. opacity: 1,
  718. zIndex: _.options.zIndex
  719. });
  720. if (callback) {
  721. setTimeout(function() {
  722. _.disableTransition(slideIndex);
  723. callback.call();
  724. }, _.options.speed);
  725. }
  726. }
  727. };
  728. Slick.prototype.fadeSlideOut = function(slideIndex) {
  729. var _ = this;
  730. if (_.cssTransitions === false) {
  731. _.$slides.eq(slideIndex).animate({
  732. opacity: 0,
  733. zIndex: _.options.zIndex - 2
  734. }, _.options.speed, _.options.easing);
  735. } else {
  736. _.applyTransition(slideIndex);
  737. _.$slides.eq(slideIndex).css({
  738. opacity: 0,
  739. zIndex: _.options.zIndex - 2
  740. });
  741. }
  742. };
  743. Slick.prototype.filterSlides = Slick.prototype.slickFilter = function(filter) {
  744. var _ = this;
  745. if (filter !== null) {
  746. _.$slidesCache = _.$slides;
  747. _.unload();
  748. _.$slideTrack.children(this.options.slide).detach();
  749. _.$slidesCache.filter(filter).appendTo(_.$slideTrack);
  750. _.reinit();
  751. }
  752. };
  753. Slick.prototype.focusHandler = function() {
  754. var _ = this;
  755. _.$slider
  756. .off('focus.slick blur.slick')
  757. .on('focus.slick blur.slick', '*', function(event) {
  758. event.stopImmediatePropagation();
  759. var $sf = $(this);
  760. setTimeout(function() {
  761. if( _.options.pauseOnFocus ) {
  762. _.focussed = $sf.is(':focus');
  763. _.autoPlay();
  764. }
  765. }, 0);
  766. });
  767. };
  768. Slick.prototype.getCurrent = Slick.prototype.slickCurrentSlide = function() {
  769. var _ = this;
  770. return _.currentSlide;
  771. };
  772. Slick.prototype.getDotCount = function() {
  773. var _ = this;
  774. var breakPoint = 0;
  775. var counter = 0;
  776. var pagerQty = 0;
  777. if (_.options.infinite === true) {
  778. if (_.slideCount <= _.options.slidesToShow) {
  779. ++pagerQty;
  780. } else {
  781. while (breakPoint < _.slideCount) {
  782. ++pagerQty;
  783. breakPoint = counter + _.options.slidesToScroll;
  784. counter += _.options.slidesToScroll <= _.options.slidesToShow ? _.options.slidesToScroll : _.options.slidesToShow;
  785. }
  786. }
  787. } else if (_.options.centerMode === true) {
  788. pagerQty = _.slideCount;
  789. } else if(!_.options.asNavFor) {
  790. pagerQty = 1 + Math.ceil((_.slideCount - _.options.slidesToShow) / _.options.slidesToScroll);
  791. }else {
  792. while (breakPoint < _.slideCount) {
  793. ++pagerQty;
  794. breakPoint = counter + _.options.slidesToScroll;
  795. counter += _.options.slidesToScroll <= _.options.slidesToShow ? _.options.slidesToScroll : _.options.slidesToShow;
  796. }
  797. }
  798. return pagerQty - 1;
  799. };
  800. Slick.prototype.getLeft = function(slideIndex) {
  801. var _ = this,
  802. targetLeft,
  803. verticalHeight,
  804. verticalOffset = 0,
  805. targetSlide;
  806. _.slideOffset = 0;
  807. verticalHeight = _.$slides.first().outerHeight(true);
  808. if (_.options.infinite === true) {
  809. if (_.slideCount > _.options.slidesToShow) {
  810. _.slideOffset = (_.slideWidth * _.options.slidesToShow) * -1;
  811. verticalOffset = (verticalHeight * _.options.slidesToShow) * -1;
  812. }
  813. if (_.slideCount % _.options.slidesToScroll !== 0) {
  814. if (slideIndex + _.options.slidesToScroll > _.slideCount && _.slideCount > _.options.slidesToShow) {
  815. if (slideIndex > _.slideCount) {
  816. _.slideOffset = ((_.options.slidesToShow - (slideIndex - _.slideCount)) * _.slideWidth) * -1;
  817. verticalOffset = ((_.options.slidesToShow - (slideIndex - _.slideCount)) * verticalHeight) * -1;
  818. } else {
  819. _.slideOffset = ((_.slideCount % _.options.slidesToScroll) * _.slideWidth) * -1;
  820. verticalOffset = ((_.slideCount % _.options.slidesToScroll) * verticalHeight) * -1;
  821. }
  822. }
  823. }
  824. } else {
  825. if (slideIndex + _.options.slidesToShow > _.slideCount) {
  826. _.slideOffset = ((slideIndex + _.options.slidesToShow) - _.slideCount) * _.slideWidth;
  827. verticalOffset = ((slideIndex + _.options.slidesToShow) - _.slideCount) * verticalHeight;
  828. }
  829. }
  830. if (_.slideCount <= _.options.slidesToShow) {
  831. _.slideOffset = 0;
  832. verticalOffset = 0;
  833. }
  834. if (_.options.centerMode === true && _.slideCount <= _.options.slidesToShow) {
  835. _.slideOffset = ((_.slideWidth * Math.floor(_.options.slidesToShow)) / 2) - ((_.slideWidth * _.slideCount) / 2);
  836. } else if (_.options.centerMode === true && _.options.infinite === true) {
  837. _.slideOffset += _.slideWidth * Math.floor(_.options.slidesToShow / 2) - _.slideWidth;
  838. } else if (_.options.centerMode === true) {
  839. _.slideOffset = 0;
  840. _.slideOffset += _.slideWidth * Math.floor(_.options.slidesToShow / 2);
  841. }
  842. if (_.options.vertical === false) {
  843. targetLeft = ((slideIndex * _.slideWidth) * -1) + _.slideOffset;
  844. } else {
  845. targetLeft = ((slideIndex * verticalHeight) * -1) + verticalOffset;
  846. }
  847. if (_.options.variableWidth === true) {
  848. if (_.slideCount <= _.options.slidesToShow || _.options.infinite === false) {
  849. targetSlide = _.$slideTrack.children('.slick-slide').eq(slideIndex);
  850. } else {
  851. targetSlide = _.$slideTrack.children('.slick-slide').eq(slideIndex + _.options.slidesToShow);
  852. }
  853. if (_.options.rtl === true) {
  854. if (targetSlide[0]) {
  855. targetLeft = (_.$slideTrack.width() - targetSlide[0].offsetLeft - targetSlide.width()) * -1;
  856. } else {
  857. targetLeft = 0;
  858. }
  859. } else {
  860. targetLeft = targetSlide[0] ? targetSlide[0].offsetLeft * -1 : 0;
  861. }
  862. if (_.options.centerMode === true) {
  863. if (_.slideCount <= _.options.slidesToShow || _.options.infinite === false) {
  864. targetSlide = _.$slideTrack.children('.slick-slide').eq(slideIndex);
  865. } else {
  866. targetSlide = _.$slideTrack.children('.slick-slide').eq(slideIndex + _.options.slidesToShow + 1);
  867. }
  868. if (_.options.rtl === true) {
  869. if (targetSlide[0]) {
  870. targetLeft = (_.$slideTrack.width() - targetSlide[0].offsetLeft - targetSlide.width()) * -1;
  871. } else {
  872. targetLeft = 0;
  873. }
  874. } else {
  875. targetLeft = targetSlide[0] ? targetSlide[0].offsetLeft * -1 : 0;
  876. }
  877. targetLeft += (_.$list.width() - targetSlide.outerWidth()) / 2;
  878. }
  879. }
  880. return targetLeft;
  881. };
  882. Slick.prototype.getOption = Slick.prototype.slickGetOption = function(option) {
  883. var _ = this;
  884. return _.options[option];
  885. };
  886. Slick.prototype.getNavigableIndexes = function() {
  887. var _ = this,
  888. breakPoint = 0,
  889. counter = 0,
  890. indexes = [],
  891. max;
  892. if (_.options.infinite === false) {
  893. max = _.slideCount;
  894. } else {
  895. breakPoint = _.options.slidesToScroll * -1;
  896. counter = _.options.slidesToScroll * -1;
  897. max = _.slideCount * 2;
  898. }
  899. while (breakPoint < max) {
  900. indexes.push(breakPoint);
  901. breakPoint = counter + _.options.slidesToScroll;
  902. counter += _.options.slidesToScroll <= _.options.slidesToShow ? _.options.slidesToScroll : _.options.slidesToShow;
  903. }
  904. return indexes;
  905. };
  906. Slick.prototype.getSlick = function() {
  907. return this;
  908. };
  909. Slick.prototype.getSlideCount = function() {
  910. var _ = this,
  911. slidesTraversed, swipedSlide, centerOffset;
  912. centerOffset = _.options.centerMode === true ? _.slideWidth * Math.floor(_.options.slidesToShow / 2) : 0;
  913. if (_.options.swipeToSlide === true) {
  914. _.$slideTrack.find('.slick-slide').each(function(index, slide) {
  915. if (slide.offsetLeft - centerOffset + ($(slide).outerWidth() / 2) > (_.swipeLeft * -1)) {
  916. swipedSlide = slide;
  917. return false;
  918. }
  919. });
  920. slidesTraversed = Math.abs($(swipedSlide).attr('data-slick-index') - _.currentSlide) || 1;
  921. return slidesTraversed;
  922. } else {
  923. return _.options.slidesToScroll;
  924. }
  925. };
  926. Slick.prototype.goTo = Slick.prototype.slickGoTo = function(slide, dontAnimate) {
  927. var _ = this;
  928. _.changeSlide({
  929. data: {
  930. message: 'index',
  931. index: parseInt(slide)
  932. }
  933. }, dontAnimate);
  934. };
  935. Slick.prototype.init = function(creation) {
  936. var _ = this;
  937. if (!$(_.$slider).hasClass('slick-initialized')) {
  938. $(_.$slider).addClass('slick-initialized');
  939. _.buildRows();
  940. _.buildOut();
  941. _.setProps();
  942. _.startLoad();
  943. _.loadSlider();
  944. _.initializeEvents();
  945. _.updateArrows();
  946. _.updateDots();
  947. _.checkResponsive(true);
  948. _.focusHandler();
  949. }
  950. if (creation) {
  951. _.$slider.trigger('init', [_]);
  952. }
  953. if (_.options.accessibility === true) {
  954. _.initADA();
  955. }
  956. if ( _.options.autoplay ) {
  957. _.paused = false;
  958. _.autoPlay();
  959. }
  960. };
  961. Slick.prototype.initADA = function() {
  962. var _ = this,
  963. numDotGroups = Math.ceil(_.slideCount / _.options.slidesToShow),
  964. tabControlIndexes = _.getNavigableIndexes().filter(function(val) {
  965. return (val >= 0) && (val < _.slideCount);
  966. });
  967. _.$slides.add(_.$slideTrack.find('.slick-cloned')).attr({
  968. 'aria-hidden': 'true',
  969. 'tabindex': '-1'
  970. }).find('a, input, button, select').attr({
  971. 'tabindex': '-1'
  972. });
  973. if (_.$dots !== null) {
  974. _.$slides.not(_.$slideTrack.find('.slick-cloned')).each(function(i) {
  975. var slideControlIndex = tabControlIndexes.indexOf(i);
  976. $(this).attr({
  977. 'role': 'tabpanel',
  978. 'id': 'slick-slide' + _.instanceUid + i,
  979. 'tabindex': -1
  980. });
  981. if (slideControlIndex !== -1) {
  982. $(this).attr({
  983. 'aria-describedby': 'slick-slide-control' + _.instanceUid + slideControlIndex
  984. });
  985. }
  986. });
  987. _.$dots.attr('role', 'tablist').find('li').each(function(i) {
  988. var mappedSlideIndex = tabControlIndexes[i];
  989. $(this).attr({
  990. 'role': 'presentation'
  991. });
  992. $(this).find('button').first().attr({
  993. 'role': 'tab',
  994. 'id': 'slick-slide-control' + _.instanceUid + i,
  995. 'aria-controls': 'slick-slide' + _.instanceUid + mappedSlideIndex,
  996. 'aria-label': (i + 1) + ' of ' + numDotGroups,
  997. 'aria-selected': null,
  998. 'tabindex': '-1'
  999. });
  1000. }).eq(_.currentSlide).find('button').attr({
  1001. 'aria-selected': 'true',
  1002. 'tabindex': '0'
  1003. }).end();
  1004. }
  1005. for (var i=_.currentSlide, max=i+_.options.slidesToShow; i < max; i++) {
  1006. _.$slides.eq(i).attr('tabindex', 0);
  1007. }
  1008. _.activateADA();
  1009. };
  1010. Slick.prototype.initArrowEvents = function() {
  1011. var _ = this;
  1012. if (_.options.arrows === true && _.slideCount > _.options.slidesToShow) {
  1013. _.$prevArrow
  1014. .off('click.slick')
  1015. .on('click.slick', {
  1016. message: 'previous'
  1017. }, _.changeSlide);
  1018. _.$nextArrow
  1019. .off('click.slick')
  1020. .on('click.slick', {
  1021. message: 'next'
  1022. }, _.changeSlide);
  1023. if (_.options.accessibility === true) {
  1024. _.$prevArrow.on('keydown.slick', _.keyHandler);
  1025. _.$nextArrow.on('keydown.slick', _.keyHandler);
  1026. }
  1027. }
  1028. };
  1029. Slick.prototype.initDotEvents = function() {
  1030. var _ = this;
  1031. if (_.options.dots === true) {
  1032. $('li', _.$dots).on('click.slick', {
  1033. message: 'index'
  1034. }, _.changeSlide);
  1035. if (_.options.accessibility === true) {
  1036. _.$dots.on('keydown.slick', _.keyHandler);
  1037. }
  1038. }
  1039. if ( _.options.dots === true && _.options.pauseOnDotsHover === true ) {
  1040. $('li', _.$dots)
  1041. .on('mouseenter.slick', $.proxy(_.interrupt, _, true))
  1042. .on('mouseleave.slick', $.proxy(_.interrupt, _, false));
  1043. }
  1044. };
  1045. Slick.prototype.initSlideEvents = function() {
  1046. var _ = this;
  1047. if ( _.options.pauseOnHover ) {
  1048. _.$list.on('mouseenter.slick', $.proxy(_.interrupt, _, true));
  1049. _.$list.on('mouseleave.slick', $.proxy(_.interrupt, _, false));
  1050. }
  1051. };
  1052. Slick.prototype.initializeEvents = function() {
  1053. var _ = this;
  1054. _.initArrowEvents();
  1055. _.initDotEvents();
  1056. _.initSlideEvents();
  1057. _.$list.on('touchstart.slick mousedown.slick', {
  1058. action: 'start'
  1059. }, _.swipeHandler);
  1060. _.$list.on('touchmove.slick mousemove.slick', {
  1061. action: 'move'
  1062. }, _.swipeHandler);
  1063. _.$list.on('touchend.slick mouseup.slick', {
  1064. action: 'end'
  1065. }, _.swipeHandler);
  1066. _.$list.on('touchcancel.slick mouseleave.slick', {
  1067. action: 'end'
  1068. }, _.swipeHandler);
  1069. _.$list.on('click.slick', _.clickHandler);
  1070. $(document).on(_.visibilityChange, $.proxy(_.visibility, _));
  1071. if (_.options.accessibility === true) {
  1072. _.$list.on('keydown.slick', _.keyHandler);
  1073. }
  1074. if (_.options.focusOnSelect === true) {
  1075. $(_.$slideTrack).children().on('click.slick', _.selectHandler);
  1076. }
  1077. $(window).on('orientationchange.slick.slick-' + _.instanceUid, $.proxy(_.orientationChange, _));
  1078. $(window).on('resize.slick.slick-' + _.instanceUid, $.proxy(_.resize, _));
  1079. $('[draggable!=true]', _.$slideTrack).on('dragstart', _.preventDefault);
  1080. $(window).on('load.slick.slick-' + _.instanceUid, _.setPosition);
  1081. $(_.setPosition);
  1082. };
  1083. Slick.prototype.initUI = function() {
  1084. var _ = this;
  1085. if (_.options.arrows === true && _.slideCount > _.options.slidesToShow) {
  1086. _.$prevArrow.show();
  1087. _.$nextArrow.show();
  1088. }
  1089. if (_.options.dots === true && _.slideCount > _.options.slidesToShow) {
  1090. _.$dots.show();
  1091. }
  1092. };
  1093. Slick.prototype.keyHandler = function(event) {
  1094. var _ = this;
  1095. //Dont slide if the cursor is inside the form fields and arrow keys are pressed
  1096. if(!event.target.tagName.match('TEXTAREA|INPUT|SELECT')) {
  1097. if (event.keyCode === 37 && _.options.accessibility === true) {
  1098. _.changeSlide({
  1099. data: {
  1100. message: _.options.rtl === true ? 'next' : 'previous'
  1101. }
  1102. });
  1103. } else if (event.keyCode === 39 && _.options.accessibility === true) {
  1104. _.changeSlide({
  1105. data: {
  1106. message: _.options.rtl === true ? 'previous' : 'next'
  1107. }
  1108. });
  1109. }
  1110. }
  1111. };
  1112. Slick.prototype.lazyLoad = function() {
  1113. var _ = this,
  1114. loadRange, cloneRange, rangeStart, rangeEnd;
  1115. function loadImages(imagesScope) {
  1116. $('img[data-lazy]', imagesScope).each(function() {
  1117. var image = $(this),
  1118. imageSource = $(this).attr('data-lazy'),
  1119. imageSrcSet = $(this).attr('data-srcset'),
  1120. imageSizes = $(this).attr('data-sizes') || _.$slider.attr('data-sizes'),
  1121. imageToLoad = document.createElement('img');
  1122. imageToLoad.onload = function() {
  1123. image
  1124. .animate({ opacity: 0 }, 100, function() {
  1125. if (imageSrcSet) {
  1126. image
  1127. .attr('srcset', imageSrcSet );
  1128. if (imageSizes) {
  1129. image
  1130. .attr('sizes', imageSizes );
  1131. }
  1132. }
  1133. image
  1134. .attr('src', imageSource)
  1135. .animate({ opacity: 1 }, 200, function() {
  1136. image
  1137. .removeAttr('data-lazy data-srcset data-sizes')
  1138. .removeClass('slick-loading');
  1139. });
  1140. _.$slider.trigger('lazyLoaded', [_, image, imageSource]);
  1141. });
  1142. };
  1143. imageToLoad.onerror = function() {
  1144. image
  1145. .removeAttr( 'data-lazy' )
  1146. .removeClass( 'slick-loading' )
  1147. .addClass( 'slick-lazyload-error' );
  1148. _.$slider.trigger('lazyLoadError', [ _, image, imageSource ]);
  1149. };
  1150. imageToLoad.src = imageSource;
  1151. });
  1152. }
  1153. if (_.options.centerMode === true) {
  1154. if (_.options.infinite === true) {
  1155. rangeStart = _.currentSlide + (_.options.slidesToShow / 2 + 1);
  1156. rangeEnd = rangeStart + _.options.slidesToShow + 2;
  1157. } else {
  1158. rangeStart = Math.max(0, _.currentSlide - (_.options.slidesToShow / 2 + 1));
  1159. rangeEnd = 2 + (_.options.slidesToShow / 2 + 1) + _.currentSlide;
  1160. }
  1161. } else {
  1162. rangeStart = _.options.infinite ? _.options.slidesToShow + _.currentSlide : _.currentSlide;
  1163. rangeEnd = Math.ceil(rangeStart + _.options.slidesToShow);
  1164. if (_.options.fade === true) {
  1165. if (rangeStart > 0) rangeStart--;
  1166. if (rangeEnd <= _.slideCount) rangeEnd++;
  1167. }
  1168. }
  1169. loadRange = _.$slider.find('.slick-slide').slice(rangeStart, rangeEnd);
  1170. if (_.options.lazyLoad === 'anticipated') {
  1171. var prevSlide = rangeStart - 1,
  1172. nextSlide = rangeEnd,
  1173. $slides = _.$slider.find('.slick-slide');
  1174. for (var i = 0; i < _.options.slidesToScroll; i++) {
  1175. if (prevSlide < 0) prevSlide = _.slideCount - 1;
  1176. loadRange = loadRange.add($slides.eq(prevSlide));
  1177. loadRange = loadRange.add($slides.eq(nextSlide));
  1178. prevSlide--;
  1179. nextSlide++;
  1180. }
  1181. }
  1182. loadImages(loadRange);
  1183. if (_.slideCount <= _.options.slidesToShow) {
  1184. cloneRange = _.$slider.find('.slick-slide');
  1185. loadImages(cloneRange);
  1186. } else
  1187. if (_.currentSlide >= _.slideCount - _.options.slidesToShow) {
  1188. cloneRange = _.$slider.find('.slick-cloned').slice(0, _.options.slidesToShow);
  1189. loadImages(cloneRange);
  1190. } else if (_.currentSlide === 0) {
  1191. cloneRange = _.$slider.find('.slick-cloned').slice(_.options.slidesToShow * -1);
  1192. loadImages(cloneRange);
  1193. }
  1194. };
  1195. Slick.prototype.loadSlider = function() {
  1196. var _ = this;
  1197. _.setPosition();
  1198. _.$slideTrack.css({
  1199. opacity: 1
  1200. });
  1201. _.$slider.removeClass('slick-loading');
  1202. _.initUI();
  1203. if (_.options.lazyLoad === 'progressive') {
  1204. _.progressiveLazyLoad();
  1205. }
  1206. };
  1207. Slick.prototype.next = Slick.prototype.slickNext = function() {
  1208. var _ = this;
  1209. _.changeSlide({
  1210. data: {
  1211. message: 'next'
  1212. }
  1213. });
  1214. };
  1215. Slick.prototype.orientationChange = function() {
  1216. var _ = this;
  1217. _.checkResponsive();
  1218. _.setPosition();
  1219. };
  1220. Slick.prototype.pause = Slick.prototype.slickPause = function() {
  1221. var _ = this;
  1222. _.autoPlayClear();
  1223. _.paused = true;
  1224. };
  1225. Slick.prototype.play = Slick.prototype.slickPlay = function() {
  1226. var _ = this;
  1227. _.autoPlay();
  1228. _.options.autoplay = true;
  1229. _.paused = false;
  1230. _.focussed = false;
  1231. _.interrupted = false;
  1232. };
  1233. Slick.prototype.postSlide = function(index) {
  1234. var _ = this;
  1235. if( !_.unslicked ) {
  1236. _.$slider.trigger('afterChange', [_, index]);
  1237. _.animating = false;
  1238. if (_.slideCount > _.options.slidesToShow) {
  1239. _.setPosition();
  1240. }
  1241. _.swipeLeft = null;
  1242. if ( _.options.autoplay ) {
  1243. _.autoPlay();
  1244. }
  1245. if (_.options.accessibility === true) {
  1246. _.initADA();
  1247. // for non-autoplay: once active slide (group) has updated, set focus on first newly showing slide
  1248. if (!_.options.autoplay) {
  1249. var $currentSlide = $(_.$slides.get(_.currentSlide));
  1250. $currentSlide.attr('tabindex', 0).focus();
  1251. }
  1252. }
  1253. }
  1254. };
  1255. Slick.prototype.prev = Slick.prototype.slickPrev = function() {
  1256. var _ = this;
  1257. _.changeSlide({
  1258. data: {
  1259. message: 'previous'
  1260. }
  1261. });
  1262. };
  1263. Slick.prototype.preventDefault = function(event) {
  1264. event.preventDefault();
  1265. };
  1266. Slick.prototype.progressiveLazyLoad = function( tryCount ) {
  1267. tryCount = tryCount || 1;
  1268. var _ = this,
  1269. $imgsToLoad = $( 'img[data-lazy]', _.$slider ),
  1270. image,
  1271. imageSource,
  1272. imageSrcSet,
  1273. imageSizes,
  1274. imageToLoad;
  1275. if ( $imgsToLoad.length ) {
  1276. image = $imgsToLoad.first();
  1277. imageSource = image.attr('data-lazy');
  1278. imageSrcSet = image.attr('data-srcset');
  1279. imageSizes = image.attr('data-sizes') || _.$slider.attr('data-sizes');
  1280. imageToLoad = document.createElement('img');
  1281. imageToLoad.onload = function() {
  1282. if (imageSrcSet) {
  1283. image
  1284. .attr('srcset', imageSrcSet );
  1285. if (imageSizes) {
  1286. image
  1287. .attr('sizes', imageSizes );
  1288. }
  1289. }
  1290. image
  1291. .attr( 'src', imageSource )
  1292. .removeAttr('data-lazy data-srcset data-sizes')
  1293. .removeClass('slick-loading');
  1294. if ( _.options.adaptiveHeight === true ) {
  1295. _.setPosition();
  1296. }
  1297. _.$slider.trigger('lazyLoaded', [ _, image, imageSource ]);
  1298. _.progressiveLazyLoad();
  1299. };
  1300. imageToLoad.onerror = function() {
  1301. if ( tryCount < 3 ) {
  1302. /**
  1303. * try to load the image 3 times,
  1304. * leave a slight delay so we don't get
  1305. * servers blocking the request.
  1306. */
  1307. setTimeout( function() {
  1308. _.progressiveLazyLoad( tryCount + 1 );
  1309. }, 500 );
  1310. } else {
  1311. image
  1312. .removeAttr( 'data-lazy' )
  1313. .removeClass( 'slick-loading' )
  1314. .addClass( 'slick-lazyload-error' );
  1315. _.$slider.trigger('lazyLoadError', [ _, image, imageSource ]);
  1316. _.progressiveLazyLoad();
  1317. }
  1318. };
  1319. imageToLoad.src = imageSource;
  1320. } else {
  1321. _.$slider.trigger('allImagesLoaded', [ _ ]);
  1322. }
  1323. };
  1324. Slick.prototype.refresh = function( initializing ) {
  1325. var _ = this, currentSlide, lastVisibleIndex;
  1326. lastVisibleIndex = _.slideCount - _.options.slidesToShow;
  1327. // in non-infinite sliders, we don't want to go past the
  1328. // last visible index.
  1329. if( !_.options.infinite && ( _.currentSlide > lastVisibleIndex )) {
  1330. _.currentSlide = lastVisibleIndex;
  1331. }
  1332. // if less slides than to show, go to start.
  1333. if ( _.slideCount <= _.options.slidesToShow ) {
  1334. _.currentSlide = 0;
  1335. }
  1336. currentSlide = _.currentSlide;
  1337. _.destroy(true);
  1338. $.extend(_, _.initials, { currentSlide: currentSlide });
  1339. _.init();
  1340. if( !initializing ) {
  1341. _.changeSlide({
  1342. data: {
  1343. message: 'index',
  1344. index: currentSlide
  1345. }
  1346. }, false);
  1347. }
  1348. };
  1349. Slick.prototype.registerBreakpoints = function() {
  1350. var _ = this, breakpoint, currentBreakpoint, l,
  1351. responsiveSettings = _.options.responsive || null;
  1352. if ( $.type(responsiveSettings) === 'array' && responsiveSettings.length ) {
  1353. _.respondTo = _.options.respondTo || 'window';
  1354. for ( breakpoint in responsiveSettings ) {
  1355. l = _.breakpoints.length-1;
  1356. if (responsiveSettings.hasOwnProperty(breakpoint)) {
  1357. currentBreakpoint = responsiveSettings[breakpoint].breakpoint;
  1358. // loop through the breakpoints and cut out any existing
  1359. // ones with the same breakpoint number, we don't want dupes.
  1360. while( l >= 0 ) {
  1361. if( _.breakpoints[l] && _.breakpoints[l] === currentBreakpoint ) {
  1362. _.breakpoints.splice(l,1);
  1363. }
  1364. l--;
  1365. }
  1366. _.breakpoints.push(currentBreakpoint);
  1367. _.breakpointSettings[currentBreakpoint] = responsiveSettings[breakpoint].settings;
  1368. }
  1369. }
  1370. _.breakpoints.sort(function(a, b) {
  1371. return ( _.options.mobileFirst ) ? a-b : b-a;
  1372. });
  1373. }
  1374. };
  1375. Slick.prototype.reinit = function() {
  1376. var _ = this;
  1377. _.$slides =
  1378. _.$slideTrack
  1379. .children(_.options.slide)
  1380. .addClass('slick-slide');
  1381. _.slideCount = _.$slides.length;
  1382. if (_.currentSlide >= _.slideCount && _.currentSlide !== 0) {
  1383. _.currentSlide = _.currentSlide - _.options.slidesToScroll;
  1384. }
  1385. if (_.slideCount <= _.options.slidesToShow) {
  1386. _.currentSlide = 0;
  1387. }
  1388. _.registerBreakpoints();
  1389. _.setProps();
  1390. _.setupInfinite();
  1391. _.buildArrows();
  1392. _.updateArrows();
  1393. _.initArrowEvents();
  1394. _.buildDots();
  1395. _.updateDots();
  1396. _.initDotEvents();
  1397. _.cleanUpSlideEvents();
  1398. _.initSlideEvents();
  1399. _.checkResponsive(false, true);
  1400. if (_.options.focusOnSelect === true) {
  1401. $(_.$slideTrack).children().on('click.slick', _.selectHandler);
  1402. }
  1403. _.setSlideClasses(typeof _.currentSlide === 'number' ? _.currentSlide : 0);
  1404. _.setPosition();
  1405. _.focusHandler();
  1406. _.paused = !_.options.autoplay;
  1407. _.autoPlay();
  1408. _.$slider.trigger('reInit', [_]);
  1409. };
  1410. Slick.prototype.resize = function() {
  1411. var _ = this;
  1412. if ($(window).width() !== _.windowWidth) {
  1413. clearTimeout(_.windowDelay);
  1414. _.windowDelay = window.setTimeout(function() {
  1415. _.windowWidth = $(window).width();
  1416. _.checkResponsive();
  1417. if( !_.unslicked ) { _.setPosition(); }
  1418. }, 50);
  1419. }
  1420. };
  1421. Slick.prototype.removeSlide = Slick.prototype.slickRemove = function(index, removeBefore, removeAll) {
  1422. var _ = this;
  1423. if (typeof(index) === 'boolean') {
  1424. removeBefore = index;
  1425. index = removeBefore === true ? 0 : _.slideCount - 1;
  1426. } else {
  1427. index = removeBefore === true ? --index : index;
  1428. }
  1429. if (_.slideCount < 1 || index < 0 || index > _.slideCount - 1) {
  1430. return false;
  1431. }
  1432. _.unload();
  1433. if (removeAll === true) {
  1434. _.$slideTrack.children().remove();
  1435. } else {
  1436. _.$slideTrack.children(this.options.slide).eq(index).remove();
  1437. }
  1438. _.$slides = _.$slideTrack.children(this.options.slide);
  1439. _.$slideTrack.children(this.options.slide).detach();
  1440. _.$slideTrack.append(_.$slides);
  1441. _.$slidesCache = _.$slides;
  1442. _.reinit();
  1443. };
  1444. Slick.prototype.setCSS = function(position) {
  1445. var _ = this,
  1446. positionProps = {},
  1447. x, y;
  1448. if (_.options.rtl === true) {
  1449. position = -position;
  1450. }
  1451. x = _.positionProp == 'left' ? Math.ceil(position) + 'px' : '0px';
  1452. y = _.positionProp == 'top' ? Math.ceil(position) + 'px' : '0px';
  1453. positionProps[_.positionProp] = position;
  1454. if (_.transformsEnabled === false) {
  1455. _.$slideTrack.css(positionProps);
  1456. } else {
  1457. positionProps = {};
  1458. if (_.cssTransitions === false) {
  1459. positionProps[_.animType] = 'translate(' + x + ', ' + y + ')';
  1460. _.$slideTrack.css(positionProps);
  1461. } else {
  1462. positionProps[_.animType] = 'translate3d(' + x + ', ' + y + ', 0px)';
  1463. _.$slideTrack.css(positionProps);
  1464. }
  1465. }
  1466. };
  1467. Slick.prototype.setDimensions = function() {
  1468. var _ = this;
  1469. if (_.options.vertical === false) {
  1470. if (_.options.centerMode === true) {
  1471. _.$list.css({
  1472. padding: ('0px ' + _.options.centerPadding)
  1473. });
  1474. }
  1475. } else {
  1476. _.$list.height(_.$slides.first().outerHeight(true) * _.options.slidesToShow);
  1477. if (_.options.centerMode === true) {
  1478. _.$list.css({
  1479. padding: (_.options.centerPadding + ' 0px')
  1480. });
  1481. }
  1482. }
  1483. _.listWidth = _.$list.width();
  1484. _.listHeight = _.$list.height();
  1485. if (_.options.vertical === false && _.options.variableWidth === false) {
  1486. _.slideWidth = Math.ceil(_.listWidth / _.options.slidesToShow);
  1487. _.$slideTrack.width(Math.ceil((_.slideWidth * _.$slideTrack.children('.slick-slide').length)));
  1488. } else if (_.options.variableWidth === true) {
  1489. _.$slideTrack.width(5000 * _.slideCount);
  1490. } else {
  1491. _.slideWidth = Math.ceil(_.listWidth);
  1492. _.$slideTrack.height(Math.ceil((_.$slides.first().outerHeight(true) * _.$slideTrack.children('.slick-slide').length)));
  1493. }
  1494. var offset = _.$slides.first().outerWidth(true) - _.$slides.first().width();
  1495. if (_.options.variableWidth === false) _.$slideTrack.children('.slick-slide').width(_.slideWidth - offset);
  1496. };
  1497. Slick.prototype.setFade = function() {
  1498. var _ = this,
  1499. targetLeft;
  1500. _.$slides.each(function(index, element) {
  1501. targetLeft = (_.slideWidth * index) * -1;
  1502. if (_.options.rtl === true) {
  1503. $(element).css({
  1504. position: 'relative',
  1505. right: targetLeft,
  1506. top: 0,
  1507. zIndex: _.options.zIndex - 2,
  1508. opacity: 0
  1509. });
  1510. } else {
  1511. $(element).css({
  1512. position: 'relative',
  1513. left: targetLeft,
  1514. top: 0,
  1515. zIndex: _.options.zIndex - 2,
  1516. opacity: 0
  1517. });
  1518. }
  1519. });
  1520. _.$slides.eq(_.currentSlide).css({
  1521. zIndex: _.options.zIndex - 1,
  1522. opacity: 1
  1523. });
  1524. };
  1525. Slick.prototype.setHeight = function() {
  1526. var _ = this;
  1527. if (_.options.slidesToShow === 1 && _.options.adaptiveHeight === true && _.options.vertical === false) {
  1528. var targetHeight = _.$slides.eq(_.currentSlide).outerHeight(true);
  1529. _.$list.css('height', targetHeight);
  1530. }
  1531. };
  1532. Slick.prototype.setOption =
  1533. Slick.prototype.slickSetOption = function() {
  1534. /**
  1535. * accepts arguments in format of:
  1536. *
  1537. * - for changing a single option's value:
  1538. * .slick("setOption", option, value, refresh )
  1539. *
  1540. * - for changing a set of responsive options:
  1541. * .slick("setOption", 'responsive', [{}, ...], refresh )
  1542. *
  1543. * - for updating multiple values at once (not responsive)
  1544. * .slick("setOption", { 'option': value, ... }, refresh )
  1545. */
  1546. var _ = this, l, item, option, value, refresh = false, type;
  1547. if( $.type( arguments[0] ) === 'object' ) {
  1548. option = arguments[0];
  1549. refresh = arguments[1];
  1550. type = 'multiple';
  1551. } else if ( $.type( arguments[0] ) === 'string' ) {
  1552. option = arguments[0];
  1553. value = arguments[1];
  1554. refresh = arguments[2];
  1555. if ( arguments[0] === 'responsive' && $.type( arguments[1] ) === 'array' ) {
  1556. type = 'responsive';
  1557. } else if ( typeof arguments[1] !== 'undefined' ) {
  1558. type = 'single';
  1559. }
  1560. }
  1561. if ( type === 'single' ) {
  1562. _.options[option] = value;
  1563. } else if ( type === 'multiple' ) {
  1564. $.each( option , function( opt, val ) {
  1565. _.options[opt] = val;
  1566. });
  1567. } else if ( type === 'responsive' ) {
  1568. for ( item in value ) {
  1569. if( $.type( _.options.responsive ) !== 'array' ) {
  1570. _.options.responsive = [ value[item] ];
  1571. } else {
  1572. l = _.options.responsive.length-1;
  1573. // loop through the responsive object and splice out duplicates.
  1574. while( l >= 0 ) {
  1575. if( _.options.responsive[l].breakpoint === value[item].breakpoint ) {
  1576. _.options.responsive.splice(l,1);
  1577. }
  1578. l--;
  1579. }
  1580. _.options.responsive.push( value[item] );
  1581. }
  1582. }
  1583. }
  1584. if ( refresh ) {
  1585. _.unload();
  1586. _.reinit();
  1587. }
  1588. };
  1589. Slick.prototype.setPosition = function() {
  1590. var _ = this;
  1591. _.setDimensions();
  1592. _.setHeight();
  1593. if (_.options.fade === false) {
  1594. _.setCSS(_.getLeft(_.currentSlide));
  1595. } else {
  1596. _.setFade();
  1597. }
  1598. _.$slider.trigger('setPosition', [_]);
  1599. };
  1600. Slick.prototype.setProps = function() {
  1601. var _ = this,
  1602. bodyStyle = document.body.style;
  1603. _.positionProp = _.options.vertical === true ? 'top' : 'left';
  1604. if (_.positionProp === 'top') {
  1605. _.$slider.addClass('slick-vertical');
  1606. } else {
  1607. _.$slider.removeClass('slick-vertical');
  1608. }
  1609. if (bodyStyle.WebkitTransition !== undefined ||
  1610. bodyStyle.MozTransition !== undefined ||
  1611. bodyStyle.msTransition !== undefined) {
  1612. if (_.options.useCSS === true) {
  1613. _.cssTransitions = true;
  1614. }
  1615. }
  1616. if ( _.options.fade ) {
  1617. if ( typeof _.options.zIndex === 'number' ) {
  1618. if( _.options.zIndex < 3 ) {
  1619. _.options.zIndex = 3;
  1620. }
  1621. } else {
  1622. _.options.zIndex = _.defaults.zIndex;
  1623. }
  1624. }
  1625. if (bodyStyle.OTransform !== undefined) {
  1626. _.animType = 'OTransform';
  1627. _.transformType = '-o-transform';
  1628. _.transitionType = 'OTransition';
  1629. if (bodyStyle.perspectiveProperty === undefined && bodyStyle.webkitPerspective === undefined) _.animType = false;
  1630. }
  1631. if (bodyStyle.MozTransform !== undefined) {
  1632. _.animType = 'MozTransform';
  1633. _.transformType = '-moz-transform';
  1634. _.transitionType = 'MozTransition';
  1635. if (bodyStyle.perspectiveProperty === undefined && bodyStyle.MozPerspective === undefined) _.animType = false;
  1636. }
  1637. if (bodyStyle.webkitTransform !== undefined) {
  1638. _.animType = 'webkitTransform';
  1639. _.transformType = '-webkit-transform';
  1640. _.transitionType = 'webkitTransition';
  1641. if (bodyStyle.perspectiveProperty === undefined && bodyStyle.webkitPerspective === undefined) _.animType = false;
  1642. }
  1643. if (bodyStyle.msTransform !== undefined) {
  1644. _.animType = 'msTransform';
  1645. _.transformType = '-ms-transform';
  1646. _.transitionType = 'msTransition';
  1647. if (bodyStyle.msTransform === undefined) _.animType = false;
  1648. }
  1649. if (bodyStyle.transform !== undefined && _.animType !== false) {
  1650. _.animType = 'transform';
  1651. _.transformType = 'transform';
  1652. _.transitionType = 'transition';
  1653. }
  1654. _.transformsEnabled = _.options.useTransform && (_.animType !== null && _.animType !== false);
  1655. };
  1656. Slick.prototype.setSlideClasses = function(index) {
  1657. var _ = this,
  1658. centerOffset, allSlides, indexOffset, remainder;
  1659. allSlides = _.$slider
  1660. .find('.slick-slide')
  1661. .removeClass('slick-active slick-center slick-current')
  1662. .attr('aria-hidden', 'true');
  1663. _.$slides
  1664. .eq(index)
  1665. .addClass('slick-current');
  1666. if (_.options.centerMode === true) {
  1667. centerOffset = Math.floor(_.options.slidesToShow / 2);
  1668. if (_.options.infinite === true) {
  1669. if (index >= centerOffset && index <= (_.slideCount - 1) - centerOffset) {
  1670. _.$slides
  1671. .slice(index - centerOffset, index + centerOffset + 1)
  1672. .addClass('slick-active')
  1673. .attr('aria-hidden', 'false');
  1674. } else {
  1675. indexOffset = _.options.slidesToShow + index;
  1676. allSlides
  1677. .slice(indexOffset - centerOffset + 1, indexOffset + centerOffset + 2)
  1678. .addClass('slick-active')
  1679. .attr('aria-hidden', 'false');
  1680. }
  1681. if (index === 0) {
  1682. allSlides
  1683. .eq(allSlides.length - 1 - _.options.slidesToShow)
  1684. .addClass('slick-center');
  1685. } else if (index === _.slideCount - 1) {
  1686. allSlides
  1687. .eq(_.options.slidesToShow)
  1688. .addClass('slick-center');
  1689. }
  1690. }
  1691. _.$slides
  1692. .eq(index)
  1693. .addClass('slick-center');
  1694. } else {
  1695. if (index >= 0 && index <= (_.slideCount - _.options.slidesToShow)) {
  1696. _.$slides
  1697. .slice(index, index + _.options.slidesToShow)
  1698. .addClass('slick-active')
  1699. .attr('aria-hidden', 'false');
  1700. } else if (allSlides.length <= _.options.slidesToShow) {
  1701. allSlides
  1702. .addClass('slick-active')
  1703. .attr('aria-hidden', 'false');
  1704. } else {
  1705. remainder = _.slideCount % _.options.slidesToShow;
  1706. indexOffset = _.options.infinite === true ? _.options.slidesToShow + index : index;
  1707. if (_.options.slidesToShow == _.options.slidesToScroll && (_.slideCount - index) < _.options.slidesToShow) {
  1708. allSlides
  1709. .slice(indexOffset - (_.options.slidesToShow - remainder), indexOffset + remainder)
  1710. .addClass('slick-active')
  1711. .attr('aria-hidden', 'false');
  1712. } else {
  1713. allSlides
  1714. .slice(indexOffset, indexOffset + _.options.slidesToShow)
  1715. .addClass('slick-active')
  1716. .attr('aria-hidden', 'false');
  1717. }
  1718. }
  1719. }
  1720. if (_.options.lazyLoad === 'ondemand' || _.options.lazyLoad === 'anticipated') {
  1721. _.lazyLoad();
  1722. }
  1723. };
  1724. Slick.prototype.setupInfinite = function() {
  1725. var _ = this,
  1726. i, slideIndex, infiniteCount;
  1727. if (_.options.fade === true) {
  1728. _.options.centerMode = false;
  1729. }
  1730. if (_.options.infinite === true && _.options.fade === false) {
  1731. slideIndex = null;
  1732. if (_.slideCount > _.options.slidesToShow) {
  1733. if (_.options.centerMode === true) {
  1734. infiniteCount = _.options.slidesToShow + 1;
  1735. } else {
  1736. infiniteCount = _.options.slidesToShow;
  1737. }
  1738. for (i = _.slideCount; i > (_.slideCount -
  1739. infiniteCount); i -= 1) {
  1740. slideIndex = i - 1;
  1741. $(_.$slides[slideIndex]).clone(true).attr('id', '')
  1742. .attr('data-slick-index', slideIndex - _.slideCount)
  1743. .prependTo(_.$slideTrack).addClass('slick-cloned');
  1744. }
  1745. for (i = 0; i < infiniteCount + _.slideCount; i += 1) {
  1746. slideIndex = i;
  1747. $(_.$slides[slideIndex]).clone(true).attr('id', '')
  1748. .attr('data-slick-index', slideIndex + _.slideCount)
  1749. .appendTo(_.$slideTrack).addClass('slick-cloned');
  1750. }
  1751. _.$slideTrack.find('.slick-cloned').find('[id]').each(function() {
  1752. $(this).attr('id', '');
  1753. });
  1754. }
  1755. }
  1756. };
  1757. Slick.prototype.interrupt = function( toggle ) {
  1758. var _ = this;
  1759. if( !toggle ) {
  1760. _.autoPlay();
  1761. }
  1762. _.interrupted = toggle;
  1763. };
  1764. Slick.prototype.selectHandler = function(event) {
  1765. var _ = this;
  1766. var targetElement =
  1767. $(event.target).is('.slick-slide') ?
  1768. $(event.target) :
  1769. $(event.target).parents('.slick-slide');
  1770. var index = parseInt(targetElement.attr('data-slick-index'));
  1771. if (!index) index = 0;
  1772. if (_.slideCount <= _.options.slidesToShow) {
  1773. _.slideHandler(index, false, true);
  1774. return;
  1775. }
  1776. _.slideHandler(index);
  1777. };
  1778. Slick.prototype.slideHandler = function(index, sync, dontAnimate) {
  1779. var targetSlide, animSlide, oldSlide, slideLeft, targetLeft = null,
  1780. _ = this, navTarget;
  1781. sync = sync || false;
  1782. if (_.animating === true && _.options.waitForAnimate === true) {
  1783. return;
  1784. }
  1785. if (_.options.fade === true && _.currentSlide === index) {
  1786. return;
  1787. }
  1788. if (sync === false) {
  1789. _.asNavFor(index);
  1790. }
  1791. targetSlide = index;
  1792. targetLeft = _.getLeft(targetSlide);
  1793. slideLeft = _.getLeft(_.currentSlide);
  1794. _.currentLeft = _.swipeLeft === null ? slideLeft : _.swipeLeft;
  1795. if (_.options.infinite === false && _.options.centerMode === false && (index < 0 || index > _.getDotCount() * _.options.slidesToScroll)) {
  1796. if (_.options.fade === false) {
  1797. targetSlide = _.currentSlide;
  1798. if (dontAnimate !== true) {
  1799. _.animateSlide(slideLeft, function() {
  1800. _.postSlide(targetSlide);
  1801. });
  1802. } else {
  1803. _.postSlide(targetSlide);
  1804. }
  1805. }
  1806. return;
  1807. } else if (_.options.infinite === false && _.options.centerMode === true && (index < 0 || index > (_.slideCount - _.options.slidesToScroll))) {
  1808. if (_.options.fade === false) {
  1809. targetSlide = _.currentSlide;
  1810. if (dontAnimate !== true) {
  1811. _.animateSlide(slideLeft, function() {
  1812. _.postSlide(targetSlide);
  1813. });
  1814. } else {
  1815. _.postSlide(targetSlide);
  1816. }
  1817. }
  1818. return;
  1819. }
  1820. if ( _.options.autoplay ) {
  1821. clearInterval(_.autoPlayTimer);
  1822. }
  1823. if (targetSlide < 0) {
  1824. if (_.slideCount % _.options.slidesToScroll !== 0) {
  1825. animSlide = _.slideCount - (_.slideCount % _.options.slidesToScroll);
  1826. } else {
  1827. animSlide = _.slideCount + targetSlide;
  1828. }
  1829. } else if (targetSlide >= _.slideCount) {
  1830. if (_.slideCount % _.options.slidesToScroll !== 0) {
  1831. animSlide = 0;
  1832. } else {
  1833. animSlide = targetSlide - _.slideCount;
  1834. }
  1835. } else {
  1836. animSlide = targetSlide;
  1837. }
  1838. _.animating = true;
  1839. _.$slider.trigger('beforeChange', [_, _.currentSlide, animSlide]);
  1840. oldSlide = _.currentSlide;
  1841. _.currentSlide = animSlide;
  1842. _.setSlideClasses(_.currentSlide);
  1843. if ( _.options.asNavFor ) {
  1844. navTarget = _.getNavTarget();
  1845. navTarget = navTarget.slick('getSlick');
  1846. if ( navTarget.slideCount <= navTarget.options.slidesToShow ) {
  1847. navTarget.setSlideClasses(_.currentSlide);
  1848. }
  1849. }
  1850. _.updateDots();
  1851. _.updateArrows();
  1852. if (_.options.fade === true) {
  1853. if (dontAnimate !== true) {
  1854. _.fadeSlideOut(oldSlide);
  1855. _.fadeSlide(animSlide, function() {
  1856. _.postSlide(animSlide);
  1857. });
  1858. } else {
  1859. _.postSlide(animSlide);
  1860. }
  1861. _.animateHeight();
  1862. return;
  1863. }
  1864. if (dontAnimate !== true) {
  1865. _.animateSlide(targetLeft, function() {
  1866. _.postSlide(animSlide);
  1867. });
  1868. } else {
  1869. _.postSlide(animSlide);
  1870. }
  1871. };
  1872. Slick.prototype.startLoad = function() {
  1873. var _ = this;
  1874. if (_.options.arrows === true && _.slideCount > _.options.slidesToShow) {
  1875. _.$prevArrow.hide();
  1876. _.$nextArrow.hide();
  1877. }
  1878. if (_.options.dots === true && _.slideCount > _.options.slidesToShow) {
  1879. _.$dots.hide();
  1880. }
  1881. _.$slider.addClass('slick-loading');
  1882. };
  1883. Slick.prototype.swipeDirection = function() {
  1884. var xDist, yDist, r, swipeAngle, _ = this;
  1885. xDist = _.touchObject.startX - _.touchObject.curX;
  1886. yDist = _.touchObject.startY - _.touchObject.curY;
  1887. r = Math.atan2(yDist, xDist);
  1888. swipeAngle = Math.round(r * 180 / Math.PI);
  1889. if (swipeAngle < 0) {
  1890. swipeAngle = 360 - Math.abs(swipeAngle);
  1891. }
  1892. if ((swipeAngle <= 45) && (swipeAngle >= 0)) {
  1893. return (_.options.rtl === false ? 'left' : 'right');
  1894. }
  1895. if ((swipeAngle <= 360) && (swipeAngle >= 315)) {
  1896. return (_.options.rtl === false ? 'left' : 'right');
  1897. }
  1898. if ((swipeAngle >= 135) && (swipeAngle <= 225)) {
  1899. return (_.options.rtl === false ? 'right' : 'left');
  1900. }
  1901. if (_.options.verticalSwiping === true) {
  1902. if ((swipeAngle >= 35) && (swipeAngle <= 135)) {
  1903. return 'down';
  1904. } else {
  1905. return 'up';
  1906. }
  1907. }
  1908. return 'vertical';
  1909. };
  1910. Slick.prototype.swipeEnd = function(event) {
  1911. var _ = this,
  1912. slideCount,
  1913. direction;
  1914. _.dragging = false;
  1915. _.swiping = false;
  1916. if (_.scrolling) {
  1917. _.scrolling = false;
  1918. return false;
  1919. }
  1920. _.interrupted = false;
  1921. _.shouldClick = ( _.touchObject.swipeLength > 10 ) ? false : true;
  1922. if ( _.touchObject.curX === undefined ) {
  1923. return false;
  1924. }
  1925. if ( _.touchObject.edgeHit === true ) {
  1926. _.$slider.trigger('edge', [_, _.swipeDirection() ]);
  1927. }
  1928. if ( _.touchObject.swipeLength >= _.touchObject.minSwipe ) {
  1929. direction = _.swipeDirection();
  1930. switch ( direction ) {
  1931. case 'left':
  1932. case 'down':
  1933. slideCount =
  1934. _.options.swipeToSlide ?
  1935. _.checkNavigable( _.currentSlide + _.getSlideCount() ) :
  1936. _.currentSlide + _.getSlideCount();
  1937. _.currentDirection = 0;
  1938. break;
  1939. case 'right':
  1940. case 'up':
  1941. slideCount =
  1942. _.options.swipeToSlide ?
  1943. _.checkNavigable( _.currentSlide - _.getSlideCount() ) :
  1944. _.currentSlide - _.getSlideCount();
  1945. _.currentDirection = 1;
  1946. break;
  1947. default:
  1948. }
  1949. if( direction != 'vertical' ) {
  1950. _.slideHandler( slideCount );
  1951. _.touchObject = {};
  1952. _.$slider.trigger('swipe', [_, direction ]);
  1953. }
  1954. } else {
  1955. if ( _.touchObject.startX !== _.touchObject.curX ) {
  1956. _.slideHandler( _.currentSlide );
  1957. _.touchObject = {};
  1958. }
  1959. }
  1960. };
  1961. Slick.prototype.swipeHandler = function(event) {
  1962. var _ = this;
  1963. if ((_.options.swipe === false) || ('ontouchend' in document && _.options.swipe === false)) {
  1964. return;
  1965. } else if (_.options.draggable === false && event.type.indexOf('mouse') !== -1) {
  1966. return;
  1967. }
  1968. _.touchObject.fingerCount = event.originalEvent && event.originalEvent.touches !== undefined ?
  1969. event.originalEvent.touches.length : 1;
  1970. _.touchObject.minSwipe = _.listWidth / _.options
  1971. .touchThreshold;
  1972. if (_.options.verticalSwiping === true) {
  1973. _.touchObject.minSwipe = _.listHeight / _.options
  1974. .touchThreshold;
  1975. }
  1976. switch (event.data.action) {
  1977. case 'start':
  1978. _.swipeStart(event);
  1979. break;
  1980. case 'move':
  1981. _.swipeMove(event);
  1982. break;
  1983. case 'end':
  1984. _.swipeEnd(event);
  1985. break;
  1986. }
  1987. };
  1988. Slick.prototype.swipeMove = function(event) {
  1989. var _ = this,
  1990. edgeWasHit = false,
  1991. curLeft, swipeDirection, swipeLength, positionOffset, touches, verticalSwipeLength;
  1992. touches = event.originalEvent !== undefined ? event.originalEvent.touches : null;
  1993. if (!_.dragging || _.scrolling || touches && touches.length !== 1) {
  1994. return false;
  1995. }
  1996. curLeft = _.getLeft(_.currentSlide);
  1997. _.touchObject.curX = touches !== undefined ? touches[0].pageX : event.clientX;
  1998. _.touchObject.curY = touches !== undefined ? touches[0].pageY : event.clientY;
  1999. _.touchObject.swipeLength = Math.round(Math.sqrt(
  2000. Math.pow(_.touchObject.curX - _.touchObject.startX, 2)));
  2001. verticalSwipeLength = Math.round(Math.sqrt(
  2002. Math.pow(_.touchObject.curY - _.touchObject.startY, 2)));
  2003. if (!_.options.verticalSwiping && !_.swiping && verticalSwipeLength > 4) {
  2004. _.scrolling = true;
  2005. return false;
  2006. }
  2007. if (_.options.verticalSwiping === true) {
  2008. _.touchObject.swipeLength = verticalSwipeLength;
  2009. }
  2010. swipeDirection = _.swipeDirection();
  2011. if (event.originalEvent !== undefined && _.touchObject.swipeLength > 4) {
  2012. _.swiping = true;
  2013. event.preventDefault();
  2014. }
  2015. positionOffset = (_.options.rtl === false ? 1 : -1) * (_.touchObject.curX > _.touchObject.startX ? 1 : -1);
  2016. if (_.options.verticalSwiping === true) {
  2017. positionOffset = _.touchObject.curY > _.touchObject.startY ? 1 : -1;
  2018. }
  2019. swipeLength = _.touchObject.swipeLength;
  2020. _.touchObject.edgeHit = false;
  2021. if (_.options.infinite === false) {
  2022. if ((_.currentSlide === 0 && swipeDirection === 'right') || (_.currentSlide >= _.getDotCount() && swipeDirection === 'left')) {
  2023. swipeLength = _.touchObject.swipeLength * _.options.edgeFriction;
  2024. _.touchObject.edgeHit = true;
  2025. }
  2026. }
  2027. if (_.options.vertical === false) {
  2028. _.swipeLeft = curLeft + swipeLength * positionOffset;
  2029. } else {
  2030. _.swipeLeft = curLeft + (swipeLength * (_.$list.height() / _.listWidth)) * positionOffset;
  2031. }
  2032. if (_.options.verticalSwiping === true) {
  2033. _.swipeLeft = curLeft + swipeLength * positionOffset;
  2034. }
  2035. if (_.options.fade === true || _.options.touchMove === false) {
  2036. return false;
  2037. }
  2038. if (_.animating === true) {
  2039. _.swipeLeft = null;
  2040. return false;
  2041. }
  2042. _.setCSS(_.swipeLeft);
  2043. };
  2044. Slick.prototype.swipeStart = function(event) {
  2045. var _ = this,
  2046. touches;
  2047. _.interrupted = true;
  2048. if (_.touchObject.fingerCount !== 1 || _.slideCount <= _.options.slidesToShow) {
  2049. _.touchObject = {};
  2050. return false;
  2051. }
  2052. if (event.originalEvent !== undefined && event.originalEvent.touches !== undefined) {
  2053. touches = event.originalEvent.touches[0];
  2054. }
  2055. _.touchObject.startX = _.touchObject.curX = touches !== undefined ? touches.pageX : event.clientX;
  2056. _.touchObject.startY = _.touchObject.curY = touches !== undefined ? touches.pageY : event.clientY;
  2057. _.dragging = true;
  2058. };
  2059. Slick.prototype.unfilterSlides = Slick.prototype.slickUnfilter = function() {
  2060. var _ = this;
  2061. if (_.$slidesCache !== null) {
  2062. _.unload();
  2063. _.$slideTrack.children(this.options.slide).detach();
  2064. _.$slidesCache.appendTo(_.$slideTrack);
  2065. _.reinit();
  2066. }
  2067. };
  2068. Slick.prototype.unload = function() {
  2069. var _ = this;
  2070. $('.slick-cloned', _.$slider).remove();
  2071. if (_.$dots) {
  2072. _.$dots.remove();
  2073. }
  2074. if (_.$prevArrow && _.htmlExpr.test(_.options.prevArrow)) {
  2075. _.$prevArrow.remove();
  2076. }
  2077. if (_.$nextArrow && _.htmlExpr.test(_.options.nextArrow)) {
  2078. _.$nextArrow.remove();
  2079. }
  2080. _.$slides
  2081. .removeClass('slick-slide slick-active slick-visible slick-current')
  2082. .attr('aria-hidden', 'true')
  2083. .css('width', '');
  2084. };
  2085. Slick.prototype.unslick = function(fromBreakpoint) {
  2086. var _ = this;
  2087. _.$slider.trigger('unslick', [_, fromBreakpoint]);
  2088. _.destroy();
  2089. };
  2090. Slick.prototype.updateArrows = function() {
  2091. var _ = this,
  2092. centerOffset;
  2093. centerOffset = Math.floor(_.options.slidesToShow / 2);
  2094. if ( _.options.arrows === true &&
  2095. _.slideCount > _.options.slidesToShow &&
  2096. !_.options.infinite ) {
  2097. _.$prevArrow.removeClass('slick-disabled').attr('aria-disabled', 'false');
  2098. _.$nextArrow.removeClass('slick-disabled').attr('aria-disabled', 'false');
  2099. if (_.currentSlide === 0) {
  2100. _.$prevArrow.addClass('slick-disabled').attr('aria-disabled', 'true');
  2101. _.$nextArrow.removeClass('slick-disabled').attr('aria-disabled', 'false');
  2102. } else if (_.currentSlide >= _.slideCount - _.options.slidesToShow && _.options.centerMode === false) {
  2103. _.$nextArrow.addClass('slick-disabled').attr('aria-disabled', 'true');
  2104. _.$prevArrow.removeClass('slick-disabled').attr('aria-disabled', 'false');
  2105. } else if (_.currentSlide >= _.slideCount - 1 && _.options.centerMode === true) {
  2106. _.$nextArrow.addClass('slick-disabled').attr('aria-disabled', 'true');
  2107. _.$prevArrow.removeClass('slick-disabled').attr('aria-disabled', 'false');
  2108. }
  2109. }
  2110. };
  2111. Slick.prototype.updateDots = function() {
  2112. var _ = this;
  2113. if (_.$dots !== null) {
  2114. _.$dots
  2115. .find('li')
  2116. .removeClass('slick-active')
  2117. .end();
  2118. _.$dots
  2119. .find('li')
  2120. .eq(Math.floor(_.currentSlide / _.options.slidesToScroll))
  2121. .addClass('slick-active');
  2122. }
  2123. };
  2124. Slick.prototype.visibility = function() {
  2125. var _ = this;
  2126. if ( _.options.autoplay ) {
  2127. if ( document[_.hidden] ) {
  2128. _.interrupted = true;
  2129. } else {
  2130. _.interrupted = false;
  2131. }
  2132. }
  2133. };
  2134. $.fn.slick = function() {
  2135. var _ = this,
  2136. opt = arguments[0],
  2137. args = Array.prototype.slice.call(arguments, 1),
  2138. l = _.length,
  2139. i,
  2140. ret;
  2141. for (i = 0; i < l; i++) {
  2142. if (typeof opt == 'object' || typeof opt == 'undefined')
  2143. _[i].slick = new Slick(_[i], opt);
  2144. else
  2145. ret = _[i].slick[opt].apply(_[i].slick, args);
  2146. if (typeof ret != 'undefined') return ret;
  2147. }
  2148. return _;
  2149. };
  2150. }));