swiper.jquery.umd.js 137 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290
  1. /**
  2. * Swiper 3.1.0
  3. * Most modern mobile touch slider and framework with hardware accelerated transitions
  4. *
  5. * http://www.idangero.us/swiper/
  6. *
  7. * Copyright 2015, Vladimir Kharlampidi
  8. * The iDangero.us
  9. * http://www.idangero.us/
  10. *
  11. * Licensed under MIT
  12. *
  13. * Released on: July 14, 2015
  14. */
  15. (function (root, factory) {
  16. 'use strict';
  17. if (typeof define === 'function' && define.amd) {
  18. // AMD. Register as an anonymous module.
  19. define(['jquery'], factory);
  20. } else if (typeof exports === 'object') {
  21. // Node. Does not work with strict CommonJS, but
  22. // only CommonJS-like environments that support module.exports,
  23. // like Node.
  24. module.exports = factory(require('jquery'));
  25. } else {
  26. // Browser globals (root is window)
  27. root.Swiper = factory(root.jQuery);
  28. }
  29. }(this, function ($) {
  30. 'use strict';
  31. /*===========================
  32. Swiper
  33. ===========================*/
  34. var Swiper = function (container, params) {
  35. if (!(this instanceof Swiper)) return new Swiper(container, params);
  36. var defaults = {
  37. direction: 'horizontal',
  38. touchEventsTarget: 'container',
  39. initialSlide: 0,
  40. speed: 300,
  41. // autoplay
  42. autoplay: false,
  43. autoplayDisableOnInteraction: true,
  44. // Free mode
  45. freeMode: false,
  46. freeModeMomentum: true,
  47. freeModeMomentumRatio: 1,
  48. freeModeMomentumBounce: true,
  49. freeModeMomentumBounceRatio: 1,
  50. freeModeSticky: false,
  51. // Set wrapper width
  52. setWrapperSize: false,
  53. // Virtual Translate
  54. virtualTranslate: false,
  55. // Effects
  56. effect: 'slide', // 'slide' or 'fade' or 'cube' or 'coverflow'
  57. coverflow: {
  58. rotate: 50,
  59. stretch: 0,
  60. depth: 100,
  61. modifier: 1,
  62. slideShadows : true
  63. },
  64. cube: {
  65. slideShadows: true,
  66. shadow: true,
  67. shadowOffset: 20,
  68. shadowScale: 0.94
  69. },
  70. fade: {
  71. crossFade: false
  72. },
  73. // Parallax
  74. parallax: false,
  75. // Scrollbar
  76. scrollbar: null,
  77. scrollbarHide: true,
  78. // Keyboard Mousewheel
  79. keyboardControl: false,
  80. mousewheelControl: false,
  81. mousewheelReleaseOnEdges: false,
  82. mousewheelInvert: false,
  83. mousewheelForceToAxis: false,
  84. // Hash Navigation
  85. hashnav: false,
  86. // Slides grid
  87. spaceBetween: 0,
  88. slidesPerView: 1,
  89. slidesPerColumn: 1,
  90. slidesPerColumnFill: 'column',
  91. slidesPerGroup: 1,
  92. centeredSlides: false,
  93. slidesOffsetBefore: 0, // in px
  94. slidesOffsetAfter: 0, // in px
  95. // Round length
  96. roundLengths: false,
  97. // Touches
  98. touchRatio: 1,
  99. touchAngle: 45,
  100. simulateTouch: true,
  101. shortSwipes: true,
  102. longSwipes: true,
  103. longSwipesRatio: 0.5,
  104. longSwipesMs: 300,
  105. followFinger: true,
  106. onlyExternal: false,
  107. threshold: 0,
  108. touchMoveStopPropagation: true,
  109. // Pagination
  110. pagination: null,
  111. paginationElement: 'span',
  112. paginationClickable: false,
  113. paginationHide: false,
  114. paginationBulletRender: null,
  115. // Resistance
  116. resistance: true,
  117. resistanceRatio: 0.85,
  118. // Next/prev buttons
  119. nextButton: null,
  120. prevButton: null,
  121. // Progress
  122. watchSlidesProgress: false,
  123. watchSlidesVisibility: false,
  124. // Cursor
  125. grabCursor: false,
  126. // Clicks
  127. preventClicks: true,
  128. preventClicksPropagation: true,
  129. slideToClickedSlide: false,
  130. // Lazy Loading
  131. lazyLoading: false,
  132. lazyLoadingInPrevNext: false,
  133. lazyLoadingOnTransitionStart: false,
  134. // Images
  135. preloadImages: true,
  136. updateOnImagesReady: true,
  137. // loop
  138. loop: false,
  139. loopAdditionalSlides: 0,
  140. loopedSlides: null,
  141. // Control
  142. control: undefined,
  143. controlInverse: false,
  144. controlBy: 'slide', //or 'container'
  145. // Swiping/no swiping
  146. allowSwipeToPrev: true,
  147. allowSwipeToNext: true,
  148. swipeHandler: null, //'.swipe-handler',
  149. noSwiping: true,
  150. noSwipingClass: 'swiper-no-swiping',
  151. // NS
  152. slideClass: 'swiper-slide',
  153. slideActiveClass: 'swiper-slide-active',
  154. slideVisibleClass: 'swiper-slide-visible',
  155. slideDuplicateClass: 'swiper-slide-duplicate',
  156. slideNextClass: 'swiper-slide-next',
  157. slidePrevClass: 'swiper-slide-prev',
  158. wrapperClass: 'swiper-wrapper',
  159. bulletClass: 'swiper-pagination-bullet',
  160. bulletActiveClass: 'swiper-pagination-bullet-active',
  161. buttonDisabledClass: 'swiper-button-disabled',
  162. paginationHiddenClass: 'swiper-pagination-hidden',
  163. // Observer
  164. observer: false,
  165. observeParents: false,
  166. // Accessibility
  167. a11y: false,
  168. prevSlideMessage: 'Previous slide',
  169. nextSlideMessage: 'Next slide',
  170. firstSlideMessage: 'This is the first slide',
  171. lastSlideMessage: 'This is the last slide',
  172. paginationBulletMessage: 'Go to slide {{index}}',
  173. // Callbacks
  174. runCallbacksOnInit: true
  175. /*
  176. Callbacks:
  177. onInit: function (swiper)
  178. onDestroy: function (swiper)
  179. onClick: function (swiper, e)
  180. onTap: function (swiper, e)
  181. onDoubleTap: function (swiper, e)
  182. onSliderMove: function (swiper, e)
  183. onSlideChangeStart: function (swiper)
  184. onSlideChangeEnd: function (swiper)
  185. onTransitionStart: function (swiper)
  186. onTransitionEnd: function (swiper)
  187. onImagesReady: function (swiper)
  188. onProgress: function (swiper, progress)
  189. onTouchStart: function (swiper, e)
  190. onTouchMove: function (swiper, e)
  191. onTouchMoveOpposite: function (swiper, e)
  192. onTouchEnd: function (swiper, e)
  193. onReachBeginning: function (swiper)
  194. onReachEnd: function (swiper)
  195. onSetTransition: function (swiper, duration)
  196. onSetTranslate: function (swiper, translate)
  197. onAutoplayStart: function (swiper)
  198. onAutoplayStop: function (swiper),
  199. onLazyImageLoad: function (swiper, slide, image)
  200. onLazyImageReady: function (swiper, slide, image)
  201. */
  202. };
  203. var initialVirtualTranslate = params && params.virtualTranslate;
  204. params = params || {};
  205. for (var def in defaults) {
  206. if (typeof params[def] === 'undefined') {
  207. params[def] = defaults[def];
  208. }
  209. else if (typeof params[def] === 'object') {
  210. for (var deepDef in defaults[def]) {
  211. if (typeof params[def][deepDef] === 'undefined') {
  212. params[def][deepDef] = defaults[def][deepDef];
  213. }
  214. }
  215. }
  216. }
  217. // Swiper
  218. var s = this;
  219. // Version
  220. s.version = '3.1.0';
  221. // Params
  222. s.params = params;
  223. // Classname
  224. s.classNames = [];
  225. /*=========================
  226. Dom Library and plugins
  227. ===========================*/
  228. if (typeof $ !== 'undefined' && typeof Dom7 !== 'undefined'){
  229. $ = Dom7;
  230. }
  231. if (typeof $ === 'undefined') {
  232. if (typeof Dom7 === 'undefined') {
  233. $ = window.Dom7 || window.Zepto || window.jQuery;
  234. }
  235. else {
  236. $ = Dom7;
  237. }
  238. if (!$) return;
  239. }
  240. // Export it to Swiper instance
  241. s.$ = $;
  242. /*=========================
  243. Preparation - Define Container, Wrapper and Pagination
  244. ===========================*/
  245. s.container = $(container);
  246. if (s.container.length === 0) return;
  247. if (s.container.length > 1) {
  248. s.container.each(function () {
  249. new Swiper(this, params);
  250. });
  251. return;
  252. }
  253. // Save instance in container HTML Element and in data
  254. s.container[0].swiper = s;
  255. s.container.data('swiper', s);
  256. s.classNames.push('swiper-container-' + s.params.direction);
  257. if (s.params.freeMode) {
  258. s.classNames.push('swiper-container-free-mode');
  259. }
  260. if (!s.support.flexbox) {
  261. s.classNames.push('swiper-container-no-flexbox');
  262. s.params.slidesPerColumn = 1;
  263. }
  264. // Enable slides progress when required
  265. if (s.params.parallax || s.params.watchSlidesVisibility) {
  266. s.params.watchSlidesProgress = true;
  267. }
  268. // Coverflow / 3D
  269. if (['cube', 'coverflow'].indexOf(s.params.effect) >= 0) {
  270. if (s.support.transforms3d) {
  271. s.params.watchSlidesProgress = true;
  272. s.classNames.push('swiper-container-3d');
  273. }
  274. else {
  275. s.params.effect = 'slide';
  276. }
  277. }
  278. if (s.params.effect !== 'slide') {
  279. s.classNames.push('swiper-container-' + s.params.effect);
  280. }
  281. if (s.params.effect === 'cube') {
  282. s.params.resistanceRatio = 0;
  283. s.params.slidesPerView = 1;
  284. s.params.slidesPerColumn = 1;
  285. s.params.slidesPerGroup = 1;
  286. s.params.centeredSlides = false;
  287. s.params.spaceBetween = 0;
  288. s.params.virtualTranslate = true;
  289. s.params.setWrapperSize = false;
  290. }
  291. if (s.params.effect === 'fade') {
  292. s.params.slidesPerView = 1;
  293. s.params.slidesPerColumn = 1;
  294. s.params.slidesPerGroup = 1;
  295. s.params.watchSlidesProgress = true;
  296. s.params.spaceBetween = 0;
  297. if (typeof initialVirtualTranslate === 'undefined') {
  298. s.params.virtualTranslate = true;
  299. }
  300. }
  301. // Grab Cursor
  302. if (s.params.grabCursor && s.support.touch) {
  303. s.params.grabCursor = false;
  304. }
  305. // Wrapper
  306. s.wrapper = s.container.children('.' + s.params.wrapperClass);
  307. // Pagination
  308. if (s.params.pagination) {
  309. s.paginationContainer = $(s.params.pagination);
  310. if (s.params.paginationClickable) {
  311. s.paginationContainer.addClass('swiper-pagination-clickable');
  312. }
  313. }
  314. // Is Horizontal
  315. function isH() {
  316. return s.params.direction === 'horizontal';
  317. }
  318. // RTL
  319. s.rtl = isH() && (s.container[0].dir.toLowerCase() === 'rtl' || s.container.css('direction') === 'rtl');
  320. if (s.rtl) {
  321. s.classNames.push('swiper-container-rtl');
  322. }
  323. // Wrong RTL support
  324. if (s.rtl) {
  325. s.wrongRTL = s.wrapper.css('display') === '-webkit-box';
  326. }
  327. // Columns
  328. if (s.params.slidesPerColumn > 1) {
  329. s.classNames.push('swiper-container-multirow');
  330. }
  331. // Check for Android
  332. if (s.device.android) {
  333. s.classNames.push('swiper-container-android');
  334. }
  335. // Add classes
  336. s.container.addClass(s.classNames.join(' '));
  337. // Translate
  338. s.translate = 0;
  339. // Progress
  340. s.progress = 0;
  341. // Velocity
  342. s.velocity = 0;
  343. /*=========================
  344. Locks, unlocks
  345. ===========================*/
  346. s.lockSwipeToNext = function () {
  347. s.params.allowSwipeToNext = false;
  348. };
  349. s.lockSwipeToPrev = function () {
  350. s.params.allowSwipeToPrev = false;
  351. };
  352. s.lockSwipes = function () {
  353. s.params.allowSwipeToNext = s.params.allowSwipeToPrev = false;
  354. };
  355. s.unlockSwipeToNext = function () {
  356. s.params.allowSwipeToNext = true;
  357. };
  358. s.unlockSwipeToPrev = function () {
  359. s.params.allowSwipeToPrev = true;
  360. };
  361. s.unlockSwipes = function () {
  362. s.params.allowSwipeToNext = s.params.allowSwipeToPrev = true;
  363. };
  364. /*=========================
  365. Round helper
  366. ===========================*/
  367. function round(a) {
  368. return Math.floor(a);
  369. }
  370. /*=========================
  371. Set grab cursor
  372. ===========================*/
  373. if (s.params.grabCursor) {
  374. s.container[0].style.cursor = 'move';
  375. s.container[0].style.cursor = '-webkit-grab';
  376. s.container[0].style.cursor = '-moz-grab';
  377. s.container[0].style.cursor = 'grab';
  378. }
  379. /*=========================
  380. Update on Images Ready
  381. ===========================*/
  382. s.imagesToLoad = [];
  383. s.imagesLoaded = 0;
  384. s.loadImage = function (imgElement, src, checkForComplete, callback) {
  385. var image;
  386. function onReady () {
  387. if (callback) callback();
  388. }
  389. if (!imgElement.complete || !checkForComplete) {
  390. if (src) {
  391. image = new window.Image();
  392. image.onload = onReady;
  393. image.onerror = onReady;
  394. image.src = src;
  395. } else {
  396. onReady();
  397. }
  398. } else {//image already loaded...
  399. onReady();
  400. }
  401. };
  402. s.preloadImages = function () {
  403. s.imagesToLoad = s.container.find('img');
  404. function _onReady() {
  405. if (typeof s === 'undefined' || s === null) return;
  406. if (s.imagesLoaded !== undefined) s.imagesLoaded++;
  407. if (s.imagesLoaded === s.imagesToLoad.length) {
  408. if (s.params.updateOnImagesReady) s.update();
  409. s.emit('onImagesReady', s);
  410. }
  411. }
  412. for (var i = 0; i < s.imagesToLoad.length; i++) {
  413. s.loadImage(s.imagesToLoad[i], (s.imagesToLoad[i].currentSrc || s.imagesToLoad[i].getAttribute('src')), true, _onReady);
  414. }
  415. };
  416. /*=========================
  417. Autoplay
  418. ===========================*/
  419. s.autoplayTimeoutId = undefined;
  420. s.autoplaying = false;
  421. s.autoplayPaused = false;
  422. function autoplay() {
  423. s.autoplayTimeoutId = setTimeout(function () {
  424. if (s.params.loop) {
  425. s.fixLoop();
  426. s._slideNext();
  427. }
  428. else {
  429. if (!s.isEnd) {
  430. s._slideNext();
  431. }
  432. else {
  433. if (!params.autoplayStopOnLast) {
  434. s._slideTo(0);
  435. }
  436. else {
  437. s.stopAutoplay();
  438. }
  439. }
  440. }
  441. }, s.params.autoplay);
  442. }
  443. s.startAutoplay = function () {
  444. if (typeof s.autoplayTimeoutId !== 'undefined') return false;
  445. if (!s.params.autoplay) return false;
  446. if (s.autoplaying) return false;
  447. s.autoplaying = true;
  448. s.emit('onAutoplayStart', s);
  449. autoplay();
  450. };
  451. s.stopAutoplay = function (internal) {
  452. if (!s.autoplayTimeoutId) return;
  453. if (s.autoplayTimeoutId) clearTimeout(s.autoplayTimeoutId);
  454. s.autoplaying = false;
  455. s.autoplayTimeoutId = undefined;
  456. s.emit('onAutoplayStop', s);
  457. };
  458. s.pauseAutoplay = function (speed) {
  459. if (s.autoplayPaused) return;
  460. if (s.autoplayTimeoutId) clearTimeout(s.autoplayTimeoutId);
  461. s.autoplayPaused = true;
  462. if (speed === 0) {
  463. s.autoplayPaused = false;
  464. autoplay();
  465. }
  466. else {
  467. s.wrapper.transitionEnd(function () {
  468. if (!s) return;
  469. s.autoplayPaused = false;
  470. if (!s.autoplaying) {
  471. s.stopAutoplay();
  472. }
  473. else {
  474. autoplay();
  475. }
  476. });
  477. }
  478. };
  479. /*=========================
  480. Min/Max Translate
  481. ===========================*/
  482. s.minTranslate = function () {
  483. return (-s.snapGrid[0]);
  484. };
  485. s.maxTranslate = function () {
  486. return (-s.snapGrid[s.snapGrid.length - 1]);
  487. };
  488. /*=========================
  489. Slider/slides sizes
  490. ===========================*/
  491. s.updateContainerSize = function () {
  492. var width, height;
  493. if (typeof s.params.width !== 'undefined') {
  494. width = s.params.width;
  495. }
  496. else {
  497. width = s.container[0].clientWidth;
  498. }
  499. if (typeof s.params.height !== 'undefined') {
  500. height = s.params.height;
  501. }
  502. else {
  503. height = s.container[0].clientHeight;
  504. }
  505. if (width === 0 && isH() || height === 0 && !isH()) {
  506. return;
  507. }
  508. //Subtract paddings
  509. width = width - parseInt(s.container.css('padding-left'), 10) - parseInt(s.container.css('padding-right'), 10);
  510. height = height - parseInt(s.container.css('padding-top'), 10) - parseInt(s.container.css('padding-bottom'), 10);
  511. // Store values
  512. s.width = width;
  513. s.height = height;
  514. s.size = isH() ? s.width : s.height;
  515. };
  516. s.updateSlidesSize = function () {
  517. s.slides = s.wrapper.children('.' + s.params.slideClass);
  518. s.snapGrid = [];
  519. s.slidesGrid = [];
  520. s.slidesSizesGrid = [];
  521. var spaceBetween = s.params.spaceBetween,
  522. slidePosition = -s.params.slidesOffsetBefore,
  523. i,
  524. prevSlideSize = 0,
  525. index = 0;
  526. if (typeof spaceBetween === 'string' && spaceBetween.indexOf('%') >= 0) {
  527. spaceBetween = parseFloat(spaceBetween.replace('%', '')) / 100 * s.size;
  528. }
  529. s.virtualSize = -spaceBetween;
  530. // reset margins
  531. if (s.rtl) s.slides.css({marginLeft: '', marginTop: ''});
  532. else s.slides.css({marginRight: '', marginBottom: ''});
  533. var slidesNumberEvenToRows;
  534. if (s.params.slidesPerColumn > 1) {
  535. if (Math.floor(s.slides.length / s.params.slidesPerColumn) === s.slides.length / s.params.slidesPerColumn) {
  536. slidesNumberEvenToRows = s.slides.length;
  537. }
  538. else {
  539. slidesNumberEvenToRows = Math.ceil(s.slides.length / s.params.slidesPerColumn) * s.params.slidesPerColumn;
  540. }
  541. }
  542. // Calc slides
  543. var slideSize;
  544. var slidesPerColumn = s.params.slidesPerColumn;
  545. var slidesPerRow = slidesNumberEvenToRows / slidesPerColumn;
  546. var numFullColumns = slidesPerRow - (s.params.slidesPerColumn * slidesPerRow - s.slides.length);
  547. for (i = 0; i < s.slides.length; i++) {
  548. slideSize = 0;
  549. var slide = s.slides.eq(i);
  550. if (s.params.slidesPerColumn > 1) {
  551. // Set slides order
  552. var newSlideOrderIndex;
  553. var column, row;
  554. if (s.params.slidesPerColumnFill === 'column') {
  555. column = Math.floor(i / slidesPerColumn);
  556. row = i - column * slidesPerColumn;
  557. if (column > numFullColumns || (column === numFullColumns && row === slidesPerColumn-1)) {
  558. if (++row >= slidesPerColumn) {
  559. row = 0;
  560. column++;
  561. }
  562. }
  563. newSlideOrderIndex = column + row * slidesNumberEvenToRows / slidesPerColumn;
  564. slide
  565. .css({
  566. '-webkit-box-ordinal-group': newSlideOrderIndex,
  567. '-moz-box-ordinal-group': newSlideOrderIndex,
  568. '-ms-flex-order': newSlideOrderIndex,
  569. '-webkit-order': newSlideOrderIndex,
  570. 'order': newSlideOrderIndex
  571. });
  572. }
  573. else {
  574. row = Math.floor(i / slidesPerRow);
  575. column = i - row * slidesPerRow;
  576. }
  577. slide
  578. .css({
  579. 'margin-top': (row !== 0 && s.params.spaceBetween) && (s.params.spaceBetween + 'px')
  580. })
  581. .attr('data-swiper-column', column)
  582. .attr('data-swiper-row', row);
  583. }
  584. if (slide.css('display') === 'none') continue;
  585. if (s.params.slidesPerView === 'auto') {
  586. slideSize = isH() ? slide.outerWidth(true) : slide.outerHeight(true);
  587. if (s.params.roundLengths) slideSize = round(slideSize);
  588. }
  589. else {
  590. slideSize = (s.size - (s.params.slidesPerView - 1) * spaceBetween) / s.params.slidesPerView;
  591. if (s.params.roundLengths) slideSize = round(slideSize);
  592. if (isH()) {
  593. s.slides[i].style.width = slideSize + 'px';
  594. }
  595. else {
  596. s.slides[i].style.height = slideSize + 'px';
  597. }
  598. }
  599. s.slides[i].swiperSlideSize = slideSize;
  600. s.slidesSizesGrid.push(slideSize);
  601. if (s.params.centeredSlides) {
  602. slidePosition = slidePosition + slideSize / 2 + prevSlideSize / 2 + spaceBetween;
  603. if (i === 0) slidePosition = slidePosition - s.size / 2 - spaceBetween;
  604. if (Math.abs(slidePosition) < 1 / 1000) slidePosition = 0;
  605. if ((index) % s.params.slidesPerGroup === 0) s.snapGrid.push(slidePosition);
  606. s.slidesGrid.push(slidePosition);
  607. }
  608. else {
  609. if ((index) % s.params.slidesPerGroup === 0) s.snapGrid.push(slidePosition);
  610. s.slidesGrid.push(slidePosition);
  611. slidePosition = slidePosition + slideSize + spaceBetween;
  612. }
  613. s.virtualSize += slideSize + spaceBetween;
  614. prevSlideSize = slideSize;
  615. index ++;
  616. }
  617. s.virtualSize = Math.max(s.virtualSize, s.size) + s.params.slidesOffsetAfter;
  618. var newSlidesGrid;
  619. if (
  620. s.rtl && s.wrongRTL && (s.params.effect === 'slide' || s.params.effect === 'coverflow')) {
  621. s.wrapper.css({width: s.virtualSize + s.params.spaceBetween + 'px'});
  622. }
  623. if (!s.support.flexbox || s.params.setWrapperSize) {
  624. if (isH()) s.wrapper.css({width: s.virtualSize + s.params.spaceBetween + 'px'});
  625. else s.wrapper.css({height: s.virtualSize + s.params.spaceBetween + 'px'});
  626. }
  627. if (s.params.slidesPerColumn > 1) {
  628. s.virtualSize = (slideSize + s.params.spaceBetween) * slidesNumberEvenToRows;
  629. s.virtualSize = Math.ceil(s.virtualSize / s.params.slidesPerColumn) - s.params.spaceBetween;
  630. s.wrapper.css({width: s.virtualSize + s.params.spaceBetween + 'px'});
  631. if (s.params.centeredSlides) {
  632. newSlidesGrid = [];
  633. for (i = 0; i < s.snapGrid.length; i++) {
  634. if (s.snapGrid[i] < s.virtualSize + s.snapGrid[0]) newSlidesGrid.push(s.snapGrid[i]);
  635. }
  636. s.snapGrid = newSlidesGrid;
  637. }
  638. }
  639. // Remove last grid elements depending on width
  640. if (!s.params.centeredSlides) {
  641. newSlidesGrid = [];
  642. for (i = 0; i < s.snapGrid.length; i++) {
  643. if (s.snapGrid[i] <= s.virtualSize - s.size) {
  644. newSlidesGrid.push(s.snapGrid[i]);
  645. }
  646. }
  647. s.snapGrid = newSlidesGrid;
  648. if (Math.floor(s.virtualSize - s.size) > Math.floor(s.snapGrid[s.snapGrid.length - 1])) {
  649. s.snapGrid.push(s.virtualSize - s.size);
  650. }
  651. }
  652. if (s.snapGrid.length === 0) s.snapGrid = [0];
  653. if (s.params.spaceBetween !== 0) {
  654. if (isH()) {
  655. if (s.rtl) s.slides.css({marginLeft: spaceBetween + 'px'});
  656. else s.slides.css({marginRight: spaceBetween + 'px'});
  657. }
  658. else s.slides.css({marginBottom: spaceBetween + 'px'});
  659. }
  660. if (s.params.watchSlidesProgress) {
  661. s.updateSlidesOffset();
  662. }
  663. };
  664. s.updateSlidesOffset = function () {
  665. for (var i = 0; i < s.slides.length; i++) {
  666. s.slides[i].swiperSlideOffset = isH() ? s.slides[i].offsetLeft : s.slides[i].offsetTop;
  667. }
  668. };
  669. /*=========================
  670. Slider/slides progress
  671. ===========================*/
  672. s.updateSlidesProgress = function (translate) {
  673. if (typeof translate === 'undefined') {
  674. translate = s.translate || 0;
  675. }
  676. if (s.slides.length === 0) return;
  677. if (typeof s.slides[0].swiperSlideOffset === 'undefined') s.updateSlidesOffset();
  678. var offsetCenter = s.params.centeredSlides ? -translate + s.size / 2 : -translate;
  679. if (s.rtl) offsetCenter = s.params.centeredSlides ? translate - s.size / 2 : translate;
  680. // Visible Slides
  681. var containerBox = s.container[0].getBoundingClientRect();
  682. var sideBefore = isH() ? 'left' : 'top';
  683. var sideAfter = isH() ? 'right' : 'bottom';
  684. s.slides.removeClass(s.params.slideVisibleClass);
  685. for (var i = 0; i < s.slides.length; i++) {
  686. var slide = s.slides[i];
  687. var slideCenterOffset = (s.params.centeredSlides === true) ? slide.swiperSlideSize / 2 : 0;
  688. var slideProgress = (offsetCenter - slide.swiperSlideOffset - slideCenterOffset) / (slide.swiperSlideSize + s.params.spaceBetween);
  689. if (s.params.watchSlidesVisibility) {
  690. var slideBefore = -(offsetCenter - slide.swiperSlideOffset - slideCenterOffset);
  691. var slideAfter = slideBefore + s.slidesSizesGrid[i];
  692. var isVisible =
  693. (slideBefore >= 0 && slideBefore < s.size) ||
  694. (slideAfter > 0 && slideAfter <= s.size) ||
  695. (slideBefore <= 0 && slideAfter >= s.size);
  696. if (isVisible) {
  697. s.slides.eq(i).addClass(s.params.slideVisibleClass);
  698. }
  699. }
  700. slide.progress = s.rtl ? -slideProgress : slideProgress;
  701. }
  702. };
  703. s.updateProgress = function (translate) {
  704. if (typeof translate === 'undefined') {
  705. translate = s.translate || 0;
  706. }
  707. var translatesDiff = s.maxTranslate() - s.minTranslate();
  708. if (translatesDiff === 0) {
  709. s.progress = 0;
  710. s.isBeginning = s.isEnd = true;
  711. }
  712. else {
  713. s.progress = (translate - s.minTranslate()) / (translatesDiff);
  714. s.isBeginning = s.progress <= 0;
  715. s.isEnd = s.progress >= 1;
  716. }
  717. if (s.isBeginning) s.emit('onReachBeginning', s);
  718. if (s.isEnd) s.emit('onReachEnd', s);
  719. if (s.params.watchSlidesProgress) s.updateSlidesProgress(translate);
  720. s.emit('onProgress', s, s.progress);
  721. };
  722. s.updateActiveIndex = function () {
  723. var translate = s.rtl ? s.translate : -s.translate;
  724. var newActiveIndex, i, snapIndex;
  725. for (i = 0; i < s.slidesGrid.length; i ++) {
  726. if (typeof s.slidesGrid[i + 1] !== 'undefined') {
  727. if (translate >= s.slidesGrid[i] && translate < s.slidesGrid[i + 1] - (s.slidesGrid[i + 1] - s.slidesGrid[i]) / 2) {
  728. newActiveIndex = i;
  729. }
  730. else if (translate >= s.slidesGrid[i] && translate < s.slidesGrid[i + 1]) {
  731. newActiveIndex = i + 1;
  732. }
  733. }
  734. else {
  735. if (translate >= s.slidesGrid[i]) {
  736. newActiveIndex = i;
  737. }
  738. }
  739. }
  740. // Normalize slideIndex
  741. if (newActiveIndex < 0 || typeof newActiveIndex === 'undefined') newActiveIndex = 0;
  742. // for (i = 0; i < s.slidesGrid.length; i++) {
  743. // if (- translate >= s.slidesGrid[i]) {
  744. // newActiveIndex = i;
  745. // }
  746. // }
  747. snapIndex = Math.floor(newActiveIndex / s.params.slidesPerGroup);
  748. if (snapIndex >= s.snapGrid.length) snapIndex = s.snapGrid.length - 1;
  749. if (newActiveIndex === s.activeIndex) {
  750. return;
  751. }
  752. s.snapIndex = snapIndex;
  753. s.previousIndex = s.activeIndex;
  754. s.activeIndex = newActiveIndex;
  755. s.updateClasses();
  756. };
  757. /*=========================
  758. Classes
  759. ===========================*/
  760. s.updateClasses = function () {
  761. s.slides.removeClass(s.params.slideActiveClass + ' ' + s.params.slideNextClass + ' ' + s.params.slidePrevClass);
  762. var activeSlide = s.slides.eq(s.activeIndex);
  763. // Active classes
  764. activeSlide.addClass(s.params.slideActiveClass);
  765. activeSlide.next('.' + s.params.slideClass).addClass(s.params.slideNextClass);
  766. activeSlide.prev('.' + s.params.slideClass).addClass(s.params.slidePrevClass);
  767. // Pagination
  768. if (s.bullets && s.bullets.length > 0) {
  769. s.bullets.removeClass(s.params.bulletActiveClass);
  770. var bulletIndex;
  771. if (s.params.loop) {
  772. bulletIndex = Math.ceil(s.activeIndex - s.loopedSlides)/s.params.slidesPerGroup;
  773. if (bulletIndex > s.slides.length - 1 - s.loopedSlides * 2) {
  774. bulletIndex = bulletIndex - (s.slides.length - s.loopedSlides * 2);
  775. }
  776. if (bulletIndex > s.bullets.length - 1) bulletIndex = bulletIndex - s.bullets.length;
  777. }
  778. else {
  779. if (typeof s.snapIndex !== 'undefined') {
  780. bulletIndex = s.snapIndex;
  781. }
  782. else {
  783. bulletIndex = s.activeIndex || 0;
  784. }
  785. }
  786. if (s.paginationContainer.length > 1) {
  787. s.bullets.each(function () {
  788. if ($(this).index() === bulletIndex) $(this).addClass(s.params.bulletActiveClass);
  789. });
  790. }
  791. else {
  792. s.bullets.eq(bulletIndex).addClass(s.params.bulletActiveClass);
  793. }
  794. }
  795. // Next/active buttons
  796. if (!s.params.loop) {
  797. if (s.params.prevButton) {
  798. if (s.isBeginning) {
  799. $(s.params.prevButton).addClass(s.params.buttonDisabledClass);
  800. if (s.params.a11y && s.a11y) s.a11y.disable($(s.params.prevButton));
  801. }
  802. else {
  803. $(s.params.prevButton).removeClass(s.params.buttonDisabledClass);
  804. if (s.params.a11y && s.a11y) s.a11y.enable($(s.params.prevButton));
  805. }
  806. }
  807. if (s.params.nextButton) {
  808. if (s.isEnd) {
  809. $(s.params.nextButton).addClass(s.params.buttonDisabledClass);
  810. if (s.params.a11y && s.a11y) s.a11y.disable($(s.params.nextButton));
  811. }
  812. else {
  813. $(s.params.nextButton).removeClass(s.params.buttonDisabledClass);
  814. if (s.params.a11y && s.a11y) s.a11y.enable($(s.params.nextButton));
  815. }
  816. }
  817. }
  818. };
  819. /*=========================
  820. Pagination
  821. ===========================*/
  822. s.updatePagination = function () {
  823. if (!s.params.pagination) return;
  824. if (s.paginationContainer && s.paginationContainer.length > 0) {
  825. var bulletsHTML = '';
  826. var numberOfBullets = s.params.loop ? Math.ceil((s.slides.length - s.loopedSlides * 2) / s.params.slidesPerGroup) : s.snapGrid.length;
  827. for (var i = 0; i < numberOfBullets; i++) {
  828. if (s.params.paginationBulletRender) {
  829. bulletsHTML += s.params.paginationBulletRender(i, s.params.bulletClass);
  830. }
  831. else {
  832. bulletsHTML += '<' + s.params.paginationElement+' class="' + s.params.bulletClass + '"></' + s.params.paginationElement + '>';
  833. }
  834. }
  835. s.paginationContainer.html(bulletsHTML);
  836. s.bullets = s.paginationContainer.find('.' + s.params.bulletClass);
  837. if (s.params.paginationClickable && s.params.a11y && s.a11y) {
  838. s.a11y.initPagination();
  839. }
  840. }
  841. };
  842. /*=========================
  843. Common update method
  844. ===========================*/
  845. s.update = function (updateTranslate) {
  846. s.updateContainerSize();
  847. s.updateSlidesSize();
  848. s.updateProgress();
  849. s.updatePagination();
  850. s.updateClasses();
  851. if (s.params.scrollbar && s.scrollbar) {
  852. s.scrollbar.set();
  853. }
  854. function forceSetTranslate() {
  855. newTranslate = Math.min(Math.max(s.translate, s.maxTranslate()), s.minTranslate());
  856. s.setWrapperTranslate(newTranslate);
  857. s.updateActiveIndex();
  858. s.updateClasses();
  859. }
  860. if (updateTranslate) {
  861. var translated, newTranslate;
  862. if (s.controller && s.controller.spline) {
  863. s.controller.spline = undefined;
  864. }
  865. if (s.params.freeMode) {
  866. forceSetTranslate();
  867. }
  868. else {
  869. if ((s.params.slidesPerView === 'auto' || s.params.slidesPerView > 1) && s.isEnd && !s.params.centeredSlides) {
  870. translated = s.slideTo(s.slides.length - 1, 0, false, true);
  871. }
  872. else {
  873. translated = s.slideTo(s.activeIndex, 0, false, true);
  874. }
  875. if (!translated) {
  876. forceSetTranslate();
  877. }
  878. }
  879. }
  880. };
  881. /*=========================
  882. Resize Handler
  883. ===========================*/
  884. s.onResize = function (forceUpdatePagination) {
  885. // Disable locks on resize
  886. var allowSwipeToPrev = s.params.allowSwipeToPrev;
  887. var allowSwipeToNext = s.params.allowSwipeToNext;
  888. s.params.allowSwipeToPrev = s.params.allowSwipeToNext = true;
  889. s.updateContainerSize();
  890. s.updateSlidesSize();
  891. if (s.params.slidesPerView === 'auto' || s.params.freeMode || forceUpdatePagination) s.updatePagination();
  892. if (s.params.scrollbar && s.scrollbar) {
  893. s.scrollbar.set();
  894. }
  895. if (s.controller && s.controller.spline) {
  896. s.controller.spline = undefined;
  897. }
  898. if (s.params.freeMode) {
  899. var newTranslate = Math.min(Math.max(s.translate, s.maxTranslate()), s.minTranslate());
  900. s.setWrapperTranslate(newTranslate);
  901. s.updateActiveIndex();
  902. s.updateClasses();
  903. }
  904. else {
  905. s.updateClasses();
  906. if ((s.params.slidesPerView === 'auto' || s.params.slidesPerView > 1) && s.isEnd && !s.params.centeredSlides) {
  907. s.slideTo(s.slides.length - 1, 0, false, true);
  908. }
  909. else {
  910. s.slideTo(s.activeIndex, 0, false, true);
  911. }
  912. }
  913. // Return locks after resize
  914. s.params.allowSwipeToPrev = allowSwipeToPrev;
  915. s.params.allowSwipeToNext = allowSwipeToNext;
  916. };
  917. /*=========================
  918. Events
  919. ===========================*/
  920. //Define Touch Events
  921. var desktopEvents = ['mousedown', 'mousemove', 'mouseup'];
  922. if (window.navigator.pointerEnabled) desktopEvents = ['pointerdown', 'pointermove', 'pointerup'];
  923. else if (window.navigator.msPointerEnabled) desktopEvents = ['MSPointerDown', 'MSPointerMove', 'MSPointerUp'];
  924. s.touchEvents = {
  925. start : s.support.touch || !s.params.simulateTouch ? 'touchstart' : desktopEvents[0],
  926. move : s.support.touch || !s.params.simulateTouch ? 'touchmove' : desktopEvents[1],
  927. end : s.support.touch || !s.params.simulateTouch ? 'touchend' : desktopEvents[2]
  928. };
  929. // WP8 Touch Events Fix
  930. if (window.navigator.pointerEnabled || window.navigator.msPointerEnabled) {
  931. (s.params.touchEventsTarget === 'container' ? s.container : s.wrapper).addClass('swiper-wp8-' + s.params.direction);
  932. }
  933. // Attach/detach events
  934. s.initEvents = function (detach) {
  935. var actionDom = detach ? 'off' : 'on';
  936. var action = detach ? 'removeEventListener' : 'addEventListener';
  937. var touchEventsTarget = s.params.touchEventsTarget === 'container' ? s.container[0] : s.wrapper[0];
  938. var target = s.support.touch ? touchEventsTarget : document;
  939. var moveCapture = s.params.nested ? true : false;
  940. //Touch Events
  941. if (s.browser.ie) {
  942. touchEventsTarget[action](s.touchEvents.start, s.onTouchStart, false);
  943. target[action](s.touchEvents.move, s.onTouchMove, moveCapture);
  944. target[action](s.touchEvents.end, s.onTouchEnd, false);
  945. }
  946. else {
  947. if (s.support.touch) {
  948. touchEventsTarget[action](s.touchEvents.start, s.onTouchStart, false);
  949. touchEventsTarget[action](s.touchEvents.move, s.onTouchMove, moveCapture);
  950. touchEventsTarget[action](s.touchEvents.end, s.onTouchEnd, false);
  951. }
  952. if (params.simulateTouch && !s.device.ios && !s.device.android) {
  953. touchEventsTarget[action]('mousedown', s.onTouchStart, false);
  954. document[action]('mousemove', s.onTouchMove, moveCapture);
  955. document[action]('mouseup', s.onTouchEnd, false);
  956. }
  957. }
  958. window[action]('resize', s.onResize);
  959. // Next, Prev, Index
  960. if (s.params.nextButton) {
  961. $(s.params.nextButton)[actionDom]('click', s.onClickNext);
  962. if (s.params.a11y && s.a11y) $(s.params.nextButton)[actionDom]('keydown', s.a11y.onEnterKey);
  963. }
  964. if (s.params.prevButton) {
  965. $(s.params.prevButton)[actionDom]('click', s.onClickPrev);
  966. if (s.params.a11y && s.a11y) $(s.params.prevButton)[actionDom]('keydown', s.a11y.onEnterKey);
  967. }
  968. if (s.params.pagination && s.params.paginationClickable) {
  969. $(s.paginationContainer)[actionDom]('click', '.' + s.params.bulletClass, s.onClickIndex);
  970. if (s.params.a11y && s.a11y) $(s.paginationContainer)[actionDom]('keydown', '.' + s.params.bulletClass, s.a11y.onEnterKey);
  971. }
  972. // Prevent Links Clicks
  973. if (s.params.preventClicks || s.params.preventClicksPropagation) touchEventsTarget[action]('click', s.preventClicks, true);
  974. };
  975. s.attachEvents = function (detach) {
  976. s.initEvents();
  977. };
  978. s.detachEvents = function () {
  979. s.initEvents(true);
  980. };
  981. /*=========================
  982. Handle Clicks
  983. ===========================*/
  984. // Prevent Clicks
  985. s.allowClick = true;
  986. s.preventClicks = function (e) {
  987. if (!s.allowClick) {
  988. if (s.params.preventClicks) e.preventDefault();
  989. if (s.params.preventClicksPropagation && s.animating) {
  990. e.stopPropagation();
  991. e.stopImmediatePropagation();
  992. }
  993. }
  994. };
  995. // Clicks
  996. s.onClickNext = function (e) {
  997. e.preventDefault();
  998. if (s.isEnd && !s.params.loop) return;
  999. s.slideNext();
  1000. };
  1001. s.onClickPrev = function (e) {
  1002. e.preventDefault();
  1003. if (s.isBeginning && !s.params.loop) return;
  1004. s.slidePrev();
  1005. };
  1006. s.onClickIndex = function (e) {
  1007. e.preventDefault();
  1008. var index = $(this).index() * s.params.slidesPerGroup;
  1009. if (s.params.loop) index = index + s.loopedSlides;
  1010. s.slideTo(index);
  1011. };
  1012. /*=========================
  1013. Handle Touches
  1014. ===========================*/
  1015. function findElementInEvent(e, selector) {
  1016. var el = $(e.target);
  1017. if (!el.is(selector)) {
  1018. if (typeof selector === 'string') {
  1019. el = el.parents(selector);
  1020. }
  1021. else if (selector.nodeType) {
  1022. var found;
  1023. el.parents().each(function (index, _el) {
  1024. if (_el === selector) found = selector;
  1025. });
  1026. if (!found) return undefined;
  1027. else return selector;
  1028. }
  1029. }
  1030. if (el.length === 0) {
  1031. return undefined;
  1032. }
  1033. return el[0];
  1034. }
  1035. s.updateClickedSlide = function (e) {
  1036. var slide = findElementInEvent(e, '.' + s.params.slideClass);
  1037. var slideFound = false;
  1038. if (slide) {
  1039. for (var i = 0; i < s.slides.length; i++) {
  1040. if (s.slides[i] === slide) slideFound = true;
  1041. }
  1042. }
  1043. if (slide && slideFound) {
  1044. s.clickedSlide = slide;
  1045. s.clickedIndex = $(slide).index();
  1046. }
  1047. else {
  1048. s.clickedSlide = undefined;
  1049. s.clickedIndex = undefined;
  1050. return;
  1051. }
  1052. if (s.params.slideToClickedSlide && s.clickedIndex !== undefined && s.clickedIndex !== s.activeIndex) {
  1053. var slideToIndex = s.clickedIndex,
  1054. realIndex;
  1055. if (s.params.loop) {
  1056. realIndex = $(s.clickedSlide).attr('data-swiper-slide-index');
  1057. if (slideToIndex > s.slides.length - s.params.slidesPerView) {
  1058. s.fixLoop();
  1059. slideToIndex = s.wrapper.children('.' + s.params.slideClass + '[data-swiper-slide-index="' + realIndex + '"]').eq(0).index();
  1060. setTimeout(function () {
  1061. s.slideTo(slideToIndex);
  1062. }, 0);
  1063. }
  1064. else if (slideToIndex < s.params.slidesPerView - 1) {
  1065. s.fixLoop();
  1066. var duplicatedSlides = s.wrapper.children('.' + s.params.slideClass + '[data-swiper-slide-index="' + realIndex + '"]');
  1067. slideToIndex = duplicatedSlides.eq(duplicatedSlides.length - 1).index();
  1068. setTimeout(function () {
  1069. s.slideTo(slideToIndex);
  1070. }, 0);
  1071. }
  1072. else {
  1073. s.slideTo(slideToIndex);
  1074. }
  1075. }
  1076. else {
  1077. s.slideTo(slideToIndex);
  1078. }
  1079. }
  1080. };
  1081. var isTouched,
  1082. isMoved,
  1083. touchStartTime,
  1084. isScrolling,
  1085. currentTranslate,
  1086. startTranslate,
  1087. allowThresholdMove,
  1088. // Form elements to match
  1089. formElements = 'input, select, textarea, button',
  1090. // Last click time
  1091. lastClickTime = Date.now(), clickTimeout,
  1092. //Velocities
  1093. velocities = [],
  1094. allowMomentumBounce;
  1095. // Animating Flag
  1096. s.animating = false;
  1097. // Touches information
  1098. s.touches = {
  1099. startX: 0,
  1100. startY: 0,
  1101. currentX: 0,
  1102. currentY: 0,
  1103. diff: 0
  1104. };
  1105. // Touch handlers
  1106. var isTouchEvent, startMoving;
  1107. s.onTouchStart = function (e) {
  1108. if (e.originalEvent) e = e.originalEvent;
  1109. isTouchEvent = e.type === 'touchstart';
  1110. if (!isTouchEvent && 'which' in e && e.which === 3) return;
  1111. if (s.params.noSwiping && findElementInEvent(e, '.' + s.params.noSwipingClass)) {
  1112. s.allowClick = true;
  1113. return;
  1114. }
  1115. if (s.params.swipeHandler) {
  1116. if (!findElementInEvent(e, s.params.swipeHandler)) return;
  1117. }
  1118. isTouched = true;
  1119. isMoved = false;
  1120. isScrolling = undefined;
  1121. startMoving = undefined;
  1122. s.touches.startX = s.touches.currentX = e.type === 'touchstart' ? e.targetTouches[0].pageX : e.pageX;
  1123. s.touches.startY = s.touches.currentY = e.type === 'touchstart' ? e.targetTouches[0].pageY : e.pageY;
  1124. touchStartTime = Date.now();
  1125. s.allowClick = true;
  1126. s.updateContainerSize();
  1127. s.swipeDirection = undefined;
  1128. if (s.params.threshold > 0) allowThresholdMove = false;
  1129. if (e.type !== 'touchstart') {
  1130. var preventDefault = true;
  1131. if ($(e.target).is(formElements)) preventDefault = false;
  1132. if (document.activeElement && $(document.activeElement).is(formElements)) {
  1133. document.activeElement.blur();
  1134. }
  1135. if (preventDefault) {
  1136. e.preventDefault();
  1137. }
  1138. }
  1139. s.emit('onTouchStart', s, e);
  1140. };
  1141. s.onTouchMove = function (e) {
  1142. if (e.originalEvent) e = e.originalEvent;
  1143. if (isTouchEvent && e.type === 'mousemove') return;
  1144. if (e.preventedByNestedSwiper) return;
  1145. if (s.params.onlyExternal) {
  1146. // isMoved = true;
  1147. s.allowClick = false;
  1148. if (isTouched) {
  1149. s.touches.startX = s.touches.currentX = e.type === 'touchmove' ? e.targetTouches[0].pageX : e.pageX;
  1150. s.touches.startY = s.touches.currentY = e.type === 'touchmove' ? e.targetTouches[0].pageY : e.pageY;
  1151. touchStartTime = Date.now();
  1152. }
  1153. return;
  1154. }
  1155. if (isTouchEvent && document.activeElement) {
  1156. if (e.target === document.activeElement && $(e.target).is(formElements)) {
  1157. isMoved = true;
  1158. s.allowClick = false;
  1159. return;
  1160. }
  1161. }
  1162. s.emit('onTouchMove', s, e);
  1163. if (e.targetTouches && e.targetTouches.length > 1) return;
  1164. s.touches.currentX = e.type === 'touchmove' ? e.targetTouches[0].pageX : e.pageX;
  1165. s.touches.currentY = e.type === 'touchmove' ? e.targetTouches[0].pageY : e.pageY;
  1166. if (typeof isScrolling === 'undefined') {
  1167. var touchAngle = Math.atan2(Math.abs(s.touches.currentY - s.touches.startY), Math.abs(s.touches.currentX - s.touches.startX)) * 180 / Math.PI;
  1168. isScrolling = isH() ? touchAngle > s.params.touchAngle : (90 - touchAngle > s.params.touchAngle);
  1169. }
  1170. if (isScrolling) {
  1171. s.emit('onTouchMoveOpposite', s, e);
  1172. }
  1173. if (typeof startMoving === 'undefined' && s.browser.ieTouch) {
  1174. if (s.touches.currentX !== s.touches.startX || s.touches.currentY !== s.touches.startY) {
  1175. startMoving = true;
  1176. }
  1177. }
  1178. if (!isTouched) return;
  1179. if (isScrolling) {
  1180. isTouched = false;
  1181. return;
  1182. }
  1183. if (!startMoving && s.browser.ieTouch) {
  1184. return;
  1185. }
  1186. s.allowClick = false;
  1187. s.emit('onSliderMove', s, e);
  1188. e.preventDefault();
  1189. if (s.params.touchMoveStopPropagation && !s.params.nested) {
  1190. e.stopPropagation();
  1191. }
  1192. if (!isMoved) {
  1193. if (params.loop) {
  1194. s.fixLoop();
  1195. }
  1196. startTranslate = s.getWrapperTranslate();
  1197. s.setWrapperTransition(0);
  1198. if (s.animating) {
  1199. s.wrapper.trigger('webkitTransitionEnd transitionend oTransitionEnd MSTransitionEnd msTransitionEnd');
  1200. }
  1201. if (s.params.autoplay && s.autoplaying) {
  1202. if (s.params.autoplayDisableOnInteraction) {
  1203. s.stopAutoplay();
  1204. }
  1205. else {
  1206. s.pauseAutoplay();
  1207. }
  1208. }
  1209. allowMomentumBounce = false;
  1210. //Grab Cursor
  1211. if (s.params.grabCursor) {
  1212. s.container[0].style.cursor = 'move';
  1213. s.container[0].style.cursor = '-webkit-grabbing';
  1214. s.container[0].style.cursor = '-moz-grabbin';
  1215. s.container[0].style.cursor = 'grabbing';
  1216. }
  1217. }
  1218. isMoved = true;
  1219. var diff = s.touches.diff = isH() ? s.touches.currentX - s.touches.startX : s.touches.currentY - s.touches.startY;
  1220. diff = diff * s.params.touchRatio;
  1221. if (s.rtl) diff = -diff;
  1222. s.swipeDirection = diff > 0 ? 'prev' : 'next';
  1223. currentTranslate = diff + startTranslate;
  1224. var disableParentSwiper = true;
  1225. if ((diff > 0 && currentTranslate > s.minTranslate())) {
  1226. disableParentSwiper = false;
  1227. if (s.params.resistance) currentTranslate = s.minTranslate() - 1 + Math.pow(-s.minTranslate() + startTranslate + diff, s.params.resistanceRatio);
  1228. }
  1229. else if (diff < 0 && currentTranslate < s.maxTranslate()) {
  1230. disableParentSwiper = false;
  1231. if (s.params.resistance) currentTranslate = s.maxTranslate() + 1 - Math.pow(s.maxTranslate() - startTranslate - diff, s.params.resistanceRatio);
  1232. }
  1233. if (disableParentSwiper) {
  1234. e.preventedByNestedSwiper = true;
  1235. }
  1236. // Directions locks
  1237. if (!s.params.allowSwipeToNext && s.swipeDirection === 'next' && currentTranslate < startTranslate) {
  1238. currentTranslate = startTranslate;
  1239. }
  1240. if (!s.params.allowSwipeToPrev && s.swipeDirection === 'prev' && currentTranslate > startTranslate) {
  1241. currentTranslate = startTranslate;
  1242. }
  1243. if (!s.params.followFinger) return;
  1244. // Threshold
  1245. if (s.params.threshold > 0) {
  1246. if (Math.abs(diff) > s.params.threshold || allowThresholdMove) {
  1247. if (!allowThresholdMove) {
  1248. allowThresholdMove = true;
  1249. s.touches.startX = s.touches.currentX;
  1250. s.touches.startY = s.touches.currentY;
  1251. currentTranslate = startTranslate;
  1252. s.touches.diff = isH() ? s.touches.currentX - s.touches.startX : s.touches.currentY - s.touches.startY;
  1253. return;
  1254. }
  1255. }
  1256. else {
  1257. currentTranslate = startTranslate;
  1258. return;
  1259. }
  1260. }
  1261. // Update active index in free mode
  1262. if (s.params.freeMode || s.params.watchSlidesProgress) {
  1263. s.updateActiveIndex();
  1264. }
  1265. if (s.params.freeMode) {
  1266. //Velocity
  1267. if (velocities.length === 0) {
  1268. velocities.push({
  1269. position: s.touches[isH() ? 'startX' : 'startY'],
  1270. time: touchStartTime
  1271. });
  1272. }
  1273. velocities.push({
  1274. position: s.touches[isH() ? 'currentX' : 'currentY'],
  1275. time: (new window.Date()).getTime()
  1276. });
  1277. }
  1278. // Update progress
  1279. s.updateProgress(currentTranslate);
  1280. // Update translate
  1281. s.setWrapperTranslate(currentTranslate);
  1282. };
  1283. s.onTouchEnd = function (e) {
  1284. if (e.originalEvent) e = e.originalEvent;
  1285. s.emit('onTouchEnd', s, e);
  1286. if (!isTouched) return;
  1287. //Return Grab Cursor
  1288. if (s.params.grabCursor && isMoved && isTouched) {
  1289. s.container[0].style.cursor = 'move';
  1290. s.container[0].style.cursor = '-webkit-grab';
  1291. s.container[0].style.cursor = '-moz-grab';
  1292. s.container[0].style.cursor = 'grab';
  1293. }
  1294. // Time diff
  1295. var touchEndTime = Date.now();
  1296. var timeDiff = touchEndTime - touchStartTime;
  1297. // Tap, doubleTap, Click
  1298. if (s.allowClick) {
  1299. s.updateClickedSlide(e);
  1300. s.emit('onTap', s, e);
  1301. if (timeDiff < 300 && (touchEndTime - lastClickTime) > 300) {
  1302. if (clickTimeout) clearTimeout(clickTimeout);
  1303. clickTimeout = setTimeout(function () {
  1304. if (!s) return;
  1305. if (s.params.paginationHide && s.paginationContainer.length > 0 && !$(e.target).hasClass(s.params.bulletClass)) {
  1306. s.paginationContainer.toggleClass(s.params.paginationHiddenClass);
  1307. }
  1308. s.emit('onClick', s, e);
  1309. }, 300);
  1310. }
  1311. if (timeDiff < 300 && (touchEndTime - lastClickTime) < 300) {
  1312. if (clickTimeout) clearTimeout(clickTimeout);
  1313. s.emit('onDoubleTap', s, e);
  1314. }
  1315. }
  1316. lastClickTime = Date.now();
  1317. setTimeout(function () {
  1318. if (s) s.allowClick = true;
  1319. }, 0);
  1320. if (!isTouched || !isMoved || !s.swipeDirection || s.touches.diff === 0 || currentTranslate === startTranslate) {
  1321. isTouched = isMoved = false;
  1322. return;
  1323. }
  1324. isTouched = isMoved = false;
  1325. var currentPos;
  1326. if (s.params.followFinger) {
  1327. currentPos = s.rtl ? s.translate : -s.translate;
  1328. }
  1329. else {
  1330. currentPos = -currentTranslate;
  1331. }
  1332. if (s.params.freeMode) {
  1333. if (currentPos < -s.minTranslate()) {
  1334. s.slideTo(s.activeIndex);
  1335. return;
  1336. }
  1337. else if (currentPos > -s.maxTranslate()) {
  1338. if (s.slides.length < s.snapGrid.length) {
  1339. s.slideTo(s.snapGrid.length - 1);
  1340. }
  1341. else {
  1342. s.slideTo(s.slides.length - 1);
  1343. }
  1344. return;
  1345. }
  1346. if (s.params.freeModeMomentum) {
  1347. if (velocities.length > 1) {
  1348. var lastMoveEvent = velocities.pop(), velocityEvent = velocities.pop();
  1349. var distance = lastMoveEvent.position - velocityEvent.position;
  1350. var time = lastMoveEvent.time - velocityEvent.time;
  1351. s.velocity = distance / time;
  1352. s.velocity = s.velocity / 2;
  1353. if (Math.abs(s.velocity) < 0.02) {
  1354. s.velocity = 0;
  1355. }
  1356. // this implies that the user stopped moving a finger then released.
  1357. // There would be no events with distance zero, so the last event is stale.
  1358. if (time > 150 || (new window.Date().getTime() - lastMoveEvent.time) > 300) {
  1359. s.velocity = 0;
  1360. }
  1361. } else {
  1362. s.velocity = 0;
  1363. }
  1364. velocities.length = 0;
  1365. var momentumDuration = 1000 * s.params.freeModeMomentumRatio;
  1366. var momentumDistance = s.velocity * momentumDuration;
  1367. var newPosition = s.translate + momentumDistance;
  1368. if (s.rtl) newPosition = - newPosition;
  1369. var doBounce = false;
  1370. var afterBouncePosition;
  1371. var bounceAmount = Math.abs(s.velocity) * 20 * s.params.freeModeMomentumBounceRatio;
  1372. if (newPosition < s.maxTranslate()) {
  1373. if (s.params.freeModeMomentumBounce) {
  1374. if (newPosition + s.maxTranslate() < -bounceAmount) {
  1375. newPosition = s.maxTranslate() - bounceAmount;
  1376. }
  1377. afterBouncePosition = s.maxTranslate();
  1378. doBounce = true;
  1379. allowMomentumBounce = true;
  1380. }
  1381. else {
  1382. newPosition = s.maxTranslate();
  1383. }
  1384. }
  1385. else if (newPosition > s.minTranslate()) {
  1386. if (s.params.freeModeMomentumBounce) {
  1387. if (newPosition - s.minTranslate() > bounceAmount) {
  1388. newPosition = s.minTranslate() + bounceAmount;
  1389. }
  1390. afterBouncePosition = s.minTranslate();
  1391. doBounce = true;
  1392. allowMomentumBounce = true;
  1393. }
  1394. else {
  1395. newPosition = s.minTranslate();
  1396. }
  1397. }
  1398. else if (s.params.freeModeSticky) {
  1399. var j = 0,
  1400. nextSlide;
  1401. for (j = 0; j < s.snapGrid.length; j += 1) {
  1402. if (s.snapGrid[j] > -newPosition) {
  1403. nextSlide = j;
  1404. break;
  1405. }
  1406. }
  1407. if (Math.abs(s.snapGrid[nextSlide] - newPosition) < Math.abs(s.snapGrid[nextSlide - 1] - newPosition) || s.swipeDirection === 'next') {
  1408. newPosition = s.snapGrid[nextSlide];
  1409. } else {
  1410. newPosition = s.snapGrid[nextSlide - 1];
  1411. }
  1412. if (!s.rtl) newPosition = - newPosition;
  1413. }
  1414. //Fix duration
  1415. if (s.velocity !== 0) {
  1416. if (s.rtl) {
  1417. momentumDuration = Math.abs((-newPosition - s.translate) / s.velocity);
  1418. }
  1419. else {
  1420. momentumDuration = Math.abs((newPosition - s.translate) / s.velocity);
  1421. }
  1422. }
  1423. else if (s.params.freeModeSticky) {
  1424. s.slideReset();
  1425. return;
  1426. }
  1427. if (s.params.freeModeMomentumBounce && doBounce) {
  1428. s.updateProgress(afterBouncePosition);
  1429. s.setWrapperTransition(momentumDuration);
  1430. s.setWrapperTranslate(newPosition);
  1431. s.onTransitionStart();
  1432. s.animating = true;
  1433. s.wrapper.transitionEnd(function () {
  1434. if (!s || !allowMomentumBounce) return;
  1435. s.emit('onMomentumBounce', s);
  1436. s.setWrapperTransition(s.params.speed);
  1437. s.setWrapperTranslate(afterBouncePosition);
  1438. s.wrapper.transitionEnd(function () {
  1439. if (!s) return;
  1440. s.onTransitionEnd();
  1441. });
  1442. });
  1443. } else if (s.velocity) {
  1444. s.updateProgress(newPosition);
  1445. s.setWrapperTransition(momentumDuration);
  1446. s.setWrapperTranslate(newPosition);
  1447. s.onTransitionStart();
  1448. if (!s.animating) {
  1449. s.animating = true;
  1450. s.wrapper.transitionEnd(function () {
  1451. if (!s) return;
  1452. s.onTransitionEnd();
  1453. });
  1454. }
  1455. } else {
  1456. s.updateProgress(newPosition);
  1457. }
  1458. s.updateActiveIndex();
  1459. }
  1460. if (!s.params.freeModeMomentum || timeDiff >= s.params.longSwipesMs) {
  1461. s.updateProgress();
  1462. s.updateActiveIndex();
  1463. }
  1464. return;
  1465. }
  1466. // Find current slide
  1467. var i, stopIndex = 0, groupSize = s.slidesSizesGrid[0];
  1468. for (i = 0; i < s.slidesGrid.length; i += s.params.slidesPerGroup) {
  1469. if (typeof s.slidesGrid[i + s.params.slidesPerGroup] !== 'undefined') {
  1470. if (currentPos >= s.slidesGrid[i] && currentPos < s.slidesGrid[i + s.params.slidesPerGroup]) {
  1471. stopIndex = i;
  1472. groupSize = s.slidesGrid[i + s.params.slidesPerGroup] - s.slidesGrid[i];
  1473. }
  1474. }
  1475. else {
  1476. if (currentPos >= s.slidesGrid[i]) {
  1477. stopIndex = i;
  1478. groupSize = s.slidesGrid[s.slidesGrid.length - 1] - s.slidesGrid[s.slidesGrid.length - 2];
  1479. }
  1480. }
  1481. }
  1482. // Find current slide size
  1483. var ratio = (currentPos - s.slidesGrid[stopIndex]) / groupSize;
  1484. if (timeDiff > s.params.longSwipesMs) {
  1485. // Long touches
  1486. if (!s.params.longSwipes) {
  1487. s.slideTo(s.activeIndex);
  1488. return;
  1489. }
  1490. if (s.swipeDirection === 'next') {
  1491. if (ratio >= s.params.longSwipesRatio) s.slideTo(stopIndex + s.params.slidesPerGroup);
  1492. else s.slideTo(stopIndex);
  1493. }
  1494. if (s.swipeDirection === 'prev') {
  1495. if (ratio > (1 - s.params.longSwipesRatio)) s.slideTo(stopIndex + s.params.slidesPerGroup);
  1496. else s.slideTo(stopIndex);
  1497. }
  1498. }
  1499. else {
  1500. // Short swipes
  1501. if (!s.params.shortSwipes) {
  1502. s.slideTo(s.activeIndex);
  1503. return;
  1504. }
  1505. if (s.swipeDirection === 'next') {
  1506. s.slideTo(stopIndex + s.params.slidesPerGroup);
  1507. }
  1508. if (s.swipeDirection === 'prev') {
  1509. s.slideTo(stopIndex);
  1510. }
  1511. }
  1512. };
  1513. /*=========================
  1514. Transitions
  1515. ===========================*/
  1516. s._slideTo = function (slideIndex, speed) {
  1517. return s.slideTo(slideIndex, speed, true, true);
  1518. };
  1519. s.slideTo = function (slideIndex, speed, runCallbacks, internal) {
  1520. if (typeof runCallbacks === 'undefined') runCallbacks = true;
  1521. if (typeof slideIndex === 'undefined') slideIndex = 0;
  1522. if (slideIndex < 0) slideIndex = 0;
  1523. s.snapIndex = Math.floor(slideIndex / s.params.slidesPerGroup);
  1524. if (s.snapIndex >= s.snapGrid.length) s.snapIndex = s.snapGrid.length - 1;
  1525. var translate = - s.snapGrid[s.snapIndex];
  1526. // Directions locks
  1527. if (!s.params.allowSwipeToNext && translate < s.translate && translate < s.minTranslate()) {
  1528. return false;
  1529. }
  1530. if (!s.params.allowSwipeToPrev && translate > s.translate && translate > s.maxTranslate()) {
  1531. return false;
  1532. }
  1533. // Stop autoplay
  1534. if (s.params.autoplay && s.autoplaying) {
  1535. if (internal || !s.params.autoplayDisableOnInteraction) {
  1536. s.pauseAutoplay(speed);
  1537. }
  1538. else {
  1539. s.stopAutoplay();
  1540. }
  1541. }
  1542. // Update progress
  1543. s.updateProgress(translate);
  1544. // Normalize slideIndex
  1545. for (var i = 0; i < s.slidesGrid.length; i++) {
  1546. if (- Math.floor(translate * 100) >= Math.floor(s.slidesGrid[i] * 100)) {
  1547. slideIndex = i;
  1548. }
  1549. }
  1550. if (typeof speed === 'undefined') speed = s.params.speed;
  1551. s.previousIndex = s.activeIndex || 0;
  1552. s.activeIndex = slideIndex;
  1553. if (translate === s.translate) {
  1554. s.updateClasses();
  1555. return false;
  1556. }
  1557. s.updateClasses();
  1558. s.onTransitionStart(runCallbacks);
  1559. var translateX = isH() ? translate : 0, translateY = isH() ? 0 : translate;
  1560. if (speed === 0) {
  1561. s.setWrapperTransition(0);
  1562. s.setWrapperTranslate(translate);
  1563. s.onTransitionEnd(runCallbacks);
  1564. }
  1565. else {
  1566. s.setWrapperTransition(speed);
  1567. s.setWrapperTranslate(translate);
  1568. if (!s.animating) {
  1569. s.animating = true;
  1570. s.wrapper.transitionEnd(function () {
  1571. if (!s) return;
  1572. s.onTransitionEnd(runCallbacks);
  1573. });
  1574. }
  1575. }
  1576. return true;
  1577. };
  1578. s.onTransitionStart = function (runCallbacks) {
  1579. if (typeof runCallbacks === 'undefined') runCallbacks = true;
  1580. if (s.lazy) s.lazy.onTransitionStart();
  1581. if (runCallbacks) {
  1582. s.emit('onTransitionStart', s);
  1583. if (s.activeIndex !== s.previousIndex) {
  1584. s.emit('onSlideChangeStart', s);
  1585. }
  1586. }
  1587. };
  1588. s.onTransitionEnd = function (runCallbacks) {
  1589. s.animating = false;
  1590. s.setWrapperTransition(0);
  1591. if (typeof runCallbacks === 'undefined') runCallbacks = true;
  1592. if (s.lazy) s.lazy.onTransitionEnd();
  1593. if (runCallbacks) {
  1594. s.emit('onTransitionEnd', s);
  1595. if (s.activeIndex !== s.previousIndex) {
  1596. s.emit('onSlideChangeEnd', s);
  1597. }
  1598. }
  1599. if (s.params.hashnav && s.hashnav) {
  1600. s.hashnav.setHash();
  1601. }
  1602. };
  1603. s.slideNext = function (runCallbacks, speed, internal) {
  1604. if (s.params.loop) {
  1605. if (s.animating) return false;
  1606. s.fixLoop();
  1607. var clientLeft = s.container[0].clientLeft;
  1608. return s.slideTo(s.activeIndex + s.params.slidesPerGroup, speed, runCallbacks, internal);
  1609. }
  1610. else return s.slideTo(s.activeIndex + s.params.slidesPerGroup, speed, runCallbacks, internal);
  1611. };
  1612. s._slideNext = function (speed) {
  1613. return s.slideNext(true, speed, true);
  1614. };
  1615. s.slidePrev = function (runCallbacks, speed, internal) {
  1616. if (s.params.loop) {
  1617. if (s.animating) return false;
  1618. s.fixLoop();
  1619. var clientLeft = s.container[0].clientLeft;
  1620. return s.slideTo(s.activeIndex - 1, speed, runCallbacks, internal);
  1621. }
  1622. else return s.slideTo(s.activeIndex - 1, speed, runCallbacks, internal);
  1623. };
  1624. s._slidePrev = function (speed) {
  1625. return s.slidePrev(true, speed, true);
  1626. };
  1627. s.slideReset = function (runCallbacks, speed, internal) {
  1628. return s.slideTo(s.activeIndex, speed, runCallbacks);
  1629. };
  1630. /*=========================
  1631. Translate/transition helpers
  1632. ===========================*/
  1633. s.setWrapperTransition = function (duration, byController) {
  1634. s.wrapper.transition(duration);
  1635. if (s.params.effect !== 'slide' && s.effects[s.params.effect]) {
  1636. s.effects[s.params.effect].setTransition(duration);
  1637. }
  1638. if (s.params.parallax && s.parallax) {
  1639. s.parallax.setTransition(duration);
  1640. }
  1641. if (s.params.scrollbar && s.scrollbar) {
  1642. s.scrollbar.setTransition(duration);
  1643. }
  1644. if (s.params.control && s.controller) {
  1645. s.controller.setTransition(duration, byController);
  1646. }
  1647. s.emit('onSetTransition', s, duration);
  1648. };
  1649. s.setWrapperTranslate = function (translate, updateActiveIndex, byController) {
  1650. var x = 0, y = 0, z = 0;
  1651. if (isH()) {
  1652. x = s.rtl ? -translate : translate;
  1653. }
  1654. else {
  1655. y = translate;
  1656. }
  1657. if (!s.params.virtualTranslate) {
  1658. if (s.support.transforms3d) s.wrapper.transform('translate3d(' + x + 'px, ' + y + 'px, ' + z + 'px)');
  1659. else s.wrapper.transform('translate(' + x + 'px, ' + y + 'px)');
  1660. }
  1661. s.translate = isH() ? x : y;
  1662. if (updateActiveIndex) s.updateActiveIndex();
  1663. if (s.params.effect !== 'slide' && s.effects[s.params.effect]) {
  1664. s.effects[s.params.effect].setTranslate(s.translate);
  1665. }
  1666. if (s.params.parallax && s.parallax) {
  1667. s.parallax.setTranslate(s.translate);
  1668. }
  1669. if (s.params.scrollbar && s.scrollbar) {
  1670. s.scrollbar.setTranslate(s.translate);
  1671. }
  1672. if (s.params.control && s.controller) {
  1673. s.controller.setTranslate(s.translate, byController);
  1674. }
  1675. s.emit('onSetTranslate', s, s.translate);
  1676. };
  1677. s.getTranslate = function (el, axis) {
  1678. var matrix, curTransform, curStyle, transformMatrix;
  1679. // automatic axis detection
  1680. if (typeof axis === 'undefined') {
  1681. axis = 'x';
  1682. }
  1683. if (s.params.virtualTranslate) {
  1684. return s.rtl ? -s.translate : s.translate;
  1685. }
  1686. curStyle = window.getComputedStyle(el, null);
  1687. if (window.WebKitCSSMatrix) {
  1688. // Some old versions of Webkit choke when 'none' is passed; pass
  1689. // empty string instead in this case
  1690. transformMatrix = new window.WebKitCSSMatrix(curStyle.webkitTransform === 'none' ? '' : curStyle.webkitTransform);
  1691. }
  1692. else {
  1693. transformMatrix = curStyle.MozTransform || curStyle.OTransform || curStyle.MsTransform || curStyle.msTransform || curStyle.transform || curStyle.getPropertyValue('transform').replace('translate(', 'matrix(1, 0, 0, 1,');
  1694. matrix = transformMatrix.toString().split(',');
  1695. }
  1696. if (axis === 'x') {
  1697. //Latest Chrome and webkits Fix
  1698. if (window.WebKitCSSMatrix)
  1699. curTransform = transformMatrix.m41;
  1700. //Crazy IE10 Matrix
  1701. else if (matrix.length === 16)
  1702. curTransform = parseFloat(matrix[12]);
  1703. //Normal Browsers
  1704. else
  1705. curTransform = parseFloat(matrix[4]);
  1706. }
  1707. if (axis === 'y') {
  1708. //Latest Chrome and webkits Fix
  1709. if (window.WebKitCSSMatrix)
  1710. curTransform = transformMatrix.m42;
  1711. //Crazy IE10 Matrix
  1712. else if (matrix.length === 16)
  1713. curTransform = parseFloat(matrix[13]);
  1714. //Normal Browsers
  1715. else
  1716. curTransform = parseFloat(matrix[5]);
  1717. }
  1718. if (s.rtl && curTransform) curTransform = -curTransform;
  1719. return curTransform || 0;
  1720. };
  1721. s.getWrapperTranslate = function (axis) {
  1722. if (typeof axis === 'undefined') {
  1723. axis = isH() ? 'x' : 'y';
  1724. }
  1725. return s.getTranslate(s.wrapper[0], axis);
  1726. };
  1727. /*=========================
  1728. Observer
  1729. ===========================*/
  1730. s.observers = [];
  1731. function initObserver(target, options) {
  1732. options = options || {};
  1733. // create an observer instance
  1734. var ObserverFunc = window.MutationObserver || window.WebkitMutationObserver;
  1735. var observer = new ObserverFunc(function (mutations) {
  1736. mutations.forEach(function (mutation) {
  1737. s.onResize(true);
  1738. s.emit('onObserverUpdate', s, mutation);
  1739. });
  1740. });
  1741. observer.observe(target, {
  1742. attributes: typeof options.attributes === 'undefined' ? true : options.attributes,
  1743. childList: typeof options.childList === 'undefined' ? true : options.childList,
  1744. characterData: typeof options.characterData === 'undefined' ? true : options.characterData
  1745. });
  1746. s.observers.push(observer);
  1747. }
  1748. s.initObservers = function () {
  1749. if (s.params.observeParents) {
  1750. var containerParents = s.container.parents();
  1751. for (var i = 0; i < containerParents.length; i++) {
  1752. initObserver(containerParents[i]);
  1753. }
  1754. }
  1755. // Observe container
  1756. initObserver(s.container[0], {childList: false});
  1757. // Observe wrapper
  1758. initObserver(s.wrapper[0], {attributes: false});
  1759. };
  1760. s.disconnectObservers = function () {
  1761. for (var i = 0; i < s.observers.length; i++) {
  1762. s.observers[i].disconnect();
  1763. }
  1764. s.observers = [];
  1765. };
  1766. /*=========================
  1767. Loop
  1768. ===========================*/
  1769. // Create looped slides
  1770. s.createLoop = function () {
  1771. // Remove duplicated slides
  1772. s.wrapper.children('.' + s.params.slideClass + '.' + s.params.slideDuplicateClass).remove();
  1773. var slides = s.wrapper.children('.' + s.params.slideClass);
  1774. s.loopedSlides = parseInt(s.params.loopedSlides || s.params.slidesPerView, 10);
  1775. s.loopedSlides = s.loopedSlides + s.params.loopAdditionalSlides;
  1776. if (s.loopedSlides > slides.length) {
  1777. s.loopedSlides = slides.length;
  1778. }
  1779. var prependSlides = [], appendSlides = [], i;
  1780. slides.each(function (index, el) {
  1781. var slide = $(this);
  1782. if (index < s.loopedSlides) appendSlides.push(el);
  1783. if (index < slides.length && index >= slides.length - s.loopedSlides) prependSlides.push(el);
  1784. slide.attr('data-swiper-slide-index', index);
  1785. });
  1786. for (i = 0; i < appendSlides.length; i++) {
  1787. s.wrapper.append($(appendSlides[i].cloneNode(true)).addClass(s.params.slideDuplicateClass));
  1788. }
  1789. for (i = prependSlides.length - 1; i >= 0; i--) {
  1790. s.wrapper.prepend($(prependSlides[i].cloneNode(true)).addClass(s.params.slideDuplicateClass));
  1791. }
  1792. };
  1793. s.destroyLoop = function () {
  1794. s.wrapper.children('.' + s.params.slideClass + '.' + s.params.slideDuplicateClass).remove();
  1795. s.slides.removeAttr('data-swiper-slide-index');
  1796. };
  1797. s.fixLoop = function () {
  1798. var newIndex;
  1799. //Fix For Negative Oversliding
  1800. if (s.activeIndex < s.loopedSlides) {
  1801. newIndex = s.slides.length - s.loopedSlides * 3 + s.activeIndex;
  1802. newIndex = newIndex + s.loopedSlides;
  1803. s.slideTo(newIndex, 0, false, true);
  1804. }
  1805. //Fix For Positive Oversliding
  1806. else if ((s.params.slidesPerView === 'auto' && s.activeIndex >= s.loopedSlides * 2) || (s.activeIndex > s.slides.length - s.params.slidesPerView * 2)) {
  1807. newIndex = -s.slides.length + s.activeIndex + s.loopedSlides;
  1808. newIndex = newIndex + s.loopedSlides;
  1809. s.slideTo(newIndex, 0, false, true);
  1810. }
  1811. };
  1812. /*=========================
  1813. Append/Prepend/Remove Slides
  1814. ===========================*/
  1815. s.appendSlide = function (slides) {
  1816. if (s.params.loop) {
  1817. s.destroyLoop();
  1818. }
  1819. if (typeof slides === 'object' && slides.length) {
  1820. for (var i = 0; i < slides.length; i++) {
  1821. if (slides[i]) s.wrapper.append(slides[i]);
  1822. }
  1823. }
  1824. else {
  1825. s.wrapper.append(slides);
  1826. }
  1827. if (s.params.loop) {
  1828. s.createLoop();
  1829. }
  1830. if (!(s.params.observer && s.support.observer)) {
  1831. s.update(true);
  1832. }
  1833. };
  1834. s.prependSlide = function (slides) {
  1835. if (s.params.loop) {
  1836. s.destroyLoop();
  1837. }
  1838. var newActiveIndex = s.activeIndex + 1;
  1839. if (typeof slides === 'object' && slides.length) {
  1840. for (var i = 0; i < slides.length; i++) {
  1841. if (slides[i]) s.wrapper.prepend(slides[i]);
  1842. }
  1843. newActiveIndex = s.activeIndex + slides.length;
  1844. }
  1845. else {
  1846. s.wrapper.prepend(slides);
  1847. }
  1848. if (s.params.loop) {
  1849. s.createLoop();
  1850. }
  1851. if (!(s.params.observer && s.support.observer)) {
  1852. s.update(true);
  1853. }
  1854. s.slideTo(newActiveIndex, 0, false);
  1855. };
  1856. s.removeSlide = function (slidesIndexes) {
  1857. if (s.params.loop) {
  1858. s.destroyLoop();
  1859. s.slides = s.wrapper.children('.' + s.params.slideClass);
  1860. }
  1861. var newActiveIndex = s.activeIndex,
  1862. indexToRemove;
  1863. if (typeof slidesIndexes === 'object' && slidesIndexes.length) {
  1864. for (var i = 0; i < slidesIndexes.length; i++) {
  1865. indexToRemove = slidesIndexes[i];
  1866. if (s.slides[indexToRemove]) s.slides.eq(indexToRemove).remove();
  1867. if (indexToRemove < newActiveIndex) newActiveIndex--;
  1868. }
  1869. newActiveIndex = Math.max(newActiveIndex, 0);
  1870. }
  1871. else {
  1872. indexToRemove = slidesIndexes;
  1873. if (s.slides[indexToRemove]) s.slides.eq(indexToRemove).remove();
  1874. if (indexToRemove < newActiveIndex) newActiveIndex--;
  1875. newActiveIndex = Math.max(newActiveIndex, 0);
  1876. }
  1877. if (s.params.loop) {
  1878. s.createLoop();
  1879. }
  1880. if (!(s.params.observer && s.support.observer)) {
  1881. s.update(true);
  1882. }
  1883. if (s.params.loop) {
  1884. s.slideTo(newActiveIndex + s.loopedSlides, 0, false);
  1885. }
  1886. else {
  1887. s.slideTo(newActiveIndex, 0, false);
  1888. }
  1889. };
  1890. s.removeAllSlides = function () {
  1891. var slidesIndexes = [];
  1892. for (var i = 0; i < s.slides.length; i++) {
  1893. slidesIndexes.push(i);
  1894. }
  1895. s.removeSlide(slidesIndexes);
  1896. };
  1897. /*=========================
  1898. Effects
  1899. ===========================*/
  1900. s.effects = {
  1901. fade: {
  1902. setTranslate: function () {
  1903. for (var i = 0; i < s.slides.length; i++) {
  1904. var slide = s.slides.eq(i);
  1905. var offset = slide[0].swiperSlideOffset;
  1906. var tx = -offset;
  1907. if (!s.params.virtualTranslate) tx = tx - s.translate;
  1908. var ty = 0;
  1909. if (!isH()) {
  1910. ty = tx;
  1911. tx = 0;
  1912. }
  1913. var slideOpacity = s.params.fade.crossFade ?
  1914. Math.max(1 - Math.abs(slide[0].progress), 0) :
  1915. 1 + Math.min(Math.max(slide[0].progress, -1), 0);
  1916. slide
  1917. .css({
  1918. opacity: slideOpacity
  1919. })
  1920. .transform('translate3d(' + tx + 'px, ' + ty + 'px, 0px)');
  1921. }
  1922. },
  1923. setTransition: function (duration) {
  1924. s.slides.transition(duration);
  1925. if (s.params.virtualTranslate && duration !== 0) {
  1926. var eventTriggered = false;
  1927. s.slides.transitionEnd(function () {
  1928. if (eventTriggered) return;
  1929. if (!s) return;
  1930. eventTriggered = true;
  1931. s.animating = false;
  1932. var triggerEvents = ['webkitTransitionEnd', 'transitionend', 'oTransitionEnd', 'MSTransitionEnd', 'msTransitionEnd'];
  1933. for (var i = 0; i < triggerEvents.length; i++) {
  1934. s.wrapper.trigger(triggerEvents[i]);
  1935. }
  1936. });
  1937. }
  1938. }
  1939. },
  1940. cube: {
  1941. setTranslate: function () {
  1942. var wrapperRotate = 0, cubeShadow;
  1943. if (s.params.cube.shadow) {
  1944. if (isH()) {
  1945. cubeShadow = s.wrapper.find('.swiper-cube-shadow');
  1946. if (cubeShadow.length === 0) {
  1947. cubeShadow = $('<div class="swiper-cube-shadow"></div>');
  1948. s.wrapper.append(cubeShadow);
  1949. }
  1950. cubeShadow.css({height: s.width + 'px'});
  1951. }
  1952. else {
  1953. cubeShadow = s.container.find('.swiper-cube-shadow');
  1954. if (cubeShadow.length === 0) {
  1955. cubeShadow = $('<div class="swiper-cube-shadow"></div>');
  1956. s.container.append(cubeShadow);
  1957. }
  1958. }
  1959. }
  1960. for (var i = 0; i < s.slides.length; i++) {
  1961. var slide = s.slides.eq(i);
  1962. var slideAngle = i * 90;
  1963. var round = Math.floor(slideAngle / 360);
  1964. if (s.rtl) {
  1965. slideAngle = -slideAngle;
  1966. round = Math.floor(-slideAngle / 360);
  1967. }
  1968. var progress = Math.max(Math.min(slide[0].progress, 1), -1);
  1969. var tx = 0, ty = 0, tz = 0;
  1970. if (i % 4 === 0) {
  1971. tx = - round * 4 * s.size;
  1972. tz = 0;
  1973. }
  1974. else if ((i - 1) % 4 === 0) {
  1975. tx = 0;
  1976. tz = - round * 4 * s.size;
  1977. }
  1978. else if ((i - 2) % 4 === 0) {
  1979. tx = s.size + round * 4 * s.size;
  1980. tz = s.size;
  1981. }
  1982. else if ((i - 3) % 4 === 0) {
  1983. tx = - s.size;
  1984. tz = 3 * s.size + s.size * 4 * round;
  1985. }
  1986. if (s.rtl) {
  1987. tx = -tx;
  1988. }
  1989. if (!isH()) {
  1990. ty = tx;
  1991. tx = 0;
  1992. }
  1993. var transform = 'rotateX(' + (isH() ? 0 : -slideAngle) + 'deg) rotateY(' + (isH() ? slideAngle : 0) + 'deg) translate3d(' + tx + 'px, ' + ty + 'px, ' + tz + 'px)';
  1994. if (progress <= 1 && progress > -1) {
  1995. wrapperRotate = i * 90 + progress * 90;
  1996. if (s.rtl) wrapperRotate = -i * 90 - progress * 90;
  1997. }
  1998. slide.transform(transform);
  1999. if (s.params.cube.slideShadows) {
  2000. //Set shadows
  2001. var shadowBefore = isH() ? slide.find('.swiper-slide-shadow-left') : slide.find('.swiper-slide-shadow-top');
  2002. var shadowAfter = isH() ? slide.find('.swiper-slide-shadow-right') : slide.find('.swiper-slide-shadow-bottom');
  2003. if (shadowBefore.length === 0) {
  2004. shadowBefore = $('<div class="swiper-slide-shadow-' + (isH() ? 'left' : 'top') + '"></div>');
  2005. slide.append(shadowBefore);
  2006. }
  2007. if (shadowAfter.length === 0) {
  2008. shadowAfter = $('<div class="swiper-slide-shadow-' + (isH() ? 'right' : 'bottom') + '"></div>');
  2009. slide.append(shadowAfter);
  2010. }
  2011. var shadowOpacity = slide[0].progress;
  2012. if (shadowBefore.length) shadowBefore[0].style.opacity = -slide[0].progress;
  2013. if (shadowAfter.length) shadowAfter[0].style.opacity = slide[0].progress;
  2014. }
  2015. }
  2016. s.wrapper.css({
  2017. '-webkit-transform-origin': '50% 50% -' + (s.size / 2) + 'px',
  2018. '-moz-transform-origin': '50% 50% -' + (s.size / 2) + 'px',
  2019. '-ms-transform-origin': '50% 50% -' + (s.size / 2) + 'px',
  2020. 'transform-origin': '50% 50% -' + (s.size / 2) + 'px'
  2021. });
  2022. if (s.params.cube.shadow) {
  2023. if (isH()) {
  2024. cubeShadow.transform('translate3d(0px, ' + (s.width / 2 + s.params.cube.shadowOffset) + 'px, ' + (-s.width / 2) + 'px) rotateX(90deg) rotateZ(0deg) scale(' + (s.params.cube.shadowScale) + ')');
  2025. }
  2026. else {
  2027. var shadowAngle = Math.abs(wrapperRotate) - Math.floor(Math.abs(wrapperRotate) / 90) * 90;
  2028. var multiplier = 1.5 - (Math.sin(shadowAngle * 2 * Math.PI / 360) / 2 + Math.cos(shadowAngle * 2 * Math.PI / 360) / 2);
  2029. var scale1 = s.params.cube.shadowScale,
  2030. scale2 = s.params.cube.shadowScale / multiplier,
  2031. offset = s.params.cube.shadowOffset;
  2032. cubeShadow.transform('scale3d(' + scale1 + ', 1, ' + scale2 + ') translate3d(0px, ' + (s.height / 2 + offset) + 'px, ' + (-s.height / 2 / scale2) + 'px) rotateX(-90deg)');
  2033. }
  2034. }
  2035. var zFactor = (s.isSafari || s.isUiWebView) ? (-s.size / 2) : 0;
  2036. s.wrapper.transform('translate3d(0px,0,' + zFactor + 'px) rotateX(' + (isH() ? 0 : wrapperRotate) + 'deg) rotateY(' + (isH() ? -wrapperRotate : 0) + 'deg)');
  2037. },
  2038. setTransition: function (duration) {
  2039. s.slides.transition(duration).find('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').transition(duration);
  2040. if (s.params.cube.shadow && !isH()) {
  2041. s.container.find('.swiper-cube-shadow').transition(duration);
  2042. }
  2043. }
  2044. },
  2045. coverflow: {
  2046. setTranslate: function () {
  2047. var transform = s.translate;
  2048. var center = isH() ? -transform + s.width / 2 : -transform + s.height / 2;
  2049. var rotate = isH() ? s.params.coverflow.rotate: -s.params.coverflow.rotate;
  2050. var translate = s.params.coverflow.depth;
  2051. //Each slide offset from center
  2052. for (var i = 0, length = s.slides.length; i < length; i++) {
  2053. var slide = s.slides.eq(i);
  2054. var slideSize = s.slidesSizesGrid[i];
  2055. var slideOffset = slide[0].swiperSlideOffset;
  2056. var offsetMultiplier = (center - slideOffset - slideSize / 2) / slideSize * s.params.coverflow.modifier;
  2057. var rotateY = isH() ? rotate * offsetMultiplier : 0;
  2058. var rotateX = isH() ? 0 : rotate * offsetMultiplier;
  2059. // var rotateZ = 0
  2060. var translateZ = -translate * Math.abs(offsetMultiplier);
  2061. var translateY = isH() ? 0 : s.params.coverflow.stretch * (offsetMultiplier);
  2062. var translateX = isH() ? s.params.coverflow.stretch * (offsetMultiplier) : 0;
  2063. //Fix for ultra small values
  2064. if (Math.abs(translateX) < 0.001) translateX = 0;
  2065. if (Math.abs(translateY) < 0.001) translateY = 0;
  2066. if (Math.abs(translateZ) < 0.001) translateZ = 0;
  2067. if (Math.abs(rotateY) < 0.001) rotateY = 0;
  2068. if (Math.abs(rotateX) < 0.001) rotateX = 0;
  2069. var slideTransform = 'translate3d(' + translateX + 'px,' + translateY + 'px,' + translateZ + 'px) rotateX(' + rotateX + 'deg) rotateY(' + rotateY + 'deg)';
  2070. slide.transform(slideTransform);
  2071. slide[0].style.zIndex = -Math.abs(Math.round(offsetMultiplier)) + 1;
  2072. if (s.params.coverflow.slideShadows) {
  2073. //Set shadows
  2074. var shadowBefore = isH() ? slide.find('.swiper-slide-shadow-left') : slide.find('.swiper-slide-shadow-top');
  2075. var shadowAfter = isH() ? slide.find('.swiper-slide-shadow-right') : slide.find('.swiper-slide-shadow-bottom');
  2076. if (shadowBefore.length === 0) {
  2077. shadowBefore = $('<div class="swiper-slide-shadow-' + (isH() ? 'left' : 'top') + '"></div>');
  2078. slide.append(shadowBefore);
  2079. }
  2080. if (shadowAfter.length === 0) {
  2081. shadowAfter = $('<div class="swiper-slide-shadow-' + (isH() ? 'right' : 'bottom') + '"></div>');
  2082. slide.append(shadowAfter);
  2083. }
  2084. if (shadowBefore.length) shadowBefore[0].style.opacity = offsetMultiplier > 0 ? offsetMultiplier : 0;
  2085. if (shadowAfter.length) shadowAfter[0].style.opacity = (-offsetMultiplier) > 0 ? -offsetMultiplier : 0;
  2086. }
  2087. }
  2088. //Set correct perspective for IE10
  2089. if (s.browser.ie) {
  2090. var ws = s.wrapper[0].style;
  2091. ws.perspectiveOrigin = center + 'px 50%';
  2092. }
  2093. },
  2094. setTransition: function (duration) {
  2095. s.slides.transition(duration).find('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').transition(duration);
  2096. }
  2097. }
  2098. };
  2099. /*=========================
  2100. Images Lazy Loading
  2101. ===========================*/
  2102. s.lazy = {
  2103. initialImageLoaded: false,
  2104. loadImageInSlide: function (index, loadInDuplicate) {
  2105. if (typeof index === 'undefined') return;
  2106. if (typeof loadInDuplicate === 'undefined') loadInDuplicate = true;
  2107. if (s.slides.length === 0) return;
  2108. var slide = s.slides.eq(index);
  2109. var img = slide.find('.swiper-lazy:not(.swiper-lazy-loaded):not(.swiper-lazy-loading)');
  2110. if (slide.hasClass('swiper-lazy') && !slide.hasClass('swiper-lazy-loaded') && !slide.hasClass('swiper-lazy-loading')) {
  2111. img.add(slide[0]);
  2112. }
  2113. if (img.length === 0) return;
  2114. img.each(function () {
  2115. var _img = $(this);
  2116. _img.addClass('swiper-lazy-loading');
  2117. var background = _img.attr('data-background');
  2118. var src = _img.attr('data-src');
  2119. s.loadImage(_img[0], (src || background), false, function () {
  2120. if (background) {
  2121. _img.css('background-image', 'url(' + background + ')');
  2122. _img.removeAttr('data-background');
  2123. }
  2124. else {
  2125. _img.attr('src', src);
  2126. _img.removeAttr('data-src');
  2127. }
  2128. _img.addClass('swiper-lazy-loaded').removeClass('swiper-lazy-loading');
  2129. slide.find('.swiper-lazy-preloader, .preloader').remove();
  2130. if (s.params.loop && loadInDuplicate) {
  2131. var slideOriginalIndex = slide.attr('data-swiper-slide-index');
  2132. if (slide.hasClass(s.params.slideDuplicateClass)) {
  2133. var originalSlide = s.wrapper.children('[data-swiper-slide-index="' + slideOriginalIndex + '"]:not(.' + s.params.slideDuplicateClass + ')');
  2134. s.lazy.loadImageInSlide(originalSlide.index(), false);
  2135. }
  2136. else {
  2137. var duplicatedSlide = s.wrapper.children('.' + s.params.slideDuplicateClass + '[data-swiper-slide-index="' + slideOriginalIndex + '"]');
  2138. s.lazy.loadImageInSlide(duplicatedSlide.index(), false);
  2139. }
  2140. }
  2141. s.emit('onLazyImageReady', s, slide[0], _img[0]);
  2142. });
  2143. s.emit('onLazyImageLoad', s, slide[0], _img[0]);
  2144. });
  2145. },
  2146. load: function () {
  2147. var i;
  2148. if (s.params.watchSlidesVisibility) {
  2149. s.wrapper.children('.' + s.params.slideVisibleClass).each(function () {
  2150. s.lazy.loadImageInSlide($(this).index());
  2151. });
  2152. }
  2153. else {
  2154. if (s.params.slidesPerView > 1) {
  2155. for (i = s.activeIndex; i < s.activeIndex + s.params.slidesPerView ; i++) {
  2156. if (s.slides[i]) s.lazy.loadImageInSlide(i);
  2157. }
  2158. }
  2159. else {
  2160. s.lazy.loadImageInSlide(s.activeIndex);
  2161. }
  2162. }
  2163. if (s.params.lazyLoadingInPrevNext) {
  2164. if (s.params.slidesPerView > 1) {
  2165. // Next Slides
  2166. for (i = s.activeIndex + s.params.slidesPerView; i < s.activeIndex + s.params.slidesPerView + s.params.slidesPerView; i++) {
  2167. if (s.slides[i]) s.lazy.loadImageInSlide(i);
  2168. }
  2169. // Prev Slides
  2170. for (i = s.activeIndex - s.params.slidesPerView; i < s.activeIndex ; i++) {
  2171. if (s.slides[i]) s.lazy.loadImageInSlide(i);
  2172. }
  2173. }
  2174. else {
  2175. var nextSlide = s.wrapper.children('.' + s.params.slideNextClass);
  2176. if (nextSlide.length > 0) s.lazy.loadImageInSlide(nextSlide.index());
  2177. var prevSlide = s.wrapper.children('.' + s.params.slidePrevClass);
  2178. if (prevSlide.length > 0) s.lazy.loadImageInSlide(prevSlide.index());
  2179. }
  2180. }
  2181. },
  2182. onTransitionStart: function () {
  2183. if (s.params.lazyLoading) {
  2184. if (s.params.lazyLoadingOnTransitionStart || (!s.params.lazyLoadingOnTransitionStart && !s.lazy.initialImageLoaded)) {
  2185. s.lazy.load();
  2186. }
  2187. }
  2188. },
  2189. onTransitionEnd: function () {
  2190. if (s.params.lazyLoading && !s.params.lazyLoadingOnTransitionStart) {
  2191. s.lazy.load();
  2192. }
  2193. }
  2194. };
  2195. /*=========================
  2196. Scrollbar
  2197. ===========================*/
  2198. s.scrollbar = {
  2199. set: function () {
  2200. if (!s.params.scrollbar) return;
  2201. var sb = s.scrollbar;
  2202. sb.track = $(s.params.scrollbar);
  2203. sb.drag = sb.track.find('.swiper-scrollbar-drag');
  2204. if (sb.drag.length === 0) {
  2205. sb.drag = $('<div class="swiper-scrollbar-drag"></div>');
  2206. sb.track.append(sb.drag);
  2207. }
  2208. sb.drag[0].style.width = '';
  2209. sb.drag[0].style.height = '';
  2210. sb.trackSize = isH() ? sb.track[0].offsetWidth : sb.track[0].offsetHeight;
  2211. sb.divider = s.size / s.virtualSize;
  2212. sb.moveDivider = sb.divider * (sb.trackSize / s.size);
  2213. sb.dragSize = sb.trackSize * sb.divider;
  2214. if (isH()) {
  2215. sb.drag[0].style.width = sb.dragSize + 'px';
  2216. }
  2217. else {
  2218. sb.drag[0].style.height = sb.dragSize + 'px';
  2219. }
  2220. if (sb.divider >= 1) {
  2221. sb.track[0].style.display = 'none';
  2222. }
  2223. else {
  2224. sb.track[0].style.display = '';
  2225. }
  2226. if (s.params.scrollbarHide) {
  2227. sb.track[0].style.opacity = 0;
  2228. }
  2229. },
  2230. setTranslate: function () {
  2231. if (!s.params.scrollbar) return;
  2232. var diff;
  2233. var sb = s.scrollbar;
  2234. var translate = s.translate || 0;
  2235. var newPos;
  2236. var newSize = sb.dragSize;
  2237. newPos = (sb.trackSize - sb.dragSize) * s.progress;
  2238. if (s.rtl && isH()) {
  2239. newPos = -newPos;
  2240. if (newPos > 0) {
  2241. newSize = sb.dragSize - newPos;
  2242. newPos = 0;
  2243. }
  2244. else if (-newPos + sb.dragSize > sb.trackSize) {
  2245. newSize = sb.trackSize + newPos;
  2246. }
  2247. }
  2248. else {
  2249. if (newPos < 0) {
  2250. newSize = sb.dragSize + newPos;
  2251. newPos = 0;
  2252. }
  2253. else if (newPos + sb.dragSize > sb.trackSize) {
  2254. newSize = sb.trackSize - newPos;
  2255. }
  2256. }
  2257. if (isH()) {
  2258. if (s.support.transforms3d) {
  2259. sb.drag.transform('translate3d(' + (newPos) + 'px, 0, 0)');
  2260. }
  2261. else {
  2262. sb.drag.transform('translateX(' + (newPos) + 'px)');
  2263. }
  2264. sb.drag[0].style.width = newSize + 'px';
  2265. }
  2266. else {
  2267. if (s.support.transforms3d) {
  2268. sb.drag.transform('translate3d(0px, ' + (newPos) + 'px, 0)');
  2269. }
  2270. else {
  2271. sb.drag.transform('translateY(' + (newPos) + 'px)');
  2272. }
  2273. sb.drag[0].style.height = newSize + 'px';
  2274. }
  2275. if (s.params.scrollbarHide) {
  2276. clearTimeout(sb.timeout);
  2277. sb.track[0].style.opacity = 1;
  2278. sb.timeout = setTimeout(function () {
  2279. sb.track[0].style.opacity = 0;
  2280. sb.track.transition(400);
  2281. }, 1000);
  2282. }
  2283. },
  2284. setTransition: function (duration) {
  2285. if (!s.params.scrollbar) return;
  2286. s.scrollbar.drag.transition(duration);
  2287. }
  2288. };
  2289. /*=========================
  2290. Controller
  2291. ===========================*/
  2292. s.controller = {
  2293. LinearSpline: function (x, y) {
  2294. this.x = x;
  2295. this.y = y;
  2296. this.lastIndex = x.length - 1;
  2297. // Given an x value (x2), return the expected y2 value:
  2298. // (x1,y1) is the known point before given value,
  2299. // (x3,y3) is the known point after given value.
  2300. var i1, i3;
  2301. var l = this.x.length;
  2302. this.interpolate = function (x2) {
  2303. if (!x2) return 0;
  2304. // Get the indexes of x1 and x3 (the array indexes before and after given x2):
  2305. i3 = binarySearch(this.x, x2);
  2306. i1 = i3 - 1;
  2307. // We have our indexes i1 & i3, so we can calculate already:
  2308. // y2 := ((x2−x1) × (y3−y1)) ÷ (x3−x1) + y1
  2309. return ((x2 - this.x[i1]) * (this.y[i3] - this.y[i1])) / (this.x[i3] - this.x[i1]) + this.y[i1];
  2310. };
  2311. var binarySearch = (function() {
  2312. var maxIndex, minIndex, guess;
  2313. return function(array, val) {
  2314. minIndex = -1;
  2315. maxIndex = array.length;
  2316. while (maxIndex - minIndex > 1)
  2317. if (array[guess = maxIndex + minIndex >> 1] <= val) {
  2318. minIndex = guess;
  2319. } else {
  2320. maxIndex = guess;
  2321. }
  2322. return maxIndex;
  2323. };
  2324. })();
  2325. },
  2326. //xxx: for now i will just save one spline function to to
  2327. getInterpolateFunction: function(c){
  2328. if(!s.controller.spline) s.controller.spline = s.params.loop ?
  2329. new s.controller.LinearSpline(s.slidesGrid, c.slidesGrid) :
  2330. new s.controller.LinearSpline(s.snapGrid, c.snapGrid);
  2331. },
  2332. setTranslate: function (translate, byController) {
  2333. var controlled = s.params.control;
  2334. var multiplier, controlledTranslate;
  2335. function setControlledTranslate(c) {
  2336. // this will create an Interpolate function based on the snapGrids
  2337. // x is the Grid of the scrolled scroller and y will be the controlled scroller
  2338. // it makes sense to create this only once and recall it for the interpolation
  2339. // the function does a lot of value caching for performance
  2340. translate = c.rtl && c.params.direction === 'horizontal' ? -s.translate : s.translate;
  2341. if (s.params.controlBy === 'slide') {
  2342. s.controller.getInterpolateFunction(c);
  2343. // i am not sure why the values have to be multiplicated this way, tried to invert the snapGrid
  2344. // but it did not work out
  2345. controlledTranslate = -s.controller.spline.interpolate(-translate);
  2346. }
  2347. if(!controlledTranslate || s.params.controlBy === 'container'){
  2348. multiplier = (c.maxTranslate() - c.minTranslate()) / (s.maxTranslate() - s.minTranslate());
  2349. controlledTranslate = (translate - s.minTranslate()) * multiplier + c.minTranslate();
  2350. }
  2351. if (s.params.controlInverse) {
  2352. controlledTranslate = c.maxTranslate() - controlledTranslate;
  2353. }
  2354. c.updateProgress(controlledTranslate);
  2355. c.setWrapperTranslate(controlledTranslate, false, s);
  2356. c.updateActiveIndex();
  2357. }
  2358. if (s.isArray(controlled)) {
  2359. for (var i = 0; i < controlled.length; i++) {
  2360. if (controlled[i] !== byController && controlled[i] instanceof Swiper) {
  2361. setControlledTranslate(controlled[i]);
  2362. }
  2363. }
  2364. }
  2365. else if (controlled instanceof Swiper && byController !== controlled) {
  2366. setControlledTranslate(controlled);
  2367. }
  2368. },
  2369. setTransition: function (duration, byController) {
  2370. var controlled = s.params.control;
  2371. var i;
  2372. function setControlledTransition(c) {
  2373. c.setWrapperTransition(duration, s);
  2374. if (duration !== 0) {
  2375. c.onTransitionStart();
  2376. c.wrapper.transitionEnd(function(){
  2377. if (!controlled) return;
  2378. if (c.params.loop && s.params.controlBy === 'slide') {
  2379. c.fixLoop();
  2380. }
  2381. c.onTransitionEnd();
  2382. });
  2383. }
  2384. }
  2385. if (s.isArray(controlled)) {
  2386. for (i = 0; i < controlled.length; i++) {
  2387. if (controlled[i] !== byController && controlled[i] instanceof Swiper) {
  2388. setControlledTransition(controlled[i]);
  2389. }
  2390. }
  2391. }
  2392. else if (controlled instanceof Swiper && byController !== controlled) {
  2393. setControlledTransition(controlled);
  2394. }
  2395. }
  2396. };
  2397. /*=========================
  2398. Hash Navigation
  2399. ===========================*/
  2400. s.hashnav = {
  2401. init: function () {
  2402. if (!s.params.hashnav) return;
  2403. s.hashnav.initialized = true;
  2404. var hash = document.location.hash.replace('#', '');
  2405. if (!hash) return;
  2406. var speed = 0;
  2407. for (var i = 0, length = s.slides.length; i < length; i++) {
  2408. var slide = s.slides.eq(i);
  2409. var slideHash = slide.attr('data-hash');
  2410. if (slideHash === hash && !slide.hasClass(s.params.slideDuplicateClass)) {
  2411. var index = slide.index();
  2412. s.slideTo(index, speed, s.params.runCallbacksOnInit, true);
  2413. }
  2414. }
  2415. },
  2416. setHash: function () {
  2417. if (!s.hashnav.initialized || !s.params.hashnav) return;
  2418. document.location.hash = s.slides.eq(s.activeIndex).attr('data-hash') || '';
  2419. }
  2420. };
  2421. /*=========================
  2422. Keyboard Control
  2423. ===========================*/
  2424. function handleKeyboard(e) {
  2425. if (e.originalEvent) e = e.originalEvent; //jquery fix
  2426. var kc = e.keyCode || e.charCode;
  2427. // Directions locks
  2428. if (!s.params.allowSwipeToNext && (isH() && kc === 39 || !isH() && kc === 40)) {
  2429. return false;
  2430. }
  2431. if (!s.params.allowSwipeToPrev && (isH() && kc === 37 || !isH() && kc === 38)) {
  2432. return false;
  2433. }
  2434. if (e.shiftKey || e.altKey || e.ctrlKey || e.metaKey) {
  2435. return;
  2436. }
  2437. if (document.activeElement && document.activeElement.nodeName && (document.activeElement.nodeName.toLowerCase() === 'input' || document.activeElement.nodeName.toLowerCase() === 'textarea')) {
  2438. return;
  2439. }
  2440. if (kc === 37 || kc === 39 || kc === 38 || kc === 40) {
  2441. var inView = false;
  2442. //Check that swiper should be inside of visible area of window
  2443. if (s.container.parents('.swiper-slide').length > 0 && s.container.parents('.swiper-slide-active').length === 0) {
  2444. return;
  2445. }
  2446. var windowScroll = {
  2447. left: window.pageXOffset,
  2448. top: window.pageYOffset
  2449. };
  2450. var windowWidth = window.innerWidth;
  2451. var windowHeight = window.innerHeight;
  2452. var swiperOffset = s.container.offset();
  2453. if (s.rtl) swiperOffset.left = swiperOffset.left - s.container[0].scrollLeft;
  2454. var swiperCoord = [
  2455. [swiperOffset.left, swiperOffset.top],
  2456. [swiperOffset.left + s.width, swiperOffset.top],
  2457. [swiperOffset.left, swiperOffset.top + s.height],
  2458. [swiperOffset.left + s.width, swiperOffset.top + s.height]
  2459. ];
  2460. for (var i = 0; i < swiperCoord.length; i++) {
  2461. var point = swiperCoord[i];
  2462. if (
  2463. point[0] >= windowScroll.left && point[0] <= windowScroll.left + windowWidth &&
  2464. point[1] >= windowScroll.top && point[1] <= windowScroll.top + windowHeight
  2465. ) {
  2466. inView = true;
  2467. }
  2468. }
  2469. if (!inView) return;
  2470. }
  2471. if (isH()) {
  2472. if (kc === 37 || kc === 39) {
  2473. if (e.preventDefault) e.preventDefault();
  2474. else e.returnValue = false;
  2475. }
  2476. if ((kc === 39 && !s.rtl) || (kc === 37 && s.rtl)) s.slideNext();
  2477. if ((kc === 37 && !s.rtl) || (kc === 39 && s.rtl)) s.slidePrev();
  2478. }
  2479. else {
  2480. if (kc === 38 || kc === 40) {
  2481. if (e.preventDefault) e.preventDefault();
  2482. else e.returnValue = false;
  2483. }
  2484. if (kc === 40) s.slideNext();
  2485. if (kc === 38) s.slidePrev();
  2486. }
  2487. }
  2488. s.disableKeyboardControl = function () {
  2489. $(document).off('keydown', handleKeyboard);
  2490. };
  2491. s.enableKeyboardControl = function () {
  2492. $(document).on('keydown', handleKeyboard);
  2493. };
  2494. /*=========================
  2495. Mousewheel Control
  2496. ===========================*/
  2497. s.mousewheel = {
  2498. event: false,
  2499. lastScrollTime: (new window.Date()).getTime()
  2500. };
  2501. if (s.params.mousewheelControl) {
  2502. if (document.onmousewheel !== undefined) {
  2503. s.mousewheel.event = 'mousewheel';
  2504. }
  2505. if (!s.mousewheel.event) {
  2506. try {
  2507. new window.WheelEvent('wheel');
  2508. s.mousewheel.event = 'wheel';
  2509. } catch (e) {}
  2510. }
  2511. if (!s.mousewheel.event) {
  2512. s.mousewheel.event = 'DOMMouseScroll';
  2513. }
  2514. }
  2515. function handleMousewheel(e) {
  2516. if (e.originalEvent) e = e.originalEvent; //jquery fix
  2517. var we = s.mousewheel.event;
  2518. var delta = 0;
  2519. //Opera & IE
  2520. if (e.detail) delta = -e.detail;
  2521. //WebKits
  2522. else if (we === 'mousewheel') {
  2523. if (s.params.mousewheelForceToAxis) {
  2524. if (isH()) {
  2525. if (Math.abs(e.wheelDeltaX) > Math.abs(e.wheelDeltaY)) delta = e.wheelDeltaX;
  2526. else return;
  2527. }
  2528. else {
  2529. if (Math.abs(e.wheelDeltaY) > Math.abs(e.wheelDeltaX)) delta = e.wheelDeltaY;
  2530. else return;
  2531. }
  2532. }
  2533. else {
  2534. delta = e.wheelDelta;
  2535. }
  2536. }
  2537. //Old FireFox
  2538. else if (we === 'DOMMouseScroll') delta = -e.detail;
  2539. //New FireFox
  2540. else if (we === 'wheel') {
  2541. if (s.params.mousewheelForceToAxis) {
  2542. if (isH()) {
  2543. if (Math.abs(e.deltaX) > Math.abs(e.deltaY)) delta = -e.deltaX;
  2544. else return;
  2545. }
  2546. else {
  2547. if (Math.abs(e.deltaY) > Math.abs(e.deltaX)) delta = -e.deltaY;
  2548. else return;
  2549. }
  2550. }
  2551. else {
  2552. delta = Math.abs(e.deltaX) > Math.abs(e.deltaY) ? - e.deltaX : - e.deltaY;
  2553. }
  2554. }
  2555. if (s.params.mousewheelInvert) delta = -delta;
  2556. if (!s.params.freeMode) {
  2557. if ((new window.Date()).getTime() - s.mousewheel.lastScrollTime > 60) {
  2558. if (delta < 0) {
  2559. if (!s.isEnd) s.slideNext();
  2560. else if (s.params.mousewheelReleaseOnEdges) return true;
  2561. }
  2562. else {
  2563. if (!s.isBeginning) s.slidePrev();
  2564. else if (s.params.mousewheelReleaseOnEdges) return true;
  2565. }
  2566. }
  2567. s.mousewheel.lastScrollTime = (new window.Date()).getTime();
  2568. }
  2569. else {
  2570. //Freemode or scrollContainer:
  2571. var position = s.getWrapperTranslate() + delta;
  2572. if (position > 0) position = 0;
  2573. if (position < s.maxTranslate()) position = s.maxTranslate();
  2574. s.setWrapperTransition(0);
  2575. s.setWrapperTranslate(position);
  2576. s.updateProgress();
  2577. s.updateActiveIndex();
  2578. if (s.params.freeModeSticky) {
  2579. clearTimeout(s.mousewheel.timeout);
  2580. s.mousewheel.timeout = setTimeout(function () {
  2581. s.slideReset();
  2582. }, 300);
  2583. }
  2584. // Return page scroll on edge positions
  2585. if (position === 0 || position === s.maxTranslate()) return;
  2586. }
  2587. if (s.params.autoplay) s.stopAutoplay();
  2588. if (e.preventDefault) e.preventDefault();
  2589. else e.returnValue = false;
  2590. return false;
  2591. }
  2592. s.disableMousewheelControl = function () {
  2593. if (!s.mousewheel.event) return false;
  2594. s.container.off(s.mousewheel.event, handleMousewheel);
  2595. return true;
  2596. };
  2597. s.enableMousewheelControl = function () {
  2598. if (!s.mousewheel.event) return false;
  2599. s.container.on(s.mousewheel.event, handleMousewheel);
  2600. return true;
  2601. };
  2602. /*=========================
  2603. Parallax
  2604. ===========================*/
  2605. function setParallaxTransform(el, progress) {
  2606. el = $(el);
  2607. var p, pX, pY;
  2608. p = el.attr('data-swiper-parallax') || '0';
  2609. pX = el.attr('data-swiper-parallax-x');
  2610. pY = el.attr('data-swiper-parallax-y');
  2611. if (pX || pY) {
  2612. pX = pX || '0';
  2613. pY = pY || '0';
  2614. }
  2615. else {
  2616. if (isH()) {
  2617. pX = p;
  2618. pY = '0';
  2619. }
  2620. else {
  2621. pY = p;
  2622. pX = '0';
  2623. }
  2624. }
  2625. if ((pX).indexOf('%') >= 0) {
  2626. pX = parseInt(pX, 10) * progress + '%';
  2627. }
  2628. else {
  2629. pX = pX * progress + 'px' ;
  2630. }
  2631. if ((pY).indexOf('%') >= 0) {
  2632. pY = parseInt(pY, 10) * progress + '%';
  2633. }
  2634. else {
  2635. pY = pY * progress + 'px' ;
  2636. }
  2637. el.transform('translate3d(' + pX + ', ' + pY + ',0px)');
  2638. }
  2639. s.parallax = {
  2640. setTranslate: function () {
  2641. s.container.children('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y]').each(function(){
  2642. setParallaxTransform(this, s.progress);
  2643. });
  2644. s.slides.each(function () {
  2645. var slide = $(this);
  2646. slide.find('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y]').each(function () {
  2647. var progress = Math.min(Math.max(slide[0].progress, -1), 1);
  2648. setParallaxTransform(this, progress);
  2649. });
  2650. });
  2651. },
  2652. setTransition: function (duration) {
  2653. if (typeof duration === 'undefined') duration = s.params.speed;
  2654. s.container.find('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y]').each(function(){
  2655. var el = $(this);
  2656. var parallaxDuration = parseInt(el.attr('data-swiper-parallax-duration'), 10) || duration;
  2657. if (duration === 0) parallaxDuration = 0;
  2658. el.transition(parallaxDuration);
  2659. });
  2660. }
  2661. };
  2662. /*=========================
  2663. Plugins API. Collect all and init all plugins
  2664. ===========================*/
  2665. s._plugins = [];
  2666. for (var plugin in s.plugins) {
  2667. var p = s.plugins[plugin](s, s.params[plugin]);
  2668. if (p) s._plugins.push(p);
  2669. }
  2670. // Method to call all plugins event/method
  2671. s.callPlugins = function (eventName) {
  2672. for (var i = 0; i < s._plugins.length; i++) {
  2673. if (eventName in s._plugins[i]) {
  2674. s._plugins[i][eventName](arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
  2675. }
  2676. }
  2677. };
  2678. /*=========================
  2679. Events/Callbacks/Plugins Emitter
  2680. ===========================*/
  2681. function normalizeEventName (eventName) {
  2682. if (eventName.indexOf('on') !== 0) {
  2683. if (eventName[0] !== eventName[0].toUpperCase()) {
  2684. eventName = 'on' + eventName[0].toUpperCase() + eventName.substring(1);
  2685. }
  2686. else {
  2687. eventName = 'on' + eventName;
  2688. }
  2689. }
  2690. return eventName;
  2691. }
  2692. s.emitterEventListeners = {
  2693. };
  2694. s.emit = function (eventName) {
  2695. // Trigger callbacks
  2696. if (s.params[eventName]) {
  2697. s.params[eventName](arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
  2698. }
  2699. var i;
  2700. // Trigger events
  2701. if (s.emitterEventListeners[eventName]) {
  2702. for (i = 0; i < s.emitterEventListeners[eventName].length; i++) {
  2703. s.emitterEventListeners[eventName][i](arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
  2704. }
  2705. }
  2706. // Trigger plugins
  2707. if (s.callPlugins) s.callPlugins(eventName, arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
  2708. };
  2709. s.on = function (eventName, handler) {
  2710. eventName = normalizeEventName(eventName);
  2711. if (!s.emitterEventListeners[eventName]) s.emitterEventListeners[eventName] = [];
  2712. s.emitterEventListeners[eventName].push(handler);
  2713. return s;
  2714. };
  2715. s.off = function (eventName, handler) {
  2716. var i;
  2717. eventName = normalizeEventName(eventName);
  2718. if (typeof handler === 'undefined') {
  2719. // Remove all handlers for such event
  2720. s.emitterEventListeners[eventName] = [];
  2721. return s;
  2722. }
  2723. if (!s.emitterEventListeners[eventName] || s.emitterEventListeners[eventName].length === 0) return;
  2724. for (i = 0; i < s.emitterEventListeners[eventName].length; i++) {
  2725. if(s.emitterEventListeners[eventName][i] === handler) s.emitterEventListeners[eventName].splice(i, 1);
  2726. }
  2727. return s;
  2728. };
  2729. s.once = function (eventName, handler) {
  2730. eventName = normalizeEventName(eventName);
  2731. var _handler = function () {
  2732. handler(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4]);
  2733. s.off(eventName, _handler);
  2734. };
  2735. s.on(eventName, _handler);
  2736. return s;
  2737. };
  2738. // Accessibility tools
  2739. s.a11y = {
  2740. makeFocusable: function ($el) {
  2741. $el.attr('tabIndex', '0');
  2742. return $el;
  2743. },
  2744. addRole: function ($el, role) {
  2745. $el.attr('role', role);
  2746. return $el;
  2747. },
  2748. addLabel: function ($el, label) {
  2749. $el.attr('aria-label', label);
  2750. return $el;
  2751. },
  2752. disable: function ($el) {
  2753. $el.attr('aria-disabled', true);
  2754. return $el;
  2755. },
  2756. enable: function ($el) {
  2757. $el.attr('aria-disabled', false);
  2758. return $el;
  2759. },
  2760. onEnterKey: function (event) {
  2761. if (event.keyCode !== 13) return;
  2762. if ($(event.target).is(s.params.nextButton)) {
  2763. s.onClickNext(event);
  2764. if (s.isEnd) {
  2765. s.a11y.notify(s.params.lastSlideMessage);
  2766. }
  2767. else {
  2768. s.a11y.notify(s.params.nextSlideMessage);
  2769. }
  2770. }
  2771. else if ($(event.target).is(s.params.prevButton)) {
  2772. s.onClickPrev(event);
  2773. if (s.isBeginning) {
  2774. s.a11y.notify(s.params.firstSlideMessage);
  2775. }
  2776. else {
  2777. s.a11y.notify(s.params.prevSlideMessage);
  2778. }
  2779. }
  2780. if ($(event.target).is('.' + s.params.bulletClass)) {
  2781. $(event.target)[0].click();
  2782. }
  2783. },
  2784. liveRegion: $('<span class="swiper-notification" aria-live="assertive" aria-atomic="true"></span>'),
  2785. notify: function (message) {
  2786. var notification = s.a11y.liveRegion;
  2787. if (notification.length === 0) return;
  2788. notification.html('');
  2789. notification.html(message);
  2790. },
  2791. init: function () {
  2792. // Setup accessibility
  2793. if (s.params.nextButton) {
  2794. var nextButton = $(s.params.nextButton);
  2795. s.a11y.makeFocusable(nextButton);
  2796. s.a11y.addRole(nextButton, 'button');
  2797. s.a11y.addLabel(nextButton, s.params.nextSlideMessage);
  2798. }
  2799. if (s.params.prevButton) {
  2800. var prevButton = $(s.params.prevButton);
  2801. s.a11y.makeFocusable(prevButton);
  2802. s.a11y.addRole(prevButton, 'button');
  2803. s.a11y.addLabel(prevButton, s.params.prevSlideMessage);
  2804. }
  2805. $(s.container).append(s.a11y.liveRegion);
  2806. },
  2807. initPagination: function () {
  2808. if (s.params.pagination && s.params.paginationClickable && s.bullets && s.bullets.length) {
  2809. s.bullets.each(function () {
  2810. var bullet = $(this);
  2811. s.a11y.makeFocusable(bullet);
  2812. s.a11y.addRole(bullet, 'button');
  2813. s.a11y.addLabel(bullet, s.params.paginationBulletMessage.replace(/{{index}}/, bullet.index() + 1));
  2814. });
  2815. }
  2816. },
  2817. destroy: function () {
  2818. if (s.a11y.liveRegion && s.a11y.liveRegion.length > 0) s.a11y.liveRegion.remove();
  2819. }
  2820. };
  2821. /*=========================
  2822. Init/Destroy
  2823. ===========================*/
  2824. s.init = function () {
  2825. if (s.params.loop) s.createLoop();
  2826. s.updateContainerSize();
  2827. s.updateSlidesSize();
  2828. s.updatePagination();
  2829. if (s.params.scrollbar && s.scrollbar) {
  2830. s.scrollbar.set();
  2831. }
  2832. if (s.params.effect !== 'slide' && s.effects[s.params.effect]) {
  2833. if (!s.params.loop) s.updateProgress();
  2834. s.effects[s.params.effect].setTranslate();
  2835. }
  2836. if (s.params.loop) {
  2837. s.slideTo(s.params.initialSlide + s.loopedSlides, 0, s.params.runCallbacksOnInit);
  2838. }
  2839. else {
  2840. s.slideTo(s.params.initialSlide, 0, s.params.runCallbacksOnInit);
  2841. if (s.params.initialSlide === 0) {
  2842. if (s.parallax && s.params.parallax) s.parallax.setTranslate();
  2843. if (s.lazy && s.params.lazyLoading) {
  2844. s.lazy.load();
  2845. s.lazy.initialImageLoaded = true;
  2846. }
  2847. }
  2848. }
  2849. s.attachEvents();
  2850. if (s.params.observer && s.support.observer) {
  2851. s.initObservers();
  2852. }
  2853. if (s.params.preloadImages && !s.params.lazyLoading) {
  2854. s.preloadImages();
  2855. }
  2856. if (s.params.autoplay) {
  2857. s.startAutoplay();
  2858. }
  2859. if (s.params.keyboardControl) {
  2860. if (s.enableKeyboardControl) s.enableKeyboardControl();
  2861. }
  2862. if (s.params.mousewheelControl) {
  2863. if (s.enableMousewheelControl) s.enableMousewheelControl();
  2864. }
  2865. if (s.params.hashnav) {
  2866. if (s.hashnav) s.hashnav.init();
  2867. }
  2868. if (s.params.a11y && s.a11y) s.a11y.init();
  2869. s.emit('onInit', s);
  2870. };
  2871. // Cleanup dynamic styles
  2872. s.cleanupStyles = function () {
  2873. // Container
  2874. s.container.removeClass(s.classNames.join(' ')).removeAttr('style');
  2875. // Wrapper
  2876. s.wrapper.removeAttr('style');
  2877. // Slides
  2878. if (s.slides && s.slides.length) {
  2879. s.slides
  2880. .removeClass([
  2881. s.params.slideVisibleClass,
  2882. s.params.slideActiveClass,
  2883. s.params.slideNextClass,
  2884. s.params.slidePrevClass
  2885. ].join(' '))
  2886. .removeAttr('style')
  2887. .removeAttr('data-swiper-column')
  2888. .removeAttr('data-swiper-row');
  2889. }
  2890. // Pagination/Bullets
  2891. if (s.paginationContainer && s.paginationContainer.length) {
  2892. s.paginationContainer.removeClass(s.params.paginationHiddenClass);
  2893. }
  2894. if (s.bullets && s.bullets.length) {
  2895. s.bullets.removeClass(s.params.bulletActiveClass);
  2896. }
  2897. // Buttons
  2898. if (s.params.prevButton) $(s.params.prevButton).removeClass(s.params.buttonDisabledClass);
  2899. if (s.params.nextButton) $(s.params.nextButton).removeClass(s.params.buttonDisabledClass);
  2900. // Scrollbar
  2901. if (s.params.scrollbar && s.scrollbar) {
  2902. if (s.scrollbar.track && s.scrollbar.track.length) s.scrollbar.track.removeAttr('style');
  2903. if (s.scrollbar.drag && s.scrollbar.drag.length) s.scrollbar.drag.removeAttr('style');
  2904. }
  2905. };
  2906. // Destroy
  2907. s.destroy = function (deleteInstance, cleanupStyles) {
  2908. // Detach evebts
  2909. s.detachEvents();
  2910. // Stop autoplay
  2911. s.stopAutoplay();
  2912. // Destroy loop
  2913. if (s.params.loop) {
  2914. s.destroyLoop();
  2915. }
  2916. // Cleanup styles
  2917. if (cleanupStyles) {
  2918. s.cleanupStyles();
  2919. }
  2920. // Disconnect observer
  2921. s.disconnectObservers();
  2922. // Disable keyboard/mousewheel
  2923. if (s.params.keyboardControl) {
  2924. if (s.disableKeyboardControl) s.disableKeyboardControl();
  2925. }
  2926. if (s.params.mousewheelControl) {
  2927. if (s.disableMousewheelControl) s.disableMousewheelControl();
  2928. }
  2929. // Disable a11y
  2930. if (s.params.a11y && s.a11y) s.a11y.destroy();
  2931. // Destroy callback
  2932. s.emit('onDestroy');
  2933. // Delete instance
  2934. if (deleteInstance !== false) s = null;
  2935. };
  2936. s.init();
  2937. // Return swiper instance
  2938. return s;
  2939. };
  2940. /*==================================================
  2941. Prototype
  2942. ====================================================*/
  2943. Swiper.prototype = {
  2944. isSafari: (function () {
  2945. var ua = navigator.userAgent.toLowerCase();
  2946. return (ua.indexOf('safari') >= 0 && ua.indexOf('chrome') < 0 && ua.indexOf('android') < 0);
  2947. })(),
  2948. isUiWebView: /(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(navigator.userAgent),
  2949. isArray: function (arr) {
  2950. return Object.prototype.toString.apply(arr) === '[object Array]';
  2951. },
  2952. /*==================================================
  2953. Browser
  2954. ====================================================*/
  2955. browser: {
  2956. ie: window.navigator.pointerEnabled || window.navigator.msPointerEnabled,
  2957. ieTouch: (window.navigator.msPointerEnabled && window.navigator.msMaxTouchPoints > 1) || (window.navigator.pointerEnabled && window.navigator.maxTouchPoints > 1),
  2958. },
  2959. /*==================================================
  2960. Devices
  2961. ====================================================*/
  2962. device: (function () {
  2963. var ua = navigator.userAgent;
  2964. var android = ua.match(/(Android);?[\s\/]+([\d.]+)?/);
  2965. var ipad = ua.match(/(iPad).*OS\s([\d_]+)/);
  2966. var ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/);
  2967. var iphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/);
  2968. return {
  2969. ios: ipad || iphone || ipod,
  2970. android: android
  2971. };
  2972. })(),
  2973. /*==================================================
  2974. Feature Detection
  2975. ====================================================*/
  2976. support: {
  2977. touch : (window.Modernizr && Modernizr.touch === true) || (function () {
  2978. return !!(('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch);
  2979. })(),
  2980. transforms3d : (window.Modernizr && Modernizr.csstransforms3d === true) || (function () {
  2981. var div = document.createElement('div').style;
  2982. return ('webkitPerspective' in div || 'MozPerspective' in div || 'OPerspective' in div || 'MsPerspective' in div || 'perspective' in div);
  2983. })(),
  2984. flexbox: (function () {
  2985. var div = document.createElement('div').style;
  2986. var styles = ('alignItems webkitAlignItems webkitBoxAlign msFlexAlign mozBoxAlign webkitFlexDirection msFlexDirection mozBoxDirection mozBoxOrient webkitBoxDirection webkitBoxOrient').split(' ');
  2987. for (var i = 0; i < styles.length; i++) {
  2988. if (styles[i] in div) return true;
  2989. }
  2990. })(),
  2991. observer: (function () {
  2992. return ('MutationObserver' in window || 'WebkitMutationObserver' in window);
  2993. })()
  2994. },
  2995. /*==================================================
  2996. Plugins
  2997. ====================================================*/
  2998. plugins: {}
  2999. };
  3000. /*===========================
  3001. Get jQuery
  3002. ===========================*/
  3003. addLibraryPlugin($);
  3004. var domLib = $;
  3005. /*===========================
  3006. Add .swiper plugin from Dom libraries
  3007. ===========================*/
  3008. function addLibraryPlugin(lib) {
  3009. lib.fn.swiper = function (params) {
  3010. var firstInstance;
  3011. lib(this).each(function () {
  3012. var s = new Swiper(this, params);
  3013. if (!firstInstance) firstInstance = s;
  3014. });
  3015. return firstInstance;
  3016. };
  3017. }
  3018. if (domLib) {
  3019. if (!('transitionEnd' in domLib.fn)) {
  3020. domLib.fn.transitionEnd = function (callback) {
  3021. var events = ['webkitTransitionEnd', 'transitionend', 'oTransitionEnd', 'MSTransitionEnd', 'msTransitionEnd'],
  3022. i, j, dom = this;
  3023. function fireCallBack(e) {
  3024. /*jshint validthis:true */
  3025. if (e.target !== this) return;
  3026. callback.call(this, e);
  3027. for (i = 0; i < events.length; i++) {
  3028. dom.off(events[i], fireCallBack);
  3029. }
  3030. }
  3031. if (callback) {
  3032. for (i = 0; i < events.length; i++) {
  3033. dom.on(events[i], fireCallBack);
  3034. }
  3035. }
  3036. return this;
  3037. };
  3038. }
  3039. if (!('transform' in domLib.fn)) {
  3040. domLib.fn.transform = function (transform) {
  3041. for (var i = 0; i < this.length; i++) {
  3042. var elStyle = this[i].style;
  3043. elStyle.webkitTransform = elStyle.MsTransform = elStyle.msTransform = elStyle.MozTransform = elStyle.OTransform = elStyle.transform = transform;
  3044. }
  3045. return this;
  3046. };
  3047. }
  3048. if (!('transition' in domLib.fn)) {
  3049. domLib.fn.transition = function (duration) {
  3050. if (typeof duration !== 'string') {
  3051. duration = duration + 'ms';
  3052. }
  3053. for (var i = 0; i < this.length; i++) {
  3054. var elStyle = this[i].style;
  3055. elStyle.webkitTransitionDuration = elStyle.MsTransitionDuration = elStyle.msTransitionDuration = elStyle.MozTransitionDuration = elStyle.OTransitionDuration = elStyle.transitionDuration = duration;
  3056. }
  3057. return this;
  3058. };
  3059. }
  3060. }
  3061. return Swiper;
  3062. }));