swiper.jquery.js 137 KB

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