slick.js 77 KB

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