swiper.jquery.js 203 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669
  1. /**
  2. * Swiper 3.4.1
  3. * Most modern mobile touch slider and framework with hardware accelerated transitions
  4. *
  5. * http://www.idangero.us/swiper/
  6. *
  7. * Copyright 2016, Vladimir Kharlampidi
  8. * The iDangero.us
  9. * http://www.idangero.us/
  10. *
  11. * Licensed under MIT
  12. *
  13. * Released on: December 13, 2016
  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. autoplayStopOnLast: false,
  32. // To support iOS's swipe-to-go-back gesture (when being used in-app, with UIWebView).
  33. iOSEdgeSwipeDetection: false,
  34. iOSEdgeSwipeThreshold: 20,
  35. // Free mode
  36. freeMode: false,
  37. freeModeMomentum: true,
  38. freeModeMomentumRatio: 1,
  39. freeModeMomentumBounce: true,
  40. freeModeMomentumBounceRatio: 1,
  41. freeModeMomentumVelocityRatio: 1,
  42. freeModeSticky: false,
  43. freeModeMinimumVelocity: 0.02,
  44. // Autoheight
  45. autoHeight: false,
  46. // Set wrapper width
  47. setWrapperSize: false,
  48. // Virtual Translate
  49. virtualTranslate: false,
  50. // Effects
  51. effect: 'slide', // 'slide' or 'fade' or 'cube' or 'coverflow' or 'flip'
  52. coverflow: {
  53. rotate: 50,
  54. stretch: 0,
  55. depth: 100,
  56. modifier: 1,
  57. slideShadows : true
  58. },
  59. flip: {
  60. slideShadows : true,
  61. limitRotation: true
  62. },
  63. cube: {
  64. slideShadows: true,
  65. shadow: true,
  66. shadowOffset: 20,
  67. shadowScale: 0.94
  68. },
  69. fade: {
  70. crossFade: false
  71. },
  72. // Parallax
  73. parallax: false,
  74. // Zoom
  75. zoom: false,
  76. zoomMax: 3,
  77. zoomMin: 1,
  78. zoomToggle: true,
  79. // Scrollbar
  80. scrollbar: null,
  81. scrollbarHide: true,
  82. scrollbarDraggable: false,
  83. scrollbarSnapOnRelease: false,
  84. // Keyboard Mousewheel
  85. keyboardControl: false,
  86. mousewheelControl: false,
  87. mousewheelReleaseOnEdges: false,
  88. mousewheelInvert: false,
  89. mousewheelForceToAxis: false,
  90. mousewheelSensitivity: 1,
  91. mousewheelEventsTarged: 'container',
  92. // Hash Navigation
  93. hashnav: false,
  94. hashnavWatchState: false,
  95. // History
  96. history: false,
  97. // Commong Nav State
  98. replaceState: false,
  99. // Breakpoints
  100. breakpoints: undefined,
  101. // Slides grid
  102. spaceBetween: 0,
  103. slidesPerView: 1,
  104. slidesPerColumn: 1,
  105. slidesPerColumnFill: 'column',
  106. slidesPerGroup: 1,
  107. centeredSlides: false,
  108. slidesOffsetBefore: 0, // in px
  109. slidesOffsetAfter: 0, // in px
  110. // Round length
  111. roundLengths: false,
  112. // Touches
  113. touchRatio: 1,
  114. touchAngle: 45,
  115. simulateTouch: true,
  116. shortSwipes: true,
  117. longSwipes: true,
  118. longSwipesRatio: 0.5,
  119. longSwipesMs: 300,
  120. followFinger: true,
  121. onlyExternal: false,
  122. threshold: 0,
  123. touchMoveStopPropagation: true,
  124. touchReleaseOnEdges: false,
  125. // Unique Navigation Elements
  126. uniqueNavElements: true,
  127. // Pagination
  128. pagination: null,
  129. paginationElement: 'span',
  130. paginationClickable: false,
  131. paginationHide: false,
  132. paginationBulletRender: null,
  133. paginationProgressRender: null,
  134. paginationFractionRender: null,
  135. paginationCustomRender: null,
  136. paginationType: 'bullets', // 'bullets' or 'progress' or 'fraction' or 'custom'
  137. // Resistance
  138. resistance: true,
  139. resistanceRatio: 0.85,
  140. // Next/prev buttons
  141. nextButton: null,
  142. prevButton: null,
  143. // Progress
  144. watchSlidesProgress: false,
  145. watchSlidesVisibility: false,
  146. // Cursor
  147. grabCursor: false,
  148. // Clicks
  149. preventClicks: true,
  150. preventClicksPropagation: true,
  151. slideToClickedSlide: false,
  152. // Lazy Loading
  153. lazyLoading: false,
  154. lazyLoadingInPrevNext: false,
  155. lazyLoadingInPrevNextAmount: 1,
  156. lazyLoadingOnTransitionStart: false,
  157. // Images
  158. preloadImages: true,
  159. updateOnImagesReady: true,
  160. // loop
  161. loop: false,
  162. loopAdditionalSlides: 0,
  163. loopedSlides: null,
  164. // Control
  165. control: undefined,
  166. controlInverse: false,
  167. controlBy: 'slide', //or 'container'
  168. normalizeSlideIndex: true,
  169. // Swiping/no swiping
  170. allowSwipeToPrev: true,
  171. allowSwipeToNext: true,
  172. swipeHandler: null, //'.swipe-handler',
  173. noSwiping: true,
  174. noSwipingClass: 'swiper-no-swiping',
  175. // Passive Listeners
  176. passiveListeners: true,
  177. // NS
  178. containerModifierClass: 'swiper-container-', // NEW
  179. slideClass: 'swiper-slide',
  180. slideActiveClass: 'swiper-slide-active',
  181. slideDuplicateActiveClass: 'swiper-slide-duplicate-active',
  182. slideVisibleClass: 'swiper-slide-visible',
  183. slideDuplicateClass: 'swiper-slide-duplicate',
  184. slideNextClass: 'swiper-slide-next',
  185. slideDuplicateNextClass: 'swiper-slide-duplicate-next',
  186. slidePrevClass: 'swiper-slide-prev',
  187. slideDuplicatePrevClass: 'swiper-slide-duplicate-prev',
  188. wrapperClass: 'swiper-wrapper',
  189. bulletClass: 'swiper-pagination-bullet',
  190. bulletActiveClass: 'swiper-pagination-bullet-active',
  191. buttonDisabledClass: 'swiper-button-disabled',
  192. paginationCurrentClass: 'swiper-pagination-current',
  193. paginationTotalClass: 'swiper-pagination-total',
  194. paginationHiddenClass: 'swiper-pagination-hidden',
  195. paginationProgressbarClass: 'swiper-pagination-progressbar',
  196. paginationClickableClass: 'swiper-pagination-clickable', // NEW
  197. paginationModifierClass: 'swiper-pagination-', // NEW
  198. lazyLoadingClass: 'swiper-lazy',
  199. lazyStatusLoadingClass: 'swiper-lazy-loading',
  200. lazyStatusLoadedClass: 'swiper-lazy-loaded',
  201. lazyPreloaderClass: 'swiper-lazy-preloader',
  202. notificationClass: 'swiper-notification',
  203. preloaderClass: 'preloader',
  204. zoomContainerClass: 'swiper-zoom-container',
  205. // Observer
  206. observer: false,
  207. observeParents: false,
  208. // Accessibility
  209. a11y: false,
  210. prevSlideMessage: 'Previous slide',
  211. nextSlideMessage: 'Next slide',
  212. firstSlideMessage: 'This is the first slide',
  213. lastSlideMessage: 'This is the last slide',
  214. paginationBulletMessage: 'Go to slide {{index}}',
  215. // Callbacks
  216. runCallbacksOnInit: true
  217. /*
  218. Callbacks:
  219. onInit: function (swiper)
  220. onDestroy: function (swiper)
  221. onClick: function (swiper, e)
  222. onTap: function (swiper, e)
  223. onDoubleTap: function (swiper, e)
  224. onSliderMove: function (swiper, e)
  225. onSlideChangeStart: function (swiper)
  226. onSlideChangeEnd: function (swiper)
  227. onTransitionStart: function (swiper)
  228. onTransitionEnd: function (swiper)
  229. onImagesReady: function (swiper)
  230. onProgress: function (swiper, progress)
  231. onTouchStart: function (swiper, e)
  232. onTouchMove: function (swiper, e)
  233. onTouchMoveOpposite: function (swiper, e)
  234. onTouchEnd: function (swiper, e)
  235. onReachBeginning: function (swiper)
  236. onReachEnd: function (swiper)
  237. onSetTransition: function (swiper, duration)
  238. onSetTranslate: function (swiper, translate)
  239. onAutoplayStart: function (swiper)
  240. onAutoplayStop: function (swiper),
  241. onLazyImageLoad: function (swiper, slide, image)
  242. onLazyImageReady: function (swiper, slide, image)
  243. */
  244. };
  245. var initialVirtualTranslate = params && params.virtualTranslate;
  246. params = params || {};
  247. var originalParams = {};
  248. for (var param in params) {
  249. if (typeof params[param] === 'object' && params[param] !== null && !(params[param].nodeType || params[param] === window || params[param] === document || (typeof Dom7 !== 'undefined' && params[param] instanceof Dom7) || (typeof jQuery !== 'undefined' && params[param] instanceof jQuery))) {
  250. originalParams[param] = {};
  251. for (var deepParam in params[param]) {
  252. originalParams[param][deepParam] = params[param][deepParam];
  253. }
  254. }
  255. else {
  256. originalParams[param] = params[param];
  257. }
  258. }
  259. for (var def in defaults) {
  260. if (typeof params[def] === 'undefined') {
  261. params[def] = defaults[def];
  262. }
  263. else if (typeof params[def] === 'object') {
  264. for (var deepDef in defaults[def]) {
  265. if (typeof params[def][deepDef] === 'undefined') {
  266. params[def][deepDef] = defaults[def][deepDef];
  267. }
  268. }
  269. }
  270. }
  271. // Swiper
  272. var s = this;
  273. // Params
  274. s.params = params;
  275. s.originalParams = originalParams;
  276. // Classname
  277. s.classNames = [];
  278. /*=========================
  279. Dom Library and plugins
  280. ===========================*/
  281. if (typeof $ !== 'undefined' && typeof Dom7 !== 'undefined'){
  282. $ = Dom7;
  283. }
  284. if (typeof $ === 'undefined') {
  285. if (typeof Dom7 === 'undefined') {
  286. $ = window.Dom7 || window.Zepto || window.jQuery;
  287. }
  288. else {
  289. $ = Dom7;
  290. }
  291. if (!$) return;
  292. }
  293. // Export it to Swiper instance
  294. s.$ = $;
  295. /*=========================
  296. Breakpoints
  297. ===========================*/
  298. s.currentBreakpoint = undefined;
  299. s.getActiveBreakpoint = function () {
  300. //Get breakpoint for window width
  301. if (!s.params.breakpoints) return false;
  302. var breakpoint = false;
  303. var points = [], point;
  304. for ( point in s.params.breakpoints ) {
  305. if (s.params.breakpoints.hasOwnProperty(point)) {
  306. points.push(point);
  307. }
  308. }
  309. points.sort(function (a, b) {
  310. return parseInt(a, 10) > parseInt(b, 10);
  311. });
  312. for (var i = 0; i < points.length; i++) {
  313. point = points[i];
  314. if (point >= window.innerWidth && !breakpoint) {
  315. breakpoint = point;
  316. }
  317. }
  318. return breakpoint || 'max';
  319. };
  320. s.setBreakpoint = function () {
  321. //Set breakpoint for window width and update parameters
  322. var breakpoint = s.getActiveBreakpoint();
  323. if (breakpoint && s.currentBreakpoint !== breakpoint) {
  324. var breakPointsParams = breakpoint in s.params.breakpoints ? s.params.breakpoints[breakpoint] : s.originalParams;
  325. var needsReLoop = s.params.loop && (breakPointsParams.slidesPerView !== s.params.slidesPerView);
  326. for ( var param in breakPointsParams ) {
  327. s.params[param] = breakPointsParams[param];
  328. }
  329. s.currentBreakpoint = breakpoint;
  330. if(needsReLoop && s.destroyLoop) {
  331. s.reLoop(true);
  332. }
  333. }
  334. };
  335. // Set breakpoint on load
  336. if (s.params.breakpoints) {
  337. s.setBreakpoint();
  338. }
  339. /*=========================
  340. Preparation - Define Container, Wrapper and Pagination
  341. ===========================*/
  342. s.container = $(container);
  343. if (s.container.length === 0) return;
  344. if (s.container.length > 1) {
  345. var swipers = [];
  346. s.container.each(function () {
  347. var container = this;
  348. swipers.push(new Swiper(this, params));
  349. });
  350. return swipers;
  351. }
  352. // Save instance in container HTML Element and in data
  353. s.container[0].swiper = s;
  354. s.container.data('swiper', s);
  355. s.classNames.push(s.params.containerModifierClass + s.params.direction);
  356. if (s.params.freeMode) {
  357. s.classNames.push(s.params.containerModifierClass + 'free-mode');
  358. }
  359. if (!s.support.flexbox) {
  360. s.classNames.push(s.params.containerModifierClass + 'no-flexbox');
  361. s.params.slidesPerColumn = 1;
  362. }
  363. if (s.params.autoHeight) {
  364. s.classNames.push(s.params.containerModifierClass + 'autoheight');
  365. }
  366. // Enable slides progress when required
  367. if (s.params.parallax || s.params.watchSlidesVisibility) {
  368. s.params.watchSlidesProgress = true;
  369. }
  370. // Max resistance when touchReleaseOnEdges
  371. if (s.params.touchReleaseOnEdges) {
  372. s.params.resistanceRatio = 0;
  373. }
  374. // Coverflow / 3D
  375. if (['cube', 'coverflow', 'flip'].indexOf(s.params.effect) >= 0) {
  376. if (s.support.transforms3d) {
  377. s.params.watchSlidesProgress = true;
  378. s.classNames.push(s.params.containerModifierClass + '3d');
  379. }
  380. else {
  381. s.params.effect = 'slide';
  382. }
  383. }
  384. if (s.params.effect !== 'slide') {
  385. s.classNames.push(s.params.containerModifierClass + s.params.effect);
  386. }
  387. if (s.params.effect === 'cube') {
  388. s.params.resistanceRatio = 0;
  389. s.params.slidesPerView = 1;
  390. s.params.slidesPerColumn = 1;
  391. s.params.slidesPerGroup = 1;
  392. s.params.centeredSlides = false;
  393. s.params.spaceBetween = 0;
  394. s.params.virtualTranslate = true;
  395. s.params.setWrapperSize = false;
  396. }
  397. if (s.params.effect === 'fade' || s.params.effect === 'flip') {
  398. s.params.slidesPerView = 1;
  399. s.params.slidesPerColumn = 1;
  400. s.params.slidesPerGroup = 1;
  401. s.params.watchSlidesProgress = true;
  402. s.params.spaceBetween = 0;
  403. s.params.setWrapperSize = false;
  404. if (typeof initialVirtualTranslate === 'undefined') {
  405. s.params.virtualTranslate = true;
  406. }
  407. }
  408. // Grab Cursor
  409. if (s.params.grabCursor && s.support.touch) {
  410. s.params.grabCursor = false;
  411. }
  412. // Wrapper
  413. s.wrapper = s.container.children('.' + s.params.wrapperClass);
  414. // Pagination
  415. if (s.params.pagination) {
  416. s.paginationContainer = $(s.params.pagination);
  417. if (s.params.uniqueNavElements && typeof s.params.pagination === 'string' && s.paginationContainer.length > 1 && s.container.find(s.params.pagination).length === 1) {
  418. s.paginationContainer = s.container.find(s.params.pagination);
  419. }
  420. if (s.params.paginationType === 'bullets' && s.params.paginationClickable) {
  421. s.paginationContainer.addClass(s.params.paginationModifierClass + 'clickable');
  422. }
  423. else {
  424. s.params.paginationClickable = false;
  425. }
  426. s.paginationContainer.addClass(s.params.paginationModifierClass + s.params.paginationType);
  427. }
  428. // Next/Prev Buttons
  429. if (s.params.nextButton || s.params.prevButton) {
  430. if (s.params.nextButton) {
  431. s.nextButton = $(s.params.nextButton);
  432. if (s.params.uniqueNavElements && typeof s.params.nextButton === 'string' && s.nextButton.length > 1 && s.container.find(s.params.nextButton).length === 1) {
  433. s.nextButton = s.container.find(s.params.nextButton);
  434. }
  435. }
  436. if (s.params.prevButton) {
  437. s.prevButton = $(s.params.prevButton);
  438. if (s.params.uniqueNavElements && typeof s.params.prevButton === 'string' && s.prevButton.length > 1 && s.container.find(s.params.prevButton).length === 1) {
  439. s.prevButton = s.container.find(s.params.prevButton);
  440. }
  441. }
  442. }
  443. // Is Horizontal
  444. s.isHorizontal = function () {
  445. return s.params.direction === 'horizontal';
  446. };
  447. // s.isH = isH;
  448. // RTL
  449. s.rtl = s.isHorizontal() && (s.container[0].dir.toLowerCase() === 'rtl' || s.container.css('direction') === 'rtl');
  450. if (s.rtl) {
  451. s.classNames.push(s.params.containerModifierClass + 'rtl');
  452. }
  453. // Wrong RTL support
  454. if (s.rtl) {
  455. s.wrongRTL = s.wrapper.css('display') === '-webkit-box';
  456. }
  457. // Columns
  458. if (s.params.slidesPerColumn > 1) {
  459. s.classNames.push(s.params.containerModifierClass + 'multirow');
  460. }
  461. // Check for Android
  462. if (s.device.android) {
  463. s.classNames.push(s.params.containerModifierClass + 'android');
  464. }
  465. // Add classes
  466. s.container.addClass(s.classNames.join(' '));
  467. // Translate
  468. s.translate = 0;
  469. // Progress
  470. s.progress = 0;
  471. // Velocity
  472. s.velocity = 0;
  473. /*=========================
  474. Locks, unlocks
  475. ===========================*/
  476. s.lockSwipeToNext = function () {
  477. s.params.allowSwipeToNext = false;
  478. if (s.params.allowSwipeToPrev === false && s.params.grabCursor) {
  479. s.unsetGrabCursor();
  480. }
  481. };
  482. s.lockSwipeToPrev = function () {
  483. s.params.allowSwipeToPrev = false;
  484. if (s.params.allowSwipeToNext === false && s.params.grabCursor) {
  485. s.unsetGrabCursor();
  486. }
  487. };
  488. s.lockSwipes = function () {
  489. s.params.allowSwipeToNext = s.params.allowSwipeToPrev = false;
  490. if (s.params.grabCursor) s.unsetGrabCursor();
  491. };
  492. s.unlockSwipeToNext = function () {
  493. s.params.allowSwipeToNext = true;
  494. if (s.params.allowSwipeToPrev === true && s.params.grabCursor) {
  495. s.setGrabCursor();
  496. }
  497. };
  498. s.unlockSwipeToPrev = function () {
  499. s.params.allowSwipeToPrev = true;
  500. if (s.params.allowSwipeToNext === true && s.params.grabCursor) {
  501. s.setGrabCursor();
  502. }
  503. };
  504. s.unlockSwipes = function () {
  505. s.params.allowSwipeToNext = s.params.allowSwipeToPrev = true;
  506. if (s.params.grabCursor) s.setGrabCursor();
  507. };
  508. /*=========================
  509. Round helper
  510. ===========================*/
  511. function round(a) {
  512. return Math.floor(a);
  513. }
  514. /*=========================
  515. Set grab cursor
  516. ===========================*/
  517. s.setGrabCursor = function(moving) {
  518. s.container[0].style.cursor = 'move';
  519. s.container[0].style.cursor = moving ? '-webkit-grabbing' : '-webkit-grab';
  520. s.container[0].style.cursor = moving ? '-moz-grabbin' : '-moz-grab';
  521. s.container[0].style.cursor = moving ? 'grabbing': 'grab';
  522. };
  523. s.unsetGrabCursor = function () {
  524. s.container[0].style.cursor = '';
  525. };
  526. if (s.params.grabCursor) {
  527. s.setGrabCursor();
  528. }
  529. /*=========================
  530. Update on Images Ready
  531. ===========================*/
  532. s.imagesToLoad = [];
  533. s.imagesLoaded = 0;
  534. s.loadImage = function (imgElement, src, srcset, sizes, checkForComplete, callback) {
  535. var image;
  536. function onReady () {
  537. if (callback) callback();
  538. }
  539. if (!imgElement.complete || !checkForComplete) {
  540. if (src) {
  541. image = new window.Image();
  542. image.onload = onReady;
  543. image.onerror = onReady;
  544. if (sizes) {
  545. image.sizes = sizes;
  546. }
  547. if (srcset) {
  548. image.srcset = srcset;
  549. }
  550. if (src) {
  551. image.src = src;
  552. }
  553. } else {
  554. onReady();
  555. }
  556. } else {//image already loaded...
  557. onReady();
  558. }
  559. };
  560. s.preloadImages = function () {
  561. s.imagesToLoad = s.container.find('img');
  562. function _onReady() {
  563. if (typeof s === 'undefined' || s === null || !s) return;
  564. if (s.imagesLoaded !== undefined) s.imagesLoaded++;
  565. if (s.imagesLoaded === s.imagesToLoad.length) {
  566. if (s.params.updateOnImagesReady) s.update();
  567. s.emit('onImagesReady', s);
  568. }
  569. }
  570. for (var i = 0; i < s.imagesToLoad.length; i++) {
  571. s.loadImage(s.imagesToLoad[i], (s.imagesToLoad[i].currentSrc || s.imagesToLoad[i].getAttribute('src')), (s.imagesToLoad[i].srcset || s.imagesToLoad[i].getAttribute('srcset')), s.imagesToLoad[i].sizes || s.imagesToLoad[i].getAttribute('sizes'), true, _onReady);
  572. }
  573. };
  574. /*=========================
  575. Autoplay
  576. ===========================*/
  577. s.autoplayTimeoutId = undefined;
  578. s.autoplaying = false;
  579. s.autoplayPaused = false;
  580. function autoplay() {
  581. var autoplayDelay = s.params.autoplay;
  582. var activeSlide = s.slides.eq(s.activeIndex);
  583. if (activeSlide.attr('data-swiper-autoplay')) {
  584. autoplayDelay = activeSlide.attr('data-swiper-autoplay') || s.params.autoplay;
  585. }
  586. s.autoplayTimeoutId = setTimeout(function () {
  587. if (s.params.loop) {
  588. s.fixLoop();
  589. s._slideNext();
  590. s.emit('onAutoplay', s);
  591. }
  592. else {
  593. if (!s.isEnd) {
  594. s._slideNext();
  595. s.emit('onAutoplay', s);
  596. }
  597. else {
  598. if (!params.autoplayStopOnLast) {
  599. s._slideTo(0);
  600. s.emit('onAutoplay', s);
  601. }
  602. else {
  603. s.stopAutoplay();
  604. }
  605. }
  606. }
  607. }, autoplayDelay);
  608. }
  609. s.startAutoplay = function () {
  610. if (typeof s.autoplayTimeoutId !== 'undefined') return false;
  611. if (!s.params.autoplay) return false;
  612. if (s.autoplaying) return false;
  613. s.autoplaying = true;
  614. s.emit('onAutoplayStart', s);
  615. autoplay();
  616. };
  617. s.stopAutoplay = function (internal) {
  618. if (!s.autoplayTimeoutId) return;
  619. if (s.autoplayTimeoutId) clearTimeout(s.autoplayTimeoutId);
  620. s.autoplaying = false;
  621. s.autoplayTimeoutId = undefined;
  622. s.emit('onAutoplayStop', s);
  623. };
  624. s.pauseAutoplay = function (speed) {
  625. if (s.autoplayPaused) return;
  626. if (s.autoplayTimeoutId) clearTimeout(s.autoplayTimeoutId);
  627. s.autoplayPaused = true;
  628. if (speed === 0) {
  629. s.autoplayPaused = false;
  630. autoplay();
  631. }
  632. else {
  633. s.wrapper.transitionEnd(function () {
  634. if (!s) return;
  635. s.autoplayPaused = false;
  636. if (!s.autoplaying) {
  637. s.stopAutoplay();
  638. }
  639. else {
  640. autoplay();
  641. }
  642. });
  643. }
  644. };
  645. /*=========================
  646. Min/Max Translate
  647. ===========================*/
  648. s.minTranslate = function () {
  649. return (-s.snapGrid[0]);
  650. };
  651. s.maxTranslate = function () {
  652. return (-s.snapGrid[s.snapGrid.length - 1]);
  653. };
  654. /*=========================
  655. Slider/slides sizes
  656. ===========================*/
  657. s.updateAutoHeight = function () {
  658. var activeSlides = [];
  659. var newHeight = 0;
  660. var i;
  661. // Find slides currently in view
  662. if(s.params.slidesPerView !== 'auto' && s.params.slidesPerView > 1) {
  663. for (i = 0; i < Math.ceil(s.params.slidesPerView); i++) {
  664. var index = s.activeIndex + i;
  665. if(index > s.slides.length) break;
  666. activeSlides.push(s.slides.eq(index)[0]);
  667. }
  668. } else {
  669. activeSlides.push(s.slides.eq(s.activeIndex)[0]);
  670. }
  671. // Find new height from heighest slide in view
  672. for (i = 0; i < activeSlides.length; i++) {
  673. if (typeof activeSlides[i] !== 'undefined') {
  674. var height = activeSlides[i].offsetHeight;
  675. newHeight = height > newHeight ? height : newHeight;
  676. }
  677. }
  678. // Update Height
  679. if (newHeight) s.wrapper.css('height', newHeight + 'px');
  680. };
  681. s.updateContainerSize = function () {
  682. var width, height;
  683. if (typeof s.params.width !== 'undefined') {
  684. width = s.params.width;
  685. }
  686. else {
  687. width = s.container[0].clientWidth;
  688. }
  689. if (typeof s.params.height !== 'undefined') {
  690. height = s.params.height;
  691. }
  692. else {
  693. height = s.container[0].clientHeight;
  694. }
  695. if (width === 0 && s.isHorizontal() || height === 0 && !s.isHorizontal()) {
  696. return;
  697. }
  698. //Subtract paddings
  699. width = width - parseInt(s.container.css('padding-left'), 10) - parseInt(s.container.css('padding-right'), 10);
  700. height = height - parseInt(s.container.css('padding-top'), 10) - parseInt(s.container.css('padding-bottom'), 10);
  701. // Store values
  702. s.width = width;
  703. s.height = height;
  704. s.size = s.isHorizontal() ? s.width : s.height;
  705. };
  706. s.updateSlidesSize = function () {
  707. s.slides = s.wrapper.children('.' + s.params.slideClass);
  708. s.snapGrid = [];
  709. s.slidesGrid = [];
  710. s.slidesSizesGrid = [];
  711. var spaceBetween = s.params.spaceBetween,
  712. slidePosition = -s.params.slidesOffsetBefore,
  713. i,
  714. prevSlideSize = 0,
  715. index = 0;
  716. if (typeof s.size === 'undefined') return;
  717. if (typeof spaceBetween === 'string' && spaceBetween.indexOf('%') >= 0) {
  718. spaceBetween = parseFloat(spaceBetween.replace('%', '')) / 100 * s.size;
  719. }
  720. s.virtualSize = -spaceBetween;
  721. // reset margins
  722. if (s.rtl) s.slides.css({marginLeft: '', marginTop: ''});
  723. else s.slides.css({marginRight: '', marginBottom: ''});
  724. var slidesNumberEvenToRows;
  725. if (s.params.slidesPerColumn > 1) {
  726. if (Math.floor(s.slides.length / s.params.slidesPerColumn) === s.slides.length / s.params.slidesPerColumn) {
  727. slidesNumberEvenToRows = s.slides.length;
  728. }
  729. else {
  730. slidesNumberEvenToRows = Math.ceil(s.slides.length / s.params.slidesPerColumn) * s.params.slidesPerColumn;
  731. }
  732. if (s.params.slidesPerView !== 'auto' && s.params.slidesPerColumnFill === 'row') {
  733. slidesNumberEvenToRows = Math.max(slidesNumberEvenToRows, s.params.slidesPerView * s.params.slidesPerColumn);
  734. }
  735. }
  736. // Calc slides
  737. var slideSize;
  738. var slidesPerColumn = s.params.slidesPerColumn;
  739. var slidesPerRow = slidesNumberEvenToRows / slidesPerColumn;
  740. var numFullColumns = slidesPerRow - (s.params.slidesPerColumn * slidesPerRow - s.slides.length);
  741. for (i = 0; i < s.slides.length; i++) {
  742. slideSize = 0;
  743. var slide = s.slides.eq(i);
  744. if (s.params.slidesPerColumn > 1) {
  745. // Set slides order
  746. var newSlideOrderIndex;
  747. var column, row;
  748. if (s.params.slidesPerColumnFill === 'column') {
  749. column = Math.floor(i / slidesPerColumn);
  750. row = i - column * slidesPerColumn;
  751. if (column > numFullColumns || (column === numFullColumns && row === slidesPerColumn-1)) {
  752. if (++row >= slidesPerColumn) {
  753. row = 0;
  754. column++;
  755. }
  756. }
  757. newSlideOrderIndex = column + row * slidesNumberEvenToRows / slidesPerColumn;
  758. slide
  759. .css({
  760. '-webkit-box-ordinal-group': newSlideOrderIndex,
  761. '-moz-box-ordinal-group': newSlideOrderIndex,
  762. '-ms-flex-order': newSlideOrderIndex,
  763. '-webkit-order': newSlideOrderIndex,
  764. 'order': newSlideOrderIndex
  765. });
  766. }
  767. else {
  768. row = Math.floor(i / slidesPerRow);
  769. column = i - row * slidesPerRow;
  770. }
  771. slide
  772. .css(
  773. 'margin-' + (s.isHorizontal() ? 'top' : 'left'),
  774. (row !== 0 && s.params.spaceBetween) && (s.params.spaceBetween + 'px')
  775. )
  776. .attr('data-swiper-column', column)
  777. .attr('data-swiper-row', row);
  778. }
  779. if (slide.css('display') === 'none') continue;
  780. if (s.params.slidesPerView === 'auto') {
  781. slideSize = s.isHorizontal() ? slide.outerWidth(true) : slide.outerHeight(true);
  782. if (s.params.roundLengths) slideSize = round(slideSize);
  783. }
  784. else {
  785. slideSize = (s.size - (s.params.slidesPerView - 1) * spaceBetween) / s.params.slidesPerView;
  786. if (s.params.roundLengths) slideSize = round(slideSize);
  787. if (s.isHorizontal()) {
  788. s.slides[i].style.width = slideSize + 'px';
  789. }
  790. else {
  791. s.slides[i].style.height = slideSize + 'px';
  792. }
  793. }
  794. s.slides[i].swiperSlideSize = slideSize;
  795. s.slidesSizesGrid.push(slideSize);
  796. if (s.params.centeredSlides) {
  797. slidePosition = slidePosition + slideSize / 2 + prevSlideSize / 2 + spaceBetween;
  798. if (i === 0) slidePosition = slidePosition - s.size / 2 - spaceBetween;
  799. if (Math.abs(slidePosition) < 1 / 1000) slidePosition = 0;
  800. if ((index) % s.params.slidesPerGroup === 0) s.snapGrid.push(slidePosition);
  801. s.slidesGrid.push(slidePosition);
  802. }
  803. else {
  804. if ((index) % s.params.slidesPerGroup === 0) s.snapGrid.push(slidePosition);
  805. s.slidesGrid.push(slidePosition);
  806. slidePosition = slidePosition + slideSize + spaceBetween;
  807. }
  808. s.virtualSize += slideSize + spaceBetween;
  809. prevSlideSize = slideSize;
  810. index ++;
  811. }
  812. s.virtualSize = Math.max(s.virtualSize, s.size) + s.params.slidesOffsetAfter;
  813. var newSlidesGrid;
  814. if (
  815. s.rtl && s.wrongRTL && (s.params.effect === 'slide' || s.params.effect === 'coverflow')) {
  816. s.wrapper.css({width: s.virtualSize + s.params.spaceBetween + 'px'});
  817. }
  818. if (!s.support.flexbox || s.params.setWrapperSize) {
  819. if (s.isHorizontal()) s.wrapper.css({width: s.virtualSize + s.params.spaceBetween + 'px'});
  820. else s.wrapper.css({height: s.virtualSize + s.params.spaceBetween + 'px'});
  821. }
  822. if (s.params.slidesPerColumn > 1) {
  823. s.virtualSize = (slideSize + s.params.spaceBetween) * slidesNumberEvenToRows;
  824. s.virtualSize = Math.ceil(s.virtualSize / s.params.slidesPerColumn) - s.params.spaceBetween;
  825. if (s.isHorizontal()) s.wrapper.css({width: s.virtualSize + s.params.spaceBetween + 'px'});
  826. else s.wrapper.css({height: s.virtualSize + s.params.spaceBetween + 'px'});
  827. if (s.params.centeredSlides) {
  828. newSlidesGrid = [];
  829. for (i = 0; i < s.snapGrid.length; i++) {
  830. if (s.snapGrid[i] < s.virtualSize + s.snapGrid[0]) newSlidesGrid.push(s.snapGrid[i]);
  831. }
  832. s.snapGrid = newSlidesGrid;
  833. }
  834. }
  835. // Remove last grid elements depending on width
  836. if (!s.params.centeredSlides) {
  837. newSlidesGrid = [];
  838. for (i = 0; i < s.snapGrid.length; i++) {
  839. if (s.snapGrid[i] <= s.virtualSize - s.size) {
  840. newSlidesGrid.push(s.snapGrid[i]);
  841. }
  842. }
  843. s.snapGrid = newSlidesGrid;
  844. if (Math.floor(s.virtualSize - s.size) - Math.floor(s.snapGrid[s.snapGrid.length - 1]) > 1) {
  845. s.snapGrid.push(s.virtualSize - s.size);
  846. }
  847. }
  848. if (s.snapGrid.length === 0) s.snapGrid = [0];
  849. if (s.params.spaceBetween !== 0) {
  850. if (s.isHorizontal()) {
  851. if (s.rtl) s.slides.css({marginLeft: spaceBetween + 'px'});
  852. else s.slides.css({marginRight: spaceBetween + 'px'});
  853. }
  854. else s.slides.css({marginBottom: spaceBetween + 'px'});
  855. }
  856. if (s.params.watchSlidesProgress) {
  857. s.updateSlidesOffset();
  858. }
  859. };
  860. s.updateSlidesOffset = function () {
  861. for (var i = 0; i < s.slides.length; i++) {
  862. s.slides[i].swiperSlideOffset = s.isHorizontal() ? s.slides[i].offsetLeft : s.slides[i].offsetTop;
  863. }
  864. };
  865. /*=========================
  866. Dynamic Slides Per View
  867. ===========================*/
  868. s.currentSlidesPerView = function () {
  869. var spv = 1, i, j;
  870. if (s.params.centeredSlides) {
  871. var size = s.slides[s.activeIndex].swiperSlideSize;
  872. var breakLoop;
  873. for (i = s.activeIndex + 1; i < s.slides.length; i++) {
  874. if (s.slides[i] && !breakLoop) {
  875. size += s.slides[i].swiperSlideSize;
  876. spv ++;
  877. if (size > s.size) breakLoop = true;
  878. }
  879. }
  880. for (j = s.activeIndex - 1; j >= 0; j--) {
  881. if (s.slides[j] && !breakLoop) {
  882. size += s.slides[j].swiperSlideSize;
  883. spv ++;
  884. if (size > s.size) breakLoop = true;
  885. }
  886. }
  887. }
  888. else {
  889. for (i = s.activeIndex + 1; i < s.slides.length; i++) {
  890. if (s.slidesGrid[i] - s.slidesGrid[s.activeIndex] < s.size) {
  891. spv++;
  892. }
  893. }
  894. }
  895. return spv;
  896. };
  897. /*=========================
  898. Slider/slides progress
  899. ===========================*/
  900. s.updateSlidesProgress = function (translate) {
  901. if (typeof translate === 'undefined') {
  902. translate = s.translate || 0;
  903. }
  904. if (s.slides.length === 0) return;
  905. if (typeof s.slides[0].swiperSlideOffset === 'undefined') s.updateSlidesOffset();
  906. var offsetCenter = -translate;
  907. if (s.rtl) offsetCenter = translate;
  908. // Visible Slides
  909. s.slides.removeClass(s.params.slideVisibleClass);
  910. for (var i = 0; i < s.slides.length; i++) {
  911. var slide = s.slides[i];
  912. var slideProgress = (offsetCenter + (s.params.centeredSlides ? s.minTranslate() : 0) - slide.swiperSlideOffset) / (slide.swiperSlideSize + s.params.spaceBetween);
  913. if (s.params.watchSlidesVisibility) {
  914. var slideBefore = -(offsetCenter - slide.swiperSlideOffset);
  915. var slideAfter = slideBefore + s.slidesSizesGrid[i];
  916. var isVisible =
  917. (slideBefore >= 0 && slideBefore < s.size) ||
  918. (slideAfter > 0 && slideAfter <= s.size) ||
  919. (slideBefore <= 0 && slideAfter >= s.size);
  920. if (isVisible) {
  921. s.slides.eq(i).addClass(s.params.slideVisibleClass);
  922. }
  923. }
  924. slide.progress = s.rtl ? -slideProgress : slideProgress;
  925. }
  926. };
  927. s.updateProgress = function (translate) {
  928. if (typeof translate === 'undefined') {
  929. translate = s.translate || 0;
  930. }
  931. var translatesDiff = s.maxTranslate() - s.minTranslate();
  932. var wasBeginning = s.isBeginning;
  933. var wasEnd = s.isEnd;
  934. if (translatesDiff === 0) {
  935. s.progress = 0;
  936. s.isBeginning = s.isEnd = true;
  937. }
  938. else {
  939. s.progress = (translate - s.minTranslate()) / (translatesDiff);
  940. s.isBeginning = s.progress <= 0;
  941. s.isEnd = s.progress >= 1;
  942. }
  943. if (s.isBeginning && !wasBeginning) s.emit('onReachBeginning', s);
  944. if (s.isEnd && !wasEnd) s.emit('onReachEnd', s);
  945. if (s.params.watchSlidesProgress) s.updateSlidesProgress(translate);
  946. s.emit('onProgress', s, s.progress);
  947. };
  948. s.updateActiveIndex = function () {
  949. var translate = s.rtl ? s.translate : -s.translate;
  950. var newActiveIndex, i, snapIndex;
  951. for (i = 0; i < s.slidesGrid.length; i ++) {
  952. if (typeof s.slidesGrid[i + 1] !== 'undefined') {
  953. if (translate >= s.slidesGrid[i] && translate < s.slidesGrid[i + 1] - (s.slidesGrid[i + 1] - s.slidesGrid[i]) / 2) {
  954. newActiveIndex = i;
  955. }
  956. else if (translate >= s.slidesGrid[i] && translate < s.slidesGrid[i + 1]) {
  957. newActiveIndex = i + 1;
  958. }
  959. }
  960. else {
  961. if (translate >= s.slidesGrid[i]) {
  962. newActiveIndex = i;
  963. }
  964. }
  965. }
  966. // Normalize slideIndex
  967. if(s.params.normalizeSlideIndex){
  968. if (newActiveIndex < 0 || typeof newActiveIndex === 'undefined') newActiveIndex = 0;
  969. }
  970. // for (i = 0; i < s.slidesGrid.length; i++) {
  971. // if (- translate >= s.slidesGrid[i]) {
  972. // newActiveIndex = i;
  973. // }
  974. // }
  975. snapIndex = Math.floor(newActiveIndex / s.params.slidesPerGroup);
  976. if (snapIndex >= s.snapGrid.length) snapIndex = s.snapGrid.length - 1;
  977. if (newActiveIndex === s.activeIndex) {
  978. return;
  979. }
  980. s.snapIndex = snapIndex;
  981. s.previousIndex = s.activeIndex;
  982. s.activeIndex = newActiveIndex;
  983. s.updateClasses();
  984. s.updateRealIndex();
  985. };
  986. s.updateRealIndex = function(){
  987. s.realIndex = parseInt(s.slides.eq(s.activeIndex).attr('data-swiper-slide-index') || s.activeIndex, 10);
  988. };
  989. /*=========================
  990. Classes
  991. ===========================*/
  992. s.updateClasses = function () {
  993. s.slides.removeClass(s.params.slideActiveClass + ' ' + s.params.slideNextClass + ' ' + s.params.slidePrevClass + ' ' + s.params.slideDuplicateActiveClass + ' ' + s.params.slideDuplicateNextClass + ' ' + s.params.slideDuplicatePrevClass);
  994. var activeSlide = s.slides.eq(s.activeIndex);
  995. // Active classes
  996. activeSlide.addClass(s.params.slideActiveClass);
  997. if (params.loop) {
  998. // Duplicate to all looped slides
  999. if (activeSlide.hasClass(s.params.slideDuplicateClass)) {
  1000. s.wrapper.children('.' + s.params.slideClass + ':not(.' + s.params.slideDuplicateClass + ')[data-swiper-slide-index="' + s.realIndex + '"]').addClass(s.params.slideDuplicateActiveClass);
  1001. }
  1002. else {
  1003. s.wrapper.children('.' + s.params.slideClass + '.' + s.params.slideDuplicateClass + '[data-swiper-slide-index="' + s.realIndex + '"]').addClass(s.params.slideDuplicateActiveClass);
  1004. }
  1005. }
  1006. // Next Slide
  1007. var nextSlide = activeSlide.next('.' + s.params.slideClass).addClass(s.params.slideNextClass);
  1008. if (s.params.loop && nextSlide.length === 0) {
  1009. nextSlide = s.slides.eq(0);
  1010. nextSlide.addClass(s.params.slideNextClass);
  1011. }
  1012. // Prev Slide
  1013. var prevSlide = activeSlide.prev('.' + s.params.slideClass).addClass(s.params.slidePrevClass);
  1014. if (s.params.loop && prevSlide.length === 0) {
  1015. prevSlide = s.slides.eq(-1);
  1016. prevSlide.addClass(s.params.slidePrevClass);
  1017. }
  1018. if (params.loop) {
  1019. // Duplicate to all looped slides
  1020. if (nextSlide.hasClass(s.params.slideDuplicateClass)) {
  1021. s.wrapper.children('.' + s.params.slideClass + ':not(.' + s.params.slideDuplicateClass + ')[data-swiper-slide-index="' + nextSlide.attr('data-swiper-slide-index') + '"]').addClass(s.params.slideDuplicateNextClass);
  1022. }
  1023. else {
  1024. s.wrapper.children('.' + s.params.slideClass + '.' + s.params.slideDuplicateClass + '[data-swiper-slide-index="' + nextSlide.attr('data-swiper-slide-index') + '"]').addClass(s.params.slideDuplicateNextClass);
  1025. }
  1026. if (prevSlide.hasClass(s.params.slideDuplicateClass)) {
  1027. s.wrapper.children('.' + s.params.slideClass + ':not(.' + s.params.slideDuplicateClass + ')[data-swiper-slide-index="' + prevSlide.attr('data-swiper-slide-index') + '"]').addClass(s.params.slideDuplicatePrevClass);
  1028. }
  1029. else {
  1030. s.wrapper.children('.' + s.params.slideClass + '.' + s.params.slideDuplicateClass + '[data-swiper-slide-index="' + prevSlide.attr('data-swiper-slide-index') + '"]').addClass(s.params.slideDuplicatePrevClass);
  1031. }
  1032. }
  1033. // Pagination
  1034. if (s.paginationContainer && s.paginationContainer.length > 0) {
  1035. // Current/Total
  1036. var current,
  1037. total = s.params.loop ? Math.ceil((s.slides.length - s.loopedSlides * 2) / s.params.slidesPerGroup) : s.snapGrid.length;
  1038. if (s.params.loop) {
  1039. current = Math.ceil((s.activeIndex - s.loopedSlides)/s.params.slidesPerGroup);
  1040. if (current > s.slides.length - 1 - s.loopedSlides * 2) {
  1041. current = current - (s.slides.length - s.loopedSlides * 2);
  1042. }
  1043. if (current > total - 1) current = current - total;
  1044. if (current < 0 && s.params.paginationType !== 'bullets') current = total + current;
  1045. }
  1046. else {
  1047. if (typeof s.snapIndex !== 'undefined') {
  1048. current = s.snapIndex;
  1049. }
  1050. else {
  1051. current = s.activeIndex || 0;
  1052. }
  1053. }
  1054. // Types
  1055. if (s.params.paginationType === 'bullets' && s.bullets && s.bullets.length > 0) {
  1056. s.bullets.removeClass(s.params.bulletActiveClass);
  1057. if (s.paginationContainer.length > 1) {
  1058. s.bullets.each(function () {
  1059. if ($(this).index() === current) $(this).addClass(s.params.bulletActiveClass);
  1060. });
  1061. }
  1062. else {
  1063. s.bullets.eq(current).addClass(s.params.bulletActiveClass);
  1064. }
  1065. }
  1066. if (s.params.paginationType === 'fraction') {
  1067. s.paginationContainer.find('.' + s.params.paginationCurrentClass).text(current + 1);
  1068. s.paginationContainer.find('.' + s.params.paginationTotalClass).text(total);
  1069. }
  1070. if (s.params.paginationType === 'progress') {
  1071. var scale = (current + 1) / total,
  1072. scaleX = scale,
  1073. scaleY = 1;
  1074. if (!s.isHorizontal()) {
  1075. scaleY = scale;
  1076. scaleX = 1;
  1077. }
  1078. s.paginationContainer.find('.' + s.params.paginationProgressbarClass).transform('translate3d(0,0,0) scaleX(' + scaleX + ') scaleY(' + scaleY + ')').transition(s.params.speed);
  1079. }
  1080. if (s.params.paginationType === 'custom' && s.params.paginationCustomRender) {
  1081. s.paginationContainer.html(s.params.paginationCustomRender(s, current + 1, total));
  1082. s.emit('onPaginationRendered', s, s.paginationContainer[0]);
  1083. }
  1084. }
  1085. // Next/active buttons
  1086. if (!s.params.loop) {
  1087. if (s.params.prevButton && s.prevButton && s.prevButton.length > 0) {
  1088. if (s.isBeginning) {
  1089. s.prevButton.addClass(s.params.buttonDisabledClass);
  1090. if (s.params.a11y && s.a11y) s.a11y.disable(s.prevButton);
  1091. }
  1092. else {
  1093. s.prevButton.removeClass(s.params.buttonDisabledClass);
  1094. if (s.params.a11y && s.a11y) s.a11y.enable(s.prevButton);
  1095. }
  1096. }
  1097. if (s.params.nextButton && s.nextButton && s.nextButton.length > 0) {
  1098. if (s.isEnd) {
  1099. s.nextButton.addClass(s.params.buttonDisabledClass);
  1100. if (s.params.a11y && s.a11y) s.a11y.disable(s.nextButton);
  1101. }
  1102. else {
  1103. s.nextButton.removeClass(s.params.buttonDisabledClass);
  1104. if (s.params.a11y && s.a11y) s.a11y.enable(s.nextButton);
  1105. }
  1106. }
  1107. }
  1108. };
  1109. /*=========================
  1110. Pagination
  1111. ===========================*/
  1112. s.updatePagination = function () {
  1113. if (!s.params.pagination) return;
  1114. if (s.paginationContainer && s.paginationContainer.length > 0) {
  1115. var paginationHTML = '';
  1116. if (s.params.paginationType === 'bullets') {
  1117. var numberOfBullets = s.params.loop ? Math.ceil((s.slides.length - s.loopedSlides * 2) / s.params.slidesPerGroup) : s.snapGrid.length;
  1118. for (var i = 0; i < numberOfBullets; i++) {
  1119. if (s.params.paginationBulletRender) {
  1120. paginationHTML += s.params.paginationBulletRender(s, i, s.params.bulletClass);
  1121. }
  1122. else {
  1123. paginationHTML += '<' + s.params.paginationElement+' class="' + s.params.bulletClass + '"></' + s.params.paginationElement + '>';
  1124. }
  1125. }
  1126. s.paginationContainer.html(paginationHTML);
  1127. s.bullets = s.paginationContainer.find('.' + s.params.bulletClass);
  1128. if (s.params.paginationClickable && s.params.a11y && s.a11y) {
  1129. s.a11y.initPagination();
  1130. }
  1131. }
  1132. if (s.params.paginationType === 'fraction') {
  1133. if (s.params.paginationFractionRender) {
  1134. paginationHTML = s.params.paginationFractionRender(s, s.params.paginationCurrentClass, s.params.paginationTotalClass);
  1135. }
  1136. else {
  1137. paginationHTML =
  1138. '<span class="' + s.params.paginationCurrentClass + '"></span>' +
  1139. ' / ' +
  1140. '<span class="' + s.params.paginationTotalClass+'"></span>';
  1141. }
  1142. s.paginationContainer.html(paginationHTML);
  1143. }
  1144. if (s.params.paginationType === 'progress') {
  1145. if (s.params.paginationProgressRender) {
  1146. paginationHTML = s.params.paginationProgressRender(s, s.params.paginationProgressbarClass);
  1147. }
  1148. else {
  1149. paginationHTML = '<span class="' + s.params.paginationProgressbarClass + '"></span>';
  1150. }
  1151. s.paginationContainer.html(paginationHTML);
  1152. }
  1153. if (s.params.paginationType !== 'custom') {
  1154. s.emit('onPaginationRendered', s, s.paginationContainer[0]);
  1155. }
  1156. }
  1157. };
  1158. /*=========================
  1159. Common update method
  1160. ===========================*/
  1161. s.update = function (updateTranslate) {
  1162. if (!s) return;
  1163. s.updateContainerSize();
  1164. s.updateSlidesSize();
  1165. s.updateProgress();
  1166. s.updatePagination();
  1167. s.updateClasses();
  1168. if (s.params.scrollbar && s.scrollbar) {
  1169. s.scrollbar.set();
  1170. }
  1171. function forceSetTranslate() {
  1172. var translate = s.rtl ? -s.translate : s.translate;
  1173. newTranslate = Math.min(Math.max(s.translate, s.maxTranslate()), s.minTranslate());
  1174. s.setWrapperTranslate(newTranslate);
  1175. s.updateActiveIndex();
  1176. s.updateClasses();
  1177. }
  1178. if (updateTranslate) {
  1179. var translated, newTranslate;
  1180. if (s.controller && s.controller.spline) {
  1181. s.controller.spline = undefined;
  1182. }
  1183. if (s.params.freeMode) {
  1184. forceSetTranslate();
  1185. if (s.params.autoHeight) {
  1186. s.updateAutoHeight();
  1187. }
  1188. }
  1189. else {
  1190. if ((s.params.slidesPerView === 'auto' || s.params.slidesPerView > 1) && s.isEnd && !s.params.centeredSlides) {
  1191. translated = s.slideTo(s.slides.length - 1, 0, false, true);
  1192. }
  1193. else {
  1194. translated = s.slideTo(s.activeIndex, 0, false, true);
  1195. }
  1196. if (!translated) {
  1197. forceSetTranslate();
  1198. }
  1199. }
  1200. }
  1201. else if (s.params.autoHeight) {
  1202. s.updateAutoHeight();
  1203. }
  1204. };
  1205. /*=========================
  1206. Resize Handler
  1207. ===========================*/
  1208. s.onResize = function (forceUpdatePagination) {
  1209. //Breakpoints
  1210. if (s.params.breakpoints) {
  1211. s.setBreakpoint();
  1212. }
  1213. // Disable locks on resize
  1214. var allowSwipeToPrev = s.params.allowSwipeToPrev;
  1215. var allowSwipeToNext = s.params.allowSwipeToNext;
  1216. s.params.allowSwipeToPrev = s.params.allowSwipeToNext = true;
  1217. s.updateContainerSize();
  1218. s.updateSlidesSize();
  1219. if (s.params.slidesPerView === 'auto' || s.params.freeMode || forceUpdatePagination) s.updatePagination();
  1220. if (s.params.scrollbar && s.scrollbar) {
  1221. s.scrollbar.set();
  1222. }
  1223. if (s.controller && s.controller.spline) {
  1224. s.controller.spline = undefined;
  1225. }
  1226. var slideChangedBySlideTo = false;
  1227. if (s.params.freeMode) {
  1228. var newTranslate = Math.min(Math.max(s.translate, s.maxTranslate()), s.minTranslate());
  1229. s.setWrapperTranslate(newTranslate);
  1230. s.updateActiveIndex();
  1231. s.updateClasses();
  1232. if (s.params.autoHeight) {
  1233. s.updateAutoHeight();
  1234. }
  1235. }
  1236. else {
  1237. s.updateClasses();
  1238. if ((s.params.slidesPerView === 'auto' || s.params.slidesPerView > 1) && s.isEnd && !s.params.centeredSlides) {
  1239. slideChangedBySlideTo = s.slideTo(s.slides.length - 1, 0, false, true);
  1240. }
  1241. else {
  1242. slideChangedBySlideTo = s.slideTo(s.activeIndex, 0, false, true);
  1243. }
  1244. }
  1245. if (s.params.lazyLoading && !slideChangedBySlideTo && s.lazy) {
  1246. s.lazy.load();
  1247. }
  1248. // Return locks after resize
  1249. s.params.allowSwipeToPrev = allowSwipeToPrev;
  1250. s.params.allowSwipeToNext = allowSwipeToNext;
  1251. };
  1252. /*=========================
  1253. Events
  1254. ===========================*/
  1255. //Define Touch Events
  1256. s.touchEventsDesktop = {start: 'mousedown', move: 'mousemove', end: 'mouseup'};
  1257. if (window.navigator.pointerEnabled) s.touchEventsDesktop = {start: 'pointerdown', move: 'pointermove', end: 'pointerup'};
  1258. else if (window.navigator.msPointerEnabled) s.touchEventsDesktop = {start: 'MSPointerDown', move: 'MSPointerMove', end: 'MSPointerUp'};
  1259. s.touchEvents = {
  1260. start : s.support.touch || !s.params.simulateTouch ? 'touchstart' : s.touchEventsDesktop.start,
  1261. move : s.support.touch || !s.params.simulateTouch ? 'touchmove' : s.touchEventsDesktop.move,
  1262. end : s.support.touch || !s.params.simulateTouch ? 'touchend' : s.touchEventsDesktop.end
  1263. };
  1264. // WP8 Touch Events Fix
  1265. if (window.navigator.pointerEnabled || window.navigator.msPointerEnabled) {
  1266. (s.params.touchEventsTarget === 'container' ? s.container : s.wrapper).addClass('swiper-wp8-' + s.params.direction);
  1267. }
  1268. // Attach/detach events
  1269. s.initEvents = function (detach) {
  1270. var actionDom = detach ? 'off' : 'on';
  1271. var action = detach ? 'removeEventListener' : 'addEventListener';
  1272. var touchEventsTarget = s.params.touchEventsTarget === 'container' ? s.container[0] : s.wrapper[0];
  1273. var target = s.support.touch ? touchEventsTarget : document;
  1274. var moveCapture = s.params.nested ? true : false;
  1275. //Touch Events
  1276. if (s.browser.ie) {
  1277. touchEventsTarget[action](s.touchEvents.start, s.onTouchStart, false);
  1278. target[action](s.touchEvents.move, s.onTouchMove, moveCapture);
  1279. target[action](s.touchEvents.end, s.onTouchEnd, false);
  1280. }
  1281. else {
  1282. if (s.support.touch) {
  1283. var passiveListener = s.touchEvents.start === 'touchstart' && s.support.passiveListener && s.params.passiveListeners ? {passive: true, capture: false} : false;
  1284. touchEventsTarget[action](s.touchEvents.start, s.onTouchStart, passiveListener);
  1285. touchEventsTarget[action](s.touchEvents.move, s.onTouchMove, moveCapture);
  1286. touchEventsTarget[action](s.touchEvents.end, s.onTouchEnd, passiveListener);
  1287. }
  1288. if ((params.simulateTouch && !s.device.ios && !s.device.android) || (params.simulateTouch && !s.support.touch && s.device.ios)) {
  1289. touchEventsTarget[action]('mousedown', s.onTouchStart, false);
  1290. document[action]('mousemove', s.onTouchMove, moveCapture);
  1291. document[action]('mouseup', s.onTouchEnd, false);
  1292. }
  1293. }
  1294. window[action]('resize', s.onResize);
  1295. // Next, Prev, Index
  1296. if (s.params.nextButton && s.nextButton && s.nextButton.length > 0) {
  1297. s.nextButton[actionDom]('click', s.onClickNext);
  1298. if (s.params.a11y && s.a11y) s.nextButton[actionDom]('keydown', s.a11y.onEnterKey);
  1299. }
  1300. if (s.params.prevButton && s.prevButton && s.prevButton.length > 0) {
  1301. s.prevButton[actionDom]('click', s.onClickPrev);
  1302. if (s.params.a11y && s.a11y) s.prevButton[actionDom]('keydown', s.a11y.onEnterKey);
  1303. }
  1304. if (s.params.pagination && s.params.paginationClickable) {
  1305. s.paginationContainer[actionDom]('click', '.' + s.params.bulletClass, s.onClickIndex);
  1306. if (s.params.a11y && s.a11y) s.paginationContainer[actionDom]('keydown', '.' + s.params.bulletClass, s.a11y.onEnterKey);
  1307. }
  1308. // Prevent Links Clicks
  1309. if (s.params.preventClicks || s.params.preventClicksPropagation) touchEventsTarget[action]('click', s.preventClicks, true);
  1310. };
  1311. s.attachEvents = function () {
  1312. s.initEvents();
  1313. };
  1314. s.detachEvents = function () {
  1315. s.initEvents(true);
  1316. };
  1317. /*=========================
  1318. Handle Clicks
  1319. ===========================*/
  1320. // Prevent Clicks
  1321. s.allowClick = true;
  1322. s.preventClicks = function (e) {
  1323. if (!s.allowClick) {
  1324. if (s.params.preventClicks) e.preventDefault();
  1325. if (s.params.preventClicksPropagation && s.animating) {
  1326. e.stopPropagation();
  1327. e.stopImmediatePropagation();
  1328. }
  1329. }
  1330. };
  1331. // Clicks
  1332. s.onClickNext = function (e) {
  1333. e.preventDefault();
  1334. if (s.isEnd && !s.params.loop) return;
  1335. s.slideNext();
  1336. };
  1337. s.onClickPrev = function (e) {
  1338. e.preventDefault();
  1339. if (s.isBeginning && !s.params.loop) return;
  1340. s.slidePrev();
  1341. };
  1342. s.onClickIndex = function (e) {
  1343. e.preventDefault();
  1344. var index = $(this).index() * s.params.slidesPerGroup;
  1345. if (s.params.loop) index = index + s.loopedSlides;
  1346. s.slideTo(index);
  1347. };
  1348. /*=========================
  1349. Handle Touches
  1350. ===========================*/
  1351. function findElementInEvent(e, selector) {
  1352. var el = $(e.target);
  1353. if (!el.is(selector)) {
  1354. if (typeof selector === 'string') {
  1355. el = el.parents(selector);
  1356. }
  1357. else if (selector.nodeType) {
  1358. var found;
  1359. el.parents().each(function (index, _el) {
  1360. if (_el === selector) found = selector;
  1361. });
  1362. if (!found) return undefined;
  1363. else return selector;
  1364. }
  1365. }
  1366. if (el.length === 0) {
  1367. return undefined;
  1368. }
  1369. return el[0];
  1370. }
  1371. s.updateClickedSlide = function (e) {
  1372. var slide = findElementInEvent(e, '.' + s.params.slideClass);
  1373. var slideFound = false;
  1374. if (slide) {
  1375. for (var i = 0; i < s.slides.length; i++) {
  1376. if (s.slides[i] === slide) slideFound = true;
  1377. }
  1378. }
  1379. if (slide && slideFound) {
  1380. s.clickedSlide = slide;
  1381. s.clickedIndex = $(slide).index();
  1382. }
  1383. else {
  1384. s.clickedSlide = undefined;
  1385. s.clickedIndex = undefined;
  1386. return;
  1387. }
  1388. if (s.params.slideToClickedSlide && s.clickedIndex !== undefined && s.clickedIndex !== s.activeIndex) {
  1389. var slideToIndex = s.clickedIndex,
  1390. realIndex,
  1391. duplicatedSlides,
  1392. slidesPerView = s.params.slidesPerView === 'auto' ? s.currentSlidesPerView() : s.params.slidesPerView;
  1393. if (s.params.loop) {
  1394. if (s.animating) return;
  1395. realIndex = parseInt($(s.clickedSlide).attr('data-swiper-slide-index'), 10);
  1396. if (s.params.centeredSlides) {
  1397. if ((slideToIndex < s.loopedSlides - slidesPerView/2) || (slideToIndex > s.slides.length - s.loopedSlides + slidesPerView/2)) {
  1398. s.fixLoop();
  1399. slideToIndex = s.wrapper.children('.' + s.params.slideClass + '[data-swiper-slide-index="' + realIndex + '"]:not(.' + s.params.slideDuplicateClass + ')').eq(0).index();
  1400. setTimeout(function () {
  1401. s.slideTo(slideToIndex);
  1402. }, 0);
  1403. }
  1404. else {
  1405. s.slideTo(slideToIndex);
  1406. }
  1407. }
  1408. else {
  1409. if (slideToIndex > s.slides.length - slidesPerView) {
  1410. s.fixLoop();
  1411. slideToIndex = s.wrapper.children('.' + s.params.slideClass + '[data-swiper-slide-index="' + realIndex + '"]:not(.' + s.params.slideDuplicateClass + ')').eq(0).index();
  1412. setTimeout(function () {
  1413. s.slideTo(slideToIndex);
  1414. }, 0);
  1415. }
  1416. else {
  1417. s.slideTo(slideToIndex);
  1418. }
  1419. }
  1420. }
  1421. else {
  1422. s.slideTo(slideToIndex);
  1423. }
  1424. }
  1425. };
  1426. var isTouched,
  1427. isMoved,
  1428. allowTouchCallbacks,
  1429. touchStartTime,
  1430. isScrolling,
  1431. currentTranslate,
  1432. startTranslate,
  1433. allowThresholdMove,
  1434. // Form elements to match
  1435. formElements = 'input, select, textarea, button, video',
  1436. // Last click time
  1437. lastClickTime = Date.now(), clickTimeout,
  1438. //Velocities
  1439. velocities = [],
  1440. allowMomentumBounce;
  1441. // Animating Flag
  1442. s.animating = false;
  1443. // Touches information
  1444. s.touches = {
  1445. startX: 0,
  1446. startY: 0,
  1447. currentX: 0,
  1448. currentY: 0,
  1449. diff: 0
  1450. };
  1451. // Touch handlers
  1452. var isTouchEvent, startMoving;
  1453. s.onTouchStart = function (e) {
  1454. if (e.originalEvent) e = e.originalEvent;
  1455. isTouchEvent = e.type === 'touchstart';
  1456. if (!isTouchEvent && 'which' in e && e.which === 3) return;
  1457. if (s.params.noSwiping && findElementInEvent(e, '.' + s.params.noSwipingClass)) {
  1458. s.allowClick = true;
  1459. return;
  1460. }
  1461. if (s.params.swipeHandler) {
  1462. if (!findElementInEvent(e, s.params.swipeHandler)) return;
  1463. }
  1464. var startX = s.touches.currentX = e.type === 'touchstart' ? e.targetTouches[0].pageX : e.pageX;
  1465. var startY = s.touches.currentY = e.type === 'touchstart' ? e.targetTouches[0].pageY : e.pageY;
  1466. // Do NOT start if iOS edge swipe is detected. Otherwise iOS app (UIWebView) cannot swipe-to-go-back anymore
  1467. if(s.device.ios && s.params.iOSEdgeSwipeDetection && startX <= s.params.iOSEdgeSwipeThreshold) {
  1468. return;
  1469. }
  1470. isTouched = true;
  1471. isMoved = false;
  1472. allowTouchCallbacks = true;
  1473. isScrolling = undefined;
  1474. startMoving = undefined;
  1475. s.touches.startX = startX;
  1476. s.touches.startY = startY;
  1477. touchStartTime = Date.now();
  1478. s.allowClick = true;
  1479. s.updateContainerSize();
  1480. s.swipeDirection = undefined;
  1481. if (s.params.threshold > 0) allowThresholdMove = false;
  1482. if (e.type !== 'touchstart') {
  1483. var preventDefault = true;
  1484. if ($(e.target).is(formElements)) preventDefault = false;
  1485. if (document.activeElement && $(document.activeElement).is(formElements)) {
  1486. document.activeElement.blur();
  1487. }
  1488. if (preventDefault) {
  1489. e.preventDefault();
  1490. }
  1491. }
  1492. s.emit('onTouchStart', s, e);
  1493. };
  1494. s.onTouchMove = function (e) {
  1495. if (e.originalEvent) e = e.originalEvent;
  1496. if (isTouchEvent && e.type === 'mousemove') return;
  1497. if (e.preventedByNestedSwiper) {
  1498. s.touches.startX = e.type === 'touchmove' ? e.targetTouches[0].pageX : e.pageX;
  1499. s.touches.startY = e.type === 'touchmove' ? e.targetTouches[0].pageY : e.pageY;
  1500. return;
  1501. }
  1502. if (s.params.onlyExternal) {
  1503. // isMoved = true;
  1504. s.allowClick = false;
  1505. if (isTouched) {
  1506. s.touches.startX = s.touches.currentX = e.type === 'touchmove' ? e.targetTouches[0].pageX : e.pageX;
  1507. s.touches.startY = s.touches.currentY = e.type === 'touchmove' ? e.targetTouches[0].pageY : e.pageY;
  1508. touchStartTime = Date.now();
  1509. }
  1510. return;
  1511. }
  1512. if (isTouchEvent && s.params.touchReleaseOnEdges && !s.params.loop) {
  1513. if (!s.isHorizontal()) {
  1514. // Vertical
  1515. if (
  1516. (s.touches.currentY < s.touches.startY && s.translate <= s.maxTranslate()) ||
  1517. (s.touches.currentY > s.touches.startY && s.translate >= s.minTranslate())
  1518. ) {
  1519. return;
  1520. }
  1521. }
  1522. else {
  1523. if (
  1524. (s.touches.currentX < s.touches.startX && s.translate <= s.maxTranslate()) ||
  1525. (s.touches.currentX > s.touches.startX && s.translate >= s.minTranslate())
  1526. ) {
  1527. return;
  1528. }
  1529. }
  1530. }
  1531. if (isTouchEvent && document.activeElement) {
  1532. if (e.target === document.activeElement && $(e.target).is(formElements)) {
  1533. isMoved = true;
  1534. s.allowClick = false;
  1535. return;
  1536. }
  1537. }
  1538. if (allowTouchCallbacks) {
  1539. s.emit('onTouchMove', s, e);
  1540. }
  1541. if (e.targetTouches && e.targetTouches.length > 1) return;
  1542. s.touches.currentX = e.type === 'touchmove' ? e.targetTouches[0].pageX : e.pageX;
  1543. s.touches.currentY = e.type === 'touchmove' ? e.targetTouches[0].pageY : e.pageY;
  1544. if (typeof isScrolling === 'undefined') {
  1545. var touchAngle;
  1546. if (s.isHorizontal() && s.touches.currentY === s.touches.startY || !s.isHorizontal() && s.touches.currentX === s.touches.startX) {
  1547. isScrolling = false;
  1548. }
  1549. else {
  1550. touchAngle = Math.atan2(Math.abs(s.touches.currentY - s.touches.startY), Math.abs(s.touches.currentX - s.touches.startX)) * 180 / Math.PI;
  1551. isScrolling = s.isHorizontal() ? touchAngle > s.params.touchAngle : (90 - touchAngle > s.params.touchAngle);
  1552. }
  1553. }
  1554. if (isScrolling) {
  1555. s.emit('onTouchMoveOpposite', s, e);
  1556. }
  1557. if (typeof startMoving === 'undefined' && s.browser.ieTouch) {
  1558. if (s.touches.currentX !== s.touches.startX || s.touches.currentY !== s.touches.startY) {
  1559. startMoving = true;
  1560. }
  1561. }
  1562. if (!isTouched) return;
  1563. if (isScrolling) {
  1564. isTouched = false;
  1565. return;
  1566. }
  1567. if (!startMoving && s.browser.ieTouch) {
  1568. return;
  1569. }
  1570. s.allowClick = false;
  1571. s.emit('onSliderMove', s, e);
  1572. e.preventDefault();
  1573. if (s.params.touchMoveStopPropagation && !s.params.nested) {
  1574. e.stopPropagation();
  1575. }
  1576. if (!isMoved) {
  1577. if (params.loop) {
  1578. s.fixLoop();
  1579. }
  1580. startTranslate = s.getWrapperTranslate();
  1581. s.setWrapperTransition(0);
  1582. if (s.animating) {
  1583. s.wrapper.trigger('webkitTransitionEnd transitionend oTransitionEnd MSTransitionEnd msTransitionEnd');
  1584. }
  1585. if (s.params.autoplay && s.autoplaying) {
  1586. if (s.params.autoplayDisableOnInteraction) {
  1587. s.stopAutoplay();
  1588. }
  1589. else {
  1590. s.pauseAutoplay();
  1591. }
  1592. }
  1593. allowMomentumBounce = false;
  1594. //Grab Cursor
  1595. if (s.params.grabCursor && (s.params.allowSwipeToNext === true || s.params.allowSwipeToPrev === true)) {
  1596. s.setGrabCursor(true);
  1597. }
  1598. }
  1599. isMoved = true;
  1600. var diff = s.touches.diff = s.isHorizontal() ? s.touches.currentX - s.touches.startX : s.touches.currentY - s.touches.startY;
  1601. diff = diff * s.params.touchRatio;
  1602. if (s.rtl) diff = -diff;
  1603. s.swipeDirection = diff > 0 ? 'prev' : 'next';
  1604. currentTranslate = diff + startTranslate;
  1605. var disableParentSwiper = true;
  1606. if ((diff > 0 && currentTranslate > s.minTranslate())) {
  1607. disableParentSwiper = false;
  1608. if (s.params.resistance) currentTranslate = s.minTranslate() - 1 + Math.pow(-s.minTranslate() + startTranslate + diff, s.params.resistanceRatio);
  1609. }
  1610. else if (diff < 0 && currentTranslate < s.maxTranslate()) {
  1611. disableParentSwiper = false;
  1612. if (s.params.resistance) currentTranslate = s.maxTranslate() + 1 - Math.pow(s.maxTranslate() - startTranslate - diff, s.params.resistanceRatio);
  1613. }
  1614. if (disableParentSwiper) {
  1615. e.preventedByNestedSwiper = true;
  1616. }
  1617. // Directions locks
  1618. if (!s.params.allowSwipeToNext && s.swipeDirection === 'next' && currentTranslate < startTranslate) {
  1619. currentTranslate = startTranslate;
  1620. }
  1621. if (!s.params.allowSwipeToPrev && s.swipeDirection === 'prev' && currentTranslate > startTranslate) {
  1622. currentTranslate = startTranslate;
  1623. }
  1624. // Threshold
  1625. if (s.params.threshold > 0) {
  1626. if (Math.abs(diff) > s.params.threshold || allowThresholdMove) {
  1627. if (!allowThresholdMove) {
  1628. allowThresholdMove = true;
  1629. s.touches.startX = s.touches.currentX;
  1630. s.touches.startY = s.touches.currentY;
  1631. currentTranslate = startTranslate;
  1632. s.touches.diff = s.isHorizontal() ? s.touches.currentX - s.touches.startX : s.touches.currentY - s.touches.startY;
  1633. return;
  1634. }
  1635. }
  1636. else {
  1637. currentTranslate = startTranslate;
  1638. return;
  1639. }
  1640. }
  1641. if (!s.params.followFinger) return;
  1642. // Update active index in free mode
  1643. if (s.params.freeMode || s.params.watchSlidesProgress) {
  1644. s.updateActiveIndex();
  1645. }
  1646. if (s.params.freeMode) {
  1647. //Velocity
  1648. if (velocities.length === 0) {
  1649. velocities.push({
  1650. position: s.touches[s.isHorizontal() ? 'startX' : 'startY'],
  1651. time: touchStartTime
  1652. });
  1653. }
  1654. velocities.push({
  1655. position: s.touches[s.isHorizontal() ? 'currentX' : 'currentY'],
  1656. time: (new window.Date()).getTime()
  1657. });
  1658. }
  1659. // Update progress
  1660. s.updateProgress(currentTranslate);
  1661. // Update translate
  1662. s.setWrapperTranslate(currentTranslate);
  1663. };
  1664. s.onTouchEnd = function (e) {
  1665. if (e.originalEvent) e = e.originalEvent;
  1666. if (allowTouchCallbacks) {
  1667. s.emit('onTouchEnd', s, e);
  1668. }
  1669. params._iscroll == undefined || params._iscroll._end(e);
  1670. allowTouchCallbacks = false;
  1671. if (!isTouched) return;
  1672. //Return Grab Cursor
  1673. if (s.params.grabCursor && isMoved && isTouched && (s.params.allowSwipeToNext === true || s.params.allowSwipeToPrev === true)) {
  1674. s.setGrabCursor(false);
  1675. }
  1676. // Time diff
  1677. var touchEndTime = Date.now();
  1678. var timeDiff = touchEndTime - touchStartTime;
  1679. // Tap, doubleTap, Click
  1680. if (s.allowClick) {
  1681. s.updateClickedSlide(e);
  1682. s.emit('onTap', s, e);
  1683. if (timeDiff < 300 && (touchEndTime - lastClickTime) > 300) {
  1684. if (clickTimeout) clearTimeout(clickTimeout);
  1685. clickTimeout = setTimeout(function () {
  1686. if (!s) return;
  1687. if (s.params.paginationHide && s.paginationContainer.length > 0 && !$(e.target).hasClass(s.params.bulletClass)) {
  1688. s.paginationContainer.toggleClass(s.params.paginationHiddenClass);
  1689. }
  1690. s.emit('onClick', s, e);
  1691. }, 300);
  1692. }
  1693. if (timeDiff < 300 && (touchEndTime - lastClickTime) < 300) {
  1694. if (clickTimeout) clearTimeout(clickTimeout);
  1695. s.emit('onDoubleTap', s, e);
  1696. }
  1697. }
  1698. lastClickTime = Date.now();
  1699. setTimeout(function () {
  1700. if (s) s.allowClick = true;
  1701. }, 0);
  1702. if (!isTouched || !isMoved || !s.swipeDirection || s.touches.diff === 0 || currentTranslate === startTranslate) {
  1703. isTouched = isMoved = false;
  1704. return;
  1705. }
  1706. isTouched = isMoved = false;
  1707. var currentPos;
  1708. if (s.params.followFinger) {
  1709. currentPos = s.rtl ? s.translate : -s.translate;
  1710. }
  1711. else {
  1712. currentPos = -currentTranslate;
  1713. }
  1714. if (s.params.freeMode) {
  1715. if (currentPos < -s.minTranslate()) {
  1716. s.slideTo(s.activeIndex);
  1717. return;
  1718. }
  1719. else if (currentPos > -s.maxTranslate()) {
  1720. if (s.slides.length < s.snapGrid.length) {
  1721. s.slideTo(s.snapGrid.length - 1);
  1722. }
  1723. else {
  1724. s.slideTo(s.slides.length - 1);
  1725. }
  1726. return;
  1727. }
  1728. if (s.params.freeModeMomentum) {
  1729. if (velocities.length > 1) {
  1730. var lastMoveEvent = velocities.pop(), velocityEvent = velocities.pop();
  1731. var distance = lastMoveEvent.position - velocityEvent.position;
  1732. var time = lastMoveEvent.time - velocityEvent.time;
  1733. s.velocity = distance / time;
  1734. s.velocity = s.velocity / 2;
  1735. if (Math.abs(s.velocity) < s.params.freeModeMinimumVelocity) {
  1736. s.velocity = 0;
  1737. }
  1738. // this implies that the user stopped moving a finger then released.
  1739. // There would be no events with distance zero, so the last event is stale.
  1740. if (time > 150 || (new window.Date().getTime() - lastMoveEvent.time) > 300) {
  1741. s.velocity = 0;
  1742. }
  1743. } else {
  1744. s.velocity = 0;
  1745. }
  1746. s.velocity = s.velocity * s.params.freeModeMomentumVelocityRatio;
  1747. velocities.length = 0;
  1748. var momentumDuration = 1000 * s.params.freeModeMomentumRatio;
  1749. var momentumDistance = s.velocity * momentumDuration;
  1750. var newPosition = s.translate + momentumDistance;
  1751. if (s.rtl) newPosition = - newPosition;
  1752. var doBounce = false;
  1753. var afterBouncePosition;
  1754. var bounceAmount = Math.abs(s.velocity) * 20 * s.params.freeModeMomentumBounceRatio;
  1755. if (newPosition < s.maxTranslate()) {
  1756. if (s.params.freeModeMomentumBounce) {
  1757. if (newPosition + s.maxTranslate() < -bounceAmount) {
  1758. newPosition = s.maxTranslate() - bounceAmount;
  1759. }
  1760. afterBouncePosition = s.maxTranslate();
  1761. doBounce = true;
  1762. allowMomentumBounce = true;
  1763. }
  1764. else {
  1765. newPosition = s.maxTranslate();
  1766. }
  1767. }
  1768. else if (newPosition > s.minTranslate()) {
  1769. if (s.params.freeModeMomentumBounce) {
  1770. if (newPosition - s.minTranslate() > bounceAmount) {
  1771. newPosition = s.minTranslate() + bounceAmount;
  1772. }
  1773. afterBouncePosition = s.minTranslate();
  1774. doBounce = true;
  1775. allowMomentumBounce = true;
  1776. }
  1777. else {
  1778. newPosition = s.minTranslate();
  1779. }
  1780. }
  1781. else if (s.params.freeModeSticky) {
  1782. var j = 0,
  1783. nextSlide;
  1784. for (j = 0; j < s.snapGrid.length; j += 1) {
  1785. if (s.snapGrid[j] > -newPosition) {
  1786. nextSlide = j;
  1787. break;
  1788. }
  1789. }
  1790. if (Math.abs(s.snapGrid[nextSlide] - newPosition) < Math.abs(s.snapGrid[nextSlide - 1] - newPosition) || s.swipeDirection === 'next') {
  1791. newPosition = s.snapGrid[nextSlide];
  1792. } else {
  1793. newPosition = s.snapGrid[nextSlide - 1];
  1794. }
  1795. if (!s.rtl) newPosition = - newPosition;
  1796. }
  1797. //Fix duration
  1798. if (s.velocity !== 0) {
  1799. if (s.rtl) {
  1800. momentumDuration = Math.abs((-newPosition - s.translate) / s.velocity);
  1801. }
  1802. else {
  1803. momentumDuration = Math.abs((newPosition - s.translate) / s.velocity);
  1804. }
  1805. }
  1806. else if (s.params.freeModeSticky) {
  1807. s.slideReset();
  1808. return;
  1809. }
  1810. if (s.params.freeModeMomentumBounce && doBounce) {
  1811. s.updateProgress(afterBouncePosition);
  1812. s.setWrapperTransition(momentumDuration);
  1813. s.setWrapperTranslate(newPosition);
  1814. s.onTransitionStart();
  1815. s.animating = true;
  1816. s.wrapper.transitionEnd(function () {
  1817. if (!s || !allowMomentumBounce) return;
  1818. s.emit('onMomentumBounce', s);
  1819. s.setWrapperTransition(s.params.speed);
  1820. s.setWrapperTranslate(afterBouncePosition);
  1821. s.wrapper.transitionEnd(function () {
  1822. if (!s) return;
  1823. s.onTransitionEnd();
  1824. });
  1825. });
  1826. } else if (s.velocity) {
  1827. s.updateProgress(newPosition);
  1828. s.setWrapperTransition(momentumDuration);
  1829. s.setWrapperTranslate(newPosition);
  1830. s.onTransitionStart();
  1831. if (!s.animating) {
  1832. s.animating = true;
  1833. s.wrapper.transitionEnd(function () {
  1834. if (!s) return;
  1835. s.onTransitionEnd();
  1836. });
  1837. }
  1838. } else {
  1839. s.updateProgress(newPosition);
  1840. }
  1841. s.updateActiveIndex();
  1842. }
  1843. if (!s.params.freeModeMomentum || timeDiff >= s.params.longSwipesMs) {
  1844. s.updateProgress();
  1845. s.updateActiveIndex();
  1846. }
  1847. return;
  1848. }
  1849. // Find current slide
  1850. var i, stopIndex = 0, groupSize = s.slidesSizesGrid[0];
  1851. for (i = 0; i < s.slidesGrid.length; i += s.params.slidesPerGroup) {
  1852. if (typeof s.slidesGrid[i + s.params.slidesPerGroup] !== 'undefined') {
  1853. if (currentPos >= s.slidesGrid[i] && currentPos < s.slidesGrid[i + s.params.slidesPerGroup]) {
  1854. stopIndex = i;
  1855. groupSize = s.slidesGrid[i + s.params.slidesPerGroup] - s.slidesGrid[i];
  1856. }
  1857. }
  1858. else {
  1859. if (currentPos >= s.slidesGrid[i]) {
  1860. stopIndex = i;
  1861. groupSize = s.slidesGrid[s.slidesGrid.length - 1] - s.slidesGrid[s.slidesGrid.length - 2];
  1862. }
  1863. }
  1864. }
  1865. // Find current slide size
  1866. var ratio = (currentPos - s.slidesGrid[stopIndex]) / groupSize;
  1867. if (timeDiff > s.params.longSwipesMs) {
  1868. // Long touches
  1869. if (!s.params.longSwipes) {
  1870. s.slideTo(s.activeIndex);
  1871. return;
  1872. }
  1873. if (s.swipeDirection === 'next') {
  1874. if (ratio >= s.params.longSwipesRatio) s.slideTo(stopIndex + s.params.slidesPerGroup);
  1875. else s.slideTo(stopIndex);
  1876. }
  1877. if (s.swipeDirection === 'prev') {
  1878. if (ratio > (1 - s.params.longSwipesRatio)) s.slideTo(stopIndex + s.params.slidesPerGroup);
  1879. else s.slideTo(stopIndex);
  1880. }
  1881. }
  1882. else {
  1883. // Short swipes
  1884. if (!s.params.shortSwipes) {
  1885. s.slideTo(s.activeIndex);
  1886. return;
  1887. }
  1888. if (s.swipeDirection === 'next') {
  1889. s.slideTo(stopIndex + s.params.slidesPerGroup);
  1890. }
  1891. if (s.swipeDirection === 'prev') {
  1892. s.slideTo(stopIndex);
  1893. }
  1894. }
  1895. };
  1896. /*=========================
  1897. Transitions
  1898. ===========================*/
  1899. s._slideTo = function (slideIndex, speed) {
  1900. return s.slideTo(slideIndex, speed, true, true);
  1901. };
  1902. s.slideTo = function (slideIndex, speed, runCallbacks, internal) {
  1903. if (typeof runCallbacks === 'undefined') runCallbacks = true;
  1904. if (typeof slideIndex === 'undefined') slideIndex = 0;
  1905. if (slideIndex < 0) slideIndex = 0;
  1906. s.snapIndex = Math.floor(slideIndex / s.params.slidesPerGroup);
  1907. if (s.snapIndex >= s.snapGrid.length) s.snapIndex = s.snapGrid.length - 1;
  1908. var translate = - s.snapGrid[s.snapIndex];
  1909. // Stop autoplay
  1910. if (s.params.autoplay && s.autoplaying) {
  1911. if (internal || !s.params.autoplayDisableOnInteraction) {
  1912. s.pauseAutoplay(speed);
  1913. }
  1914. else {
  1915. s.stopAutoplay();
  1916. }
  1917. }
  1918. // Update progress
  1919. s.updateProgress(translate);
  1920. // Normalize slideIndex
  1921. if(s.params.normalizeSlideIndex){
  1922. for (var i = 0; i < s.slidesGrid.length; i++) {
  1923. if (- Math.floor(translate * 100) >= Math.floor(s.slidesGrid[i] * 100)) {
  1924. slideIndex = i;
  1925. }
  1926. }
  1927. }
  1928. // Directions locks
  1929. if (!s.params.allowSwipeToNext && translate < s.translate && translate < s.minTranslate()) {
  1930. return false;
  1931. }
  1932. if (!s.params.allowSwipeToPrev && translate > s.translate && translate > s.maxTranslate()) {
  1933. if ((s.activeIndex || 0) !== slideIndex ) return false;
  1934. }
  1935. // Update Index
  1936. if (typeof speed === 'undefined') speed = s.params.speed;
  1937. s.previousIndex = s.activeIndex || 0;
  1938. s.activeIndex = slideIndex;
  1939. s.updateRealIndex();
  1940. if ((s.rtl && -translate === s.translate) || (!s.rtl && translate === s.translate)) {
  1941. // Update Height
  1942. if (s.params.autoHeight) {
  1943. s.updateAutoHeight();
  1944. }
  1945. s.updateClasses();
  1946. if (s.params.effect !== 'slide') {
  1947. s.setWrapperTranslate(translate);
  1948. }
  1949. return false;
  1950. }
  1951. s.updateClasses();
  1952. s.onTransitionStart(runCallbacks);
  1953. if (speed === 0 || s.browser.lteIE9) {
  1954. s.setWrapperTranslate(translate);
  1955. s.setWrapperTransition(0);
  1956. s.onTransitionEnd(runCallbacks);
  1957. }
  1958. else {
  1959. s.setWrapperTranslate(translate);
  1960. s.setWrapperTransition(speed);
  1961. if (!s.animating) {
  1962. s.animating = true;
  1963. s.wrapper.transitionEnd(function () {
  1964. if (!s) return;
  1965. s.onTransitionEnd(runCallbacks);
  1966. });
  1967. }
  1968. }
  1969. return true;
  1970. };
  1971. s.onTransitionStart = function (runCallbacks) {
  1972. if (typeof runCallbacks === 'undefined') runCallbacks = true;
  1973. if (s.params.autoHeight) {
  1974. s.updateAutoHeight();
  1975. }
  1976. if (s.lazy) s.lazy.onTransitionStart();
  1977. if (runCallbacks) {
  1978. s.emit('onTransitionStart', s);
  1979. if (s.activeIndex !== s.previousIndex) {
  1980. s.emit('onSlideChangeStart', s);
  1981. if (s.activeIndex > s.previousIndex) {
  1982. s.emit('onSlideNextStart', s);
  1983. }
  1984. else {
  1985. s.emit('onSlidePrevStart', s);
  1986. }
  1987. }
  1988. }
  1989. };
  1990. s.onTransitionEnd = function (runCallbacks) {
  1991. s.animating = false;
  1992. s.setWrapperTransition(0);
  1993. if (typeof runCallbacks === 'undefined') runCallbacks = true;
  1994. if (s.lazy) s.lazy.onTransitionEnd();
  1995. if (runCallbacks) {
  1996. s.emit('onTransitionEnd', s);
  1997. if (s.activeIndex !== s.previousIndex) {
  1998. s.emit('onSlideChangeEnd', s);
  1999. if (s.activeIndex > s.previousIndex) {
  2000. s.emit('onSlideNextEnd', s);
  2001. }
  2002. else {
  2003. s.emit('onSlidePrevEnd', s);
  2004. }
  2005. }
  2006. }
  2007. if (s.params.history && s.history) {
  2008. s.history.setHistory(s.params.history, s.activeIndex);
  2009. }
  2010. if (s.params.hashnav && s.hashnav) {
  2011. s.hashnav.setHash();
  2012. }
  2013. };
  2014. s.slideNext = function (runCallbacks, speed, internal) {
  2015. if (s.params.loop) {
  2016. if (s.animating) return false;
  2017. s.fixLoop();
  2018. var clientLeft = s.container[0].clientLeft;
  2019. return s.slideTo(s.activeIndex + s.params.slidesPerGroup, speed, runCallbacks, internal);
  2020. }
  2021. else return s.slideTo(s.activeIndex + s.params.slidesPerGroup, speed, runCallbacks, internal);
  2022. };
  2023. s._slideNext = function (speed) {
  2024. return s.slideNext(true, speed, true);
  2025. };
  2026. s.slidePrev = function (runCallbacks, speed, internal) {
  2027. if (s.params.loop) {
  2028. if (s.animating) return false;
  2029. s.fixLoop();
  2030. var clientLeft = s.container[0].clientLeft;
  2031. return s.slideTo(s.activeIndex - 1, speed, runCallbacks, internal);
  2032. }
  2033. else return s.slideTo(s.activeIndex - 1, speed, runCallbacks, internal);
  2034. };
  2035. s._slidePrev = function (speed) {
  2036. return s.slidePrev(true, speed, true);
  2037. };
  2038. s.slideReset = function (runCallbacks, speed, internal) {
  2039. return s.slideTo(s.activeIndex, speed, runCallbacks);
  2040. };
  2041. s.disableTouchControl = function () {
  2042. s.params.onlyExternal = true;
  2043. return true;
  2044. };
  2045. s.enableTouchControl = function () {
  2046. s.params.onlyExternal = false;
  2047. return true;
  2048. };
  2049. /*=========================
  2050. Translate/transition helpers
  2051. ===========================*/
  2052. s.setWrapperTransition = function (duration, byController) {
  2053. s.wrapper.transition(duration);
  2054. if (s.params.effect !== 'slide' && s.effects[s.params.effect]) {
  2055. s.effects[s.params.effect].setTransition(duration);
  2056. }
  2057. if (s.params.parallax && s.parallax) {
  2058. s.parallax.setTransition(duration);
  2059. }
  2060. if (s.params.scrollbar && s.scrollbar) {
  2061. s.scrollbar.setTransition(duration);
  2062. }
  2063. if (s.params.control && s.controller) {
  2064. s.controller.setTransition(duration, byController);
  2065. }
  2066. s.emit('onSetTransition', s, duration);
  2067. };
  2068. s.setWrapperTranslate = function (translate, updateActiveIndex, byController) {
  2069. var x = 0, y = 0, z = 0;
  2070. if (s.isHorizontal()) {
  2071. x = s.rtl ? -translate : translate;
  2072. }
  2073. else {
  2074. y = translate;
  2075. }
  2076. if (s.params.roundLengths) {
  2077. x = round(x);
  2078. y = round(y);
  2079. }
  2080. if (!s.params.virtualTranslate) {
  2081. if (s.support.transforms3d) s.wrapper.transform('translate3d(' + x + 'px, ' + y + 'px, ' + z + 'px)');
  2082. else s.wrapper.transform('translate(' + x + 'px, ' + y + 'px)');
  2083. }
  2084. s.translate = s.isHorizontal() ? x : y;
  2085. // Check if we need to update progress
  2086. var progress;
  2087. var translatesDiff = s.maxTranslate() - s.minTranslate();
  2088. if (translatesDiff === 0) {
  2089. progress = 0;
  2090. }
  2091. else {
  2092. progress = (translate - s.minTranslate()) / (translatesDiff);
  2093. }
  2094. if (progress !== s.progress) {
  2095. s.updateProgress(translate);
  2096. }
  2097. if (updateActiveIndex) s.updateActiveIndex();
  2098. if (s.params.effect !== 'slide' && s.effects[s.params.effect]) {
  2099. s.effects[s.params.effect].setTranslate(s.translate);
  2100. }
  2101. if (s.params.parallax && s.parallax) {
  2102. s.parallax.setTranslate(s.translate);
  2103. }
  2104. if (s.params.scrollbar && s.scrollbar) {
  2105. s.scrollbar.setTranslate(s.translate);
  2106. }
  2107. if (s.params.control && s.controller) {
  2108. s.controller.setTranslate(s.translate, byController);
  2109. }
  2110. s.emit('onSetTranslate', s, s.translate);
  2111. };
  2112. s.getTranslate = function (el, axis) {
  2113. var matrix, curTransform, curStyle, transformMatrix;
  2114. // automatic axis detection
  2115. if (typeof axis === 'undefined') {
  2116. axis = 'x';
  2117. }
  2118. if (s.params.virtualTranslate) {
  2119. return s.rtl ? -s.translate : s.translate;
  2120. }
  2121. curStyle = window.getComputedStyle(el, null);
  2122. if (window.WebKitCSSMatrix) {
  2123. curTransform = curStyle.transform || curStyle.webkitTransform;
  2124. if (curTransform.split(',').length > 6) {
  2125. curTransform = curTransform.split(', ').map(function(a){
  2126. return a.replace(',','.');
  2127. }).join(', ');
  2128. }
  2129. // Some old versions of Webkit choke when 'none' is passed; pass
  2130. // empty string instead in this case
  2131. transformMatrix = new window.WebKitCSSMatrix(curTransform === 'none' ? '' : curTransform);
  2132. }
  2133. else {
  2134. transformMatrix = curStyle.MozTransform || curStyle.OTransform || curStyle.MsTransform || curStyle.msTransform || curStyle.transform || curStyle.getPropertyValue('transform').replace('translate(', 'matrix(1, 0, 0, 1,');
  2135. matrix = transformMatrix.toString().split(',');
  2136. }
  2137. if (axis === 'x') {
  2138. //Latest Chrome and webkits Fix
  2139. if (window.WebKitCSSMatrix)
  2140. curTransform = transformMatrix.m41;
  2141. //Crazy IE10 Matrix
  2142. else if (matrix.length === 16)
  2143. curTransform = parseFloat(matrix[12]);
  2144. //Normal Browsers
  2145. else
  2146. curTransform = parseFloat(matrix[4]);
  2147. }
  2148. if (axis === 'y') {
  2149. //Latest Chrome and webkits Fix
  2150. if (window.WebKitCSSMatrix)
  2151. curTransform = transformMatrix.m42;
  2152. //Crazy IE10 Matrix
  2153. else if (matrix.length === 16)
  2154. curTransform = parseFloat(matrix[13]);
  2155. //Normal Browsers
  2156. else
  2157. curTransform = parseFloat(matrix[5]);
  2158. }
  2159. if (s.rtl && curTransform) curTransform = -curTransform;
  2160. return curTransform || 0;
  2161. };
  2162. s.getWrapperTranslate = function (axis) {
  2163. if (typeof axis === 'undefined') {
  2164. axis = s.isHorizontal() ? 'x' : 'y';
  2165. }
  2166. return s.getTranslate(s.wrapper[0], axis);
  2167. };
  2168. /*=========================
  2169. Observer
  2170. ===========================*/
  2171. s.observers = [];
  2172. function initObserver(target, options) {
  2173. options = options || {};
  2174. // create an observer instance
  2175. var ObserverFunc = window.MutationObserver || window.WebkitMutationObserver;
  2176. var observer = new ObserverFunc(function (mutations) {
  2177. mutations.forEach(function (mutation) {
  2178. s.onResize(true);
  2179. s.emit('onObserverUpdate', s, mutation);
  2180. });
  2181. });
  2182. observer.observe(target, {
  2183. attributes: typeof options.attributes === 'undefined' ? true : options.attributes,
  2184. childList: typeof options.childList === 'undefined' ? true : options.childList,
  2185. characterData: typeof options.characterData === 'undefined' ? true : options.characterData
  2186. });
  2187. s.observers.push(observer);
  2188. }
  2189. s.initObservers = function () {
  2190. if (s.params.observeParents) {
  2191. var containerParents = s.container.parents();
  2192. for (var i = 0; i < containerParents.length; i++) {
  2193. initObserver(containerParents[i]);
  2194. }
  2195. }
  2196. // Observe container
  2197. initObserver(s.container[0], {childList: false});
  2198. // Observe wrapper
  2199. initObserver(s.wrapper[0], {attributes: false});
  2200. };
  2201. s.disconnectObservers = function () {
  2202. for (var i = 0; i < s.observers.length; i++) {
  2203. s.observers[i].disconnect();
  2204. }
  2205. s.observers = [];
  2206. };
  2207. /*=========================
  2208. Loop
  2209. ===========================*/
  2210. // Create looped slides
  2211. s.createLoop = function () {
  2212. // Remove duplicated slides
  2213. s.wrapper.children('.' + s.params.slideClass + '.' + s.params.slideDuplicateClass).remove();
  2214. var slides = s.wrapper.children('.' + s.params.slideClass);
  2215. if(s.params.slidesPerView === 'auto' && !s.params.loopedSlides) s.params.loopedSlides = slides.length;
  2216. s.loopedSlides = parseInt(s.params.loopedSlides || s.params.slidesPerView, 10);
  2217. s.loopedSlides = s.loopedSlides + s.params.loopAdditionalSlides;
  2218. if (s.loopedSlides > slides.length) {
  2219. s.loopedSlides = slides.length;
  2220. }
  2221. var prependSlides = [], appendSlides = [], i;
  2222. slides.each(function (index, el) {
  2223. var slide = $(this);
  2224. if (index < s.loopedSlides) appendSlides.push(el);
  2225. if (index < slides.length && index >= slides.length - s.loopedSlides) prependSlides.push(el);
  2226. slide.attr('data-swiper-slide-index', index);
  2227. });
  2228. for (i = 0; i < appendSlides.length; i++) {
  2229. s.wrapper.append($(appendSlides[i].cloneNode(true)).addClass(s.params.slideDuplicateClass));
  2230. }
  2231. for (i = prependSlides.length - 1; i >= 0; i--) {
  2232. s.wrapper.prepend($(prependSlides[i].cloneNode(true)).addClass(s.params.slideDuplicateClass));
  2233. }
  2234. };
  2235. s.destroyLoop = function () {
  2236. s.wrapper.children('.' + s.params.slideClass + '.' + s.params.slideDuplicateClass).remove();
  2237. s.slides.removeAttr('data-swiper-slide-index');
  2238. };
  2239. s.reLoop = function (updatePosition) {
  2240. var oldIndex = s.activeIndex - s.loopedSlides;
  2241. s.destroyLoop();
  2242. s.createLoop();
  2243. s.updateSlidesSize();
  2244. if (updatePosition) {
  2245. s.slideTo(oldIndex + s.loopedSlides, 0, false);
  2246. }
  2247. };
  2248. s.fixLoop = function () {
  2249. var newIndex;
  2250. //Fix For Negative Oversliding
  2251. if (s.activeIndex < s.loopedSlides) {
  2252. newIndex = s.slides.length - s.loopedSlides * 3 + s.activeIndex;
  2253. newIndex = newIndex + s.loopedSlides;
  2254. s.slideTo(newIndex, 0, false, true);
  2255. }
  2256. //Fix For Positive Oversliding
  2257. else if ((s.params.slidesPerView === 'auto' && s.activeIndex >= s.loopedSlides * 2) || (s.activeIndex > s.slides.length - s.params.slidesPerView * 2)) {
  2258. newIndex = -s.slides.length + s.activeIndex + s.loopedSlides;
  2259. newIndex = newIndex + s.loopedSlides;
  2260. s.slideTo(newIndex, 0, false, true);
  2261. }
  2262. };
  2263. /*=========================
  2264. Append/Prepend/Remove Slides
  2265. ===========================*/
  2266. s.appendSlide = function (slides) {
  2267. if (s.params.loop) {
  2268. s.destroyLoop();
  2269. }
  2270. if (typeof slides === 'object' && slides.length) {
  2271. for (var i = 0; i < slides.length; i++) {
  2272. if (slides[i]) s.wrapper.append(slides[i]);
  2273. }
  2274. }
  2275. else {
  2276. s.wrapper.append(slides);
  2277. }
  2278. if (s.params.loop) {
  2279. s.createLoop();
  2280. }
  2281. if (!(s.params.observer && s.support.observer)) {
  2282. s.update(true);
  2283. }
  2284. };
  2285. s.prependSlide = function (slides) {
  2286. if (s.params.loop) {
  2287. s.destroyLoop();
  2288. }
  2289. var newActiveIndex = s.activeIndex + 1;
  2290. if (typeof slides === 'object' && slides.length) {
  2291. for (var i = 0; i < slides.length; i++) {
  2292. if (slides[i]) s.wrapper.prepend(slides[i]);
  2293. }
  2294. newActiveIndex = s.activeIndex + slides.length;
  2295. }
  2296. else {
  2297. s.wrapper.prepend(slides);
  2298. }
  2299. if (s.params.loop) {
  2300. s.createLoop();
  2301. }
  2302. if (!(s.params.observer && s.support.observer)) {
  2303. s.update(true);
  2304. }
  2305. s.slideTo(newActiveIndex, 0, false);
  2306. };
  2307. s.removeSlide = function (slidesIndexes) {
  2308. if (s.params.loop) {
  2309. s.destroyLoop();
  2310. s.slides = s.wrapper.children('.' + s.params.slideClass);
  2311. }
  2312. var newActiveIndex = s.activeIndex,
  2313. indexToRemove;
  2314. if (typeof slidesIndexes === 'object' && slidesIndexes.length) {
  2315. for (var i = 0; i < slidesIndexes.length; i++) {
  2316. indexToRemove = slidesIndexes[i];
  2317. if (s.slides[indexToRemove]) s.slides.eq(indexToRemove).remove();
  2318. if (indexToRemove < newActiveIndex) newActiveIndex--;
  2319. }
  2320. newActiveIndex = Math.max(newActiveIndex, 0);
  2321. }
  2322. else {
  2323. indexToRemove = slidesIndexes;
  2324. if (s.slides[indexToRemove]) s.slides.eq(indexToRemove).remove();
  2325. if (indexToRemove < newActiveIndex) newActiveIndex--;
  2326. newActiveIndex = Math.max(newActiveIndex, 0);
  2327. }
  2328. if (s.params.loop) {
  2329. s.createLoop();
  2330. }
  2331. if (!(s.params.observer && s.support.observer)) {
  2332. s.update(true);
  2333. }
  2334. if (s.params.loop) {
  2335. s.slideTo(newActiveIndex + s.loopedSlides, 0, false);
  2336. }
  2337. else {
  2338. s.slideTo(newActiveIndex, 0, false);
  2339. }
  2340. };
  2341. s.removeAllSlides = function () {
  2342. var slidesIndexes = [];
  2343. for (var i = 0; i < s.slides.length; i++) {
  2344. slidesIndexes.push(i);
  2345. }
  2346. s.removeSlide(slidesIndexes);
  2347. };
  2348. /*=========================
  2349. Effects
  2350. ===========================*/
  2351. s.effects = {
  2352. fade: {
  2353. setTranslate: function () {
  2354. for (var i = 0; i < s.slides.length; i++) {
  2355. var slide = s.slides.eq(i);
  2356. var offset = slide[0].swiperSlideOffset;
  2357. var tx = -offset;
  2358. if (!s.params.virtualTranslate) tx = tx - s.translate;
  2359. var ty = 0;
  2360. if (!s.isHorizontal()) {
  2361. ty = tx;
  2362. tx = 0;
  2363. }
  2364. var slideOpacity = s.params.fade.crossFade ?
  2365. Math.max(1 - Math.abs(slide[0].progress), 0) :
  2366. 1 + Math.min(Math.max(slide[0].progress, -1), 0);
  2367. slide
  2368. .css({
  2369. opacity: slideOpacity
  2370. })
  2371. .transform('translate3d(' + tx + 'px, ' + ty + 'px, 0px)');
  2372. }
  2373. },
  2374. setTransition: function (duration) {
  2375. s.slides.transition(duration);
  2376. if (s.params.virtualTranslate && duration !== 0) {
  2377. var eventTriggered = false;
  2378. s.slides.transitionEnd(function () {
  2379. if (eventTriggered) return;
  2380. if (!s) return;
  2381. eventTriggered = true;
  2382. s.animating = false;
  2383. var triggerEvents = ['webkitTransitionEnd', 'transitionend', 'oTransitionEnd', 'MSTransitionEnd', 'msTransitionEnd'];
  2384. for (var i = 0; i < triggerEvents.length; i++) {
  2385. s.wrapper.trigger(triggerEvents[i]);
  2386. }
  2387. });
  2388. }
  2389. }
  2390. },
  2391. flip: {
  2392. setTranslate: function () {
  2393. for (var i = 0; i < s.slides.length; i++) {
  2394. var slide = s.slides.eq(i);
  2395. var progress = slide[0].progress;
  2396. if (s.params.flip.limitRotation) {
  2397. progress = Math.max(Math.min(slide[0].progress, 1), -1);
  2398. }
  2399. var offset = slide[0].swiperSlideOffset;
  2400. var rotate = -180 * progress,
  2401. rotateY = rotate,
  2402. rotateX = 0,
  2403. tx = -offset,
  2404. ty = 0;
  2405. if (!s.isHorizontal()) {
  2406. ty = tx;
  2407. tx = 0;
  2408. rotateX = -rotateY;
  2409. rotateY = 0;
  2410. }
  2411. else if (s.rtl) {
  2412. rotateY = -rotateY;
  2413. }
  2414. slide[0].style.zIndex = -Math.abs(Math.round(progress)) + s.slides.length;
  2415. if (s.params.flip.slideShadows) {
  2416. //Set shadows
  2417. var shadowBefore = s.isHorizontal() ? slide.find('.swiper-slide-shadow-left') : slide.find('.swiper-slide-shadow-top');
  2418. var shadowAfter = s.isHorizontal() ? slide.find('.swiper-slide-shadow-right') : slide.find('.swiper-slide-shadow-bottom');
  2419. if (shadowBefore.length === 0) {
  2420. shadowBefore = $('<div class="swiper-slide-shadow-' + (s.isHorizontal() ? 'left' : 'top') + '"></div>');
  2421. slide.append(shadowBefore);
  2422. }
  2423. if (shadowAfter.length === 0) {
  2424. shadowAfter = $('<div class="swiper-slide-shadow-' + (s.isHorizontal() ? 'right' : 'bottom') + '"></div>');
  2425. slide.append(shadowAfter);
  2426. }
  2427. if (shadowBefore.length) shadowBefore[0].style.opacity = Math.max(-progress, 0);
  2428. if (shadowAfter.length) shadowAfter[0].style.opacity = Math.max(progress, 0);
  2429. }
  2430. slide
  2431. .transform('translate3d(' + tx + 'px, ' + ty + 'px, 0px) rotateX(' + rotateX + 'deg) rotateY(' + rotateY + 'deg)');
  2432. }
  2433. },
  2434. setTransition: function (duration) {
  2435. s.slides.transition(duration).find('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').transition(duration);
  2436. if (s.params.virtualTranslate && duration !== 0) {
  2437. var eventTriggered = false;
  2438. s.slides.eq(s.activeIndex).transitionEnd(function () {
  2439. if (eventTriggered) return;
  2440. if (!s) return;
  2441. if (!$(this).hasClass(s.params.slideActiveClass)) return;
  2442. eventTriggered = true;
  2443. s.animating = false;
  2444. var triggerEvents = ['webkitTransitionEnd', 'transitionend', 'oTransitionEnd', 'MSTransitionEnd', 'msTransitionEnd'];
  2445. for (var i = 0; i < triggerEvents.length; i++) {
  2446. s.wrapper.trigger(triggerEvents[i]);
  2447. }
  2448. });
  2449. }
  2450. }
  2451. },
  2452. cube: {
  2453. setTranslate: function () {
  2454. var wrapperRotate = 0, cubeShadow;
  2455. if (s.params.cube.shadow) {
  2456. if (s.isHorizontal()) {
  2457. cubeShadow = s.wrapper.find('.swiper-cube-shadow');
  2458. if (cubeShadow.length === 0) {
  2459. cubeShadow = $('<div class="swiper-cube-shadow"></div>');
  2460. s.wrapper.append(cubeShadow);
  2461. }
  2462. cubeShadow.css({height: s.width + 'px'});
  2463. }
  2464. else {
  2465. cubeShadow = s.container.find('.swiper-cube-shadow');
  2466. if (cubeShadow.length === 0) {
  2467. cubeShadow = $('<div class="swiper-cube-shadow"></div>');
  2468. s.container.append(cubeShadow);
  2469. }
  2470. }
  2471. }
  2472. for (var i = 0; i < s.slides.length; i++) {
  2473. var slide = s.slides.eq(i);
  2474. var slideAngle = i * 90;
  2475. var round = Math.floor(slideAngle / 360);
  2476. if (s.rtl) {
  2477. slideAngle = -slideAngle;
  2478. round = Math.floor(-slideAngle / 360);
  2479. }
  2480. var progress = Math.max(Math.min(slide[0].progress, 1), -1);
  2481. var tx = 0, ty = 0, tz = 0;
  2482. if (i % 4 === 0) {
  2483. tx = - round * 4 * s.size;
  2484. tz = 0;
  2485. }
  2486. else if ((i - 1) % 4 === 0) {
  2487. tx = 0;
  2488. tz = - round * 4 * s.size;
  2489. }
  2490. else if ((i - 2) % 4 === 0) {
  2491. tx = s.size + round * 4 * s.size;
  2492. tz = s.size;
  2493. }
  2494. else if ((i - 3) % 4 === 0) {
  2495. tx = - s.size;
  2496. tz = 3 * s.size + s.size * 4 * round;
  2497. }
  2498. if (s.rtl) {
  2499. tx = -tx;
  2500. }
  2501. if (!s.isHorizontal()) {
  2502. ty = tx;
  2503. tx = 0;
  2504. }
  2505. var transform = 'rotateX(' + (s.isHorizontal() ? 0 : -slideAngle) + 'deg) rotateY(' + (s.isHorizontal() ? slideAngle : 0) + 'deg) translate3d(' + tx + 'px, ' + ty + 'px, ' + tz + 'px)';
  2506. if (progress <= 1 && progress > -1) {
  2507. wrapperRotate = i * 90 + progress * 90;
  2508. if (s.rtl) wrapperRotate = -i * 90 - progress * 90;
  2509. }
  2510. slide.transform(transform);
  2511. if (s.params.cube.slideShadows) {
  2512. //Set shadows
  2513. var shadowBefore = s.isHorizontal() ? slide.find('.swiper-slide-shadow-left') : slide.find('.swiper-slide-shadow-top');
  2514. var shadowAfter = s.isHorizontal() ? slide.find('.swiper-slide-shadow-right') : slide.find('.swiper-slide-shadow-bottom');
  2515. if (shadowBefore.length === 0) {
  2516. shadowBefore = $('<div class="swiper-slide-shadow-' + (s.isHorizontal() ? 'left' : 'top') + '"></div>');
  2517. slide.append(shadowBefore);
  2518. }
  2519. if (shadowAfter.length === 0) {
  2520. shadowAfter = $('<div class="swiper-slide-shadow-' + (s.isHorizontal() ? 'right' : 'bottom') + '"></div>');
  2521. slide.append(shadowAfter);
  2522. }
  2523. if (shadowBefore.length) shadowBefore[0].style.opacity = Math.max(-progress, 0);
  2524. if (shadowAfter.length) shadowAfter[0].style.opacity = Math.max(progress, 0);
  2525. }
  2526. }
  2527. s.wrapper.css({
  2528. '-webkit-transform-origin': '50% 50% -' + (s.size / 2) + 'px',
  2529. '-moz-transform-origin': '50% 50% -' + (s.size / 2) + 'px',
  2530. '-ms-transform-origin': '50% 50% -' + (s.size / 2) + 'px',
  2531. 'transform-origin': '50% 50% -' + (s.size / 2) + 'px'
  2532. });
  2533. if (s.params.cube.shadow) {
  2534. if (s.isHorizontal()) {
  2535. 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) + ')');
  2536. }
  2537. else {
  2538. var shadowAngle = Math.abs(wrapperRotate) - Math.floor(Math.abs(wrapperRotate) / 90) * 90;
  2539. var multiplier = 1.5 - (Math.sin(shadowAngle * 2 * Math.PI / 360) / 2 + Math.cos(shadowAngle * 2 * Math.PI / 360) / 2);
  2540. var scale1 = s.params.cube.shadowScale,
  2541. scale2 = s.params.cube.shadowScale / multiplier,
  2542. offset = s.params.cube.shadowOffset;
  2543. cubeShadow.transform('scale3d(' + scale1 + ', 1, ' + scale2 + ') translate3d(0px, ' + (s.height / 2 + offset) + 'px, ' + (-s.height / 2 / scale2) + 'px) rotateX(-90deg)');
  2544. }
  2545. }
  2546. var zFactor = (s.isSafari || s.isUiWebView) ? (-s.size / 2) : 0;
  2547. s.wrapper.transform('translate3d(0px,0,' + zFactor + 'px) rotateX(' + (s.isHorizontal() ? 0 : wrapperRotate) + 'deg) rotateY(' + (s.isHorizontal() ? -wrapperRotate : 0) + 'deg)');
  2548. },
  2549. setTransition: function (duration) {
  2550. s.slides.transition(duration).find('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').transition(duration);
  2551. if (s.params.cube.shadow && !s.isHorizontal()) {
  2552. s.container.find('.swiper-cube-shadow').transition(duration);
  2553. }
  2554. }
  2555. },
  2556. coverflow: {
  2557. setTranslate: function () {
  2558. var transform = s.translate;
  2559. var center = s.isHorizontal() ? -transform + s.width / 2 : -transform + s.height / 2;
  2560. var rotate = s.isHorizontal() ? s.params.coverflow.rotate: -s.params.coverflow.rotate;
  2561. var translate = s.params.coverflow.depth;
  2562. //Each slide offset from center
  2563. for (var i = 0, length = s.slides.length; i < length; i++) {
  2564. var slide = s.slides.eq(i);
  2565. var slideSize = s.slidesSizesGrid[i];
  2566. var slideOffset = slide[0].swiperSlideOffset;
  2567. var offsetMultiplier = (center - slideOffset - slideSize / 2) / slideSize * s.params.coverflow.modifier;
  2568. var rotateY = s.isHorizontal() ? rotate * offsetMultiplier : 0;
  2569. var rotateX = s.isHorizontal() ? 0 : rotate * offsetMultiplier;
  2570. // var rotateZ = 0
  2571. var translateZ = -translate * Math.abs(offsetMultiplier);
  2572. var translateY = s.isHorizontal() ? 0 : s.params.coverflow.stretch * (offsetMultiplier);
  2573. var translateX = s.isHorizontal() ? s.params.coverflow.stretch * (offsetMultiplier) : 0;
  2574. //Fix for ultra small values
  2575. if (Math.abs(translateX) < 0.001) translateX = 0;
  2576. if (Math.abs(translateY) < 0.001) translateY = 0;
  2577. if (Math.abs(translateZ) < 0.001) translateZ = 0;
  2578. if (Math.abs(rotateY) < 0.001) rotateY = 0;
  2579. if (Math.abs(rotateX) < 0.001) rotateX = 0;
  2580. var slideTransform = 'translate3d(' + translateX + 'px,' + translateY + 'px,' + translateZ + 'px) rotateX(' + rotateX + 'deg) rotateY(' + rotateY + 'deg)';
  2581. slide.transform(slideTransform);
  2582. slide[0].style.zIndex = -Math.abs(Math.round(offsetMultiplier)) + 1;
  2583. if (s.params.coverflow.slideShadows) {
  2584. //Set shadows
  2585. var shadowBefore = s.isHorizontal() ? slide.find('.swiper-slide-shadow-left') : slide.find('.swiper-slide-shadow-top');
  2586. var shadowAfter = s.isHorizontal() ? slide.find('.swiper-slide-shadow-right') : slide.find('.swiper-slide-shadow-bottom');
  2587. if (shadowBefore.length === 0) {
  2588. shadowBefore = $('<div class="swiper-slide-shadow-' + (s.isHorizontal() ? 'left' : 'top') + '"></div>');
  2589. slide.append(shadowBefore);
  2590. }
  2591. if (shadowAfter.length === 0) {
  2592. shadowAfter = $('<div class="swiper-slide-shadow-' + (s.isHorizontal() ? 'right' : 'bottom') + '"></div>');
  2593. slide.append(shadowAfter);
  2594. }
  2595. if (shadowBefore.length) shadowBefore[0].style.opacity = offsetMultiplier > 0 ? offsetMultiplier : 0;
  2596. if (shadowAfter.length) shadowAfter[0].style.opacity = (-offsetMultiplier) > 0 ? -offsetMultiplier : 0;
  2597. }
  2598. }
  2599. //Set correct perspective for IE10
  2600. if (s.browser.ie) {
  2601. var ws = s.wrapper[0].style;
  2602. ws.perspectiveOrigin = center + 'px 50%';
  2603. }
  2604. },
  2605. setTransition: function (duration) {
  2606. s.slides.transition(duration).find('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').transition(duration);
  2607. }
  2608. }
  2609. };
  2610. /*=========================
  2611. Images Lazy Loading
  2612. ===========================*/
  2613. s.lazy = {
  2614. initialImageLoaded: false,
  2615. loadImageInSlide: function (index, loadInDuplicate) {
  2616. if (typeof index === 'undefined') return;
  2617. if (typeof loadInDuplicate === 'undefined') loadInDuplicate = true;
  2618. if (s.slides.length === 0) return;
  2619. var slide = s.slides.eq(index);
  2620. var img = slide.find('.' + s.params.lazyLoadingClass + ':not(.' + s.params.lazyStatusLoadedClass + '):not(.' + s.params.lazyStatusLoadingClass + ')');
  2621. if (slide.hasClass(s.params.lazyLoadingClass) && !slide.hasClass(s.params.lazyStatusLoadedClass) && !slide.hasClass(s.params.lazyStatusLoadingClass)) {
  2622. img = img.add(slide[0]);
  2623. }
  2624. if (img.length === 0) return;
  2625. img.each(function () {
  2626. var _img = $(this);
  2627. _img.addClass(s.params.lazyStatusLoadingClass);
  2628. var background = _img.attr('data-background');
  2629. var src = _img.attr('data-src'),
  2630. srcset = _img.attr('data-srcset'),
  2631. sizes = _img.attr('data-sizes');
  2632. s.loadImage(_img[0], (src || background), srcset, sizes, false, function () {
  2633. if (background) {
  2634. _img.css('background-image', 'url("' + background + '")');
  2635. _img.removeAttr('data-background');
  2636. }
  2637. else {
  2638. if (srcset) {
  2639. _img.attr('srcset', srcset);
  2640. _img.removeAttr('data-srcset');
  2641. }
  2642. if (sizes) {
  2643. _img.attr('sizes', sizes);
  2644. _img.removeAttr('data-sizes');
  2645. }
  2646. if (src) {
  2647. _img.attr('src', src);
  2648. _img.removeAttr('data-src');
  2649. }
  2650. }
  2651. _img.addClass(s.params.lazyStatusLoadedClass).removeClass(s.params.lazyStatusLoadingClass);
  2652. slide.find('.' + s.params.lazyPreloaderClass + ', .' + s.params.preloaderClass).remove();
  2653. if (s.params.loop && loadInDuplicate) {
  2654. var slideOriginalIndex = slide.attr('data-swiper-slide-index');
  2655. if (slide.hasClass(s.params.slideDuplicateClass)) {
  2656. var originalSlide = s.wrapper.children('[data-swiper-slide-index="' + slideOriginalIndex + '"]:not(.' + s.params.slideDuplicateClass + ')');
  2657. s.lazy.loadImageInSlide(originalSlide.index(), false);
  2658. }
  2659. else {
  2660. var duplicatedSlide = s.wrapper.children('.' + s.params.slideDuplicateClass + '[data-swiper-slide-index="' + slideOriginalIndex + '"]');
  2661. s.lazy.loadImageInSlide(duplicatedSlide.index(), false);
  2662. }
  2663. }
  2664. s.emit('onLazyImageReady', s, slide[0], _img[0]);
  2665. });
  2666. s.emit('onLazyImageLoad', s, slide[0], _img[0]);
  2667. });
  2668. },
  2669. load: function () {
  2670. var i;
  2671. var slidesPerView = s.params.slidesPerView;
  2672. if (slidesPerView === 'auto') {
  2673. slidesPerView = 0;
  2674. }
  2675. if (!s.lazy.initialImageLoaded) s.lazy.initialImageLoaded = true;
  2676. if (s.params.watchSlidesVisibility) {
  2677. s.wrapper.children('.' + s.params.slideVisibleClass).each(function () {
  2678. s.lazy.loadImageInSlide($(this).index());
  2679. });
  2680. }
  2681. else {
  2682. if (slidesPerView > 1) {
  2683. for (i = s.activeIndex; i < s.activeIndex + slidesPerView ; i++) {
  2684. if (s.slides[i]) s.lazy.loadImageInSlide(i);
  2685. }
  2686. }
  2687. else {
  2688. s.lazy.loadImageInSlide(s.activeIndex);
  2689. }
  2690. }
  2691. if (s.params.lazyLoadingInPrevNext) {
  2692. if (slidesPerView > 1 || (s.params.lazyLoadingInPrevNextAmount && s.params.lazyLoadingInPrevNextAmount > 1)) {
  2693. var amount = s.params.lazyLoadingInPrevNextAmount;
  2694. var spv = slidesPerView;
  2695. var maxIndex = Math.min(s.activeIndex + spv + Math.max(amount, spv), s.slides.length);
  2696. var minIndex = Math.max(s.activeIndex - Math.max(spv, amount), 0);
  2697. // Next Slides
  2698. for (i = s.activeIndex + slidesPerView; i < maxIndex; i++) {
  2699. if (s.slides[i]) s.lazy.loadImageInSlide(i);
  2700. }
  2701. // Prev Slides
  2702. for (i = minIndex; i < s.activeIndex ; i++) {
  2703. if (s.slides[i]) s.lazy.loadImageInSlide(i);
  2704. }
  2705. }
  2706. else {
  2707. var nextSlide = s.wrapper.children('.' + s.params.slideNextClass);
  2708. if (nextSlide.length > 0) s.lazy.loadImageInSlide(nextSlide.index());
  2709. var prevSlide = s.wrapper.children('.' + s.params.slidePrevClass);
  2710. if (prevSlide.length > 0) s.lazy.loadImageInSlide(prevSlide.index());
  2711. }
  2712. }
  2713. },
  2714. onTransitionStart: function () {
  2715. if (s.params.lazyLoading) {
  2716. if (s.params.lazyLoadingOnTransitionStart || (!s.params.lazyLoadingOnTransitionStart && !s.lazy.initialImageLoaded)) {
  2717. s.lazy.load();
  2718. }
  2719. }
  2720. },
  2721. onTransitionEnd: function () {
  2722. if (s.params.lazyLoading && !s.params.lazyLoadingOnTransitionStart) {
  2723. s.lazy.load();
  2724. }
  2725. }
  2726. };
  2727. /*=========================
  2728. Scrollbar
  2729. ===========================*/
  2730. s.scrollbar = {
  2731. isTouched: false,
  2732. setDragPosition: function (e) {
  2733. var sb = s.scrollbar;
  2734. var x = 0, y = 0;
  2735. var translate;
  2736. var pointerPosition = s.isHorizontal() ?
  2737. ((e.type === 'touchstart' || e.type === 'touchmove') ? e.targetTouches[0].pageX : e.pageX || e.clientX) :
  2738. ((e.type === 'touchstart' || e.type === 'touchmove') ? e.targetTouches[0].pageY : e.pageY || e.clientY) ;
  2739. var position = (pointerPosition) - sb.track.offset()[s.isHorizontal() ? 'left' : 'top'] - sb.dragSize / 2;
  2740. var positionMin = -s.minTranslate() * sb.moveDivider;
  2741. var positionMax = -s.maxTranslate() * sb.moveDivider;
  2742. if (position < positionMin) {
  2743. position = positionMin;
  2744. }
  2745. else if (position > positionMax) {
  2746. position = positionMax;
  2747. }
  2748. position = -position / sb.moveDivider;
  2749. s.updateProgress(position);
  2750. s.setWrapperTranslate(position, true);
  2751. },
  2752. dragStart: function (e) {
  2753. var sb = s.scrollbar;
  2754. sb.isTouched = true;
  2755. e.preventDefault();
  2756. e.stopPropagation();
  2757. sb.setDragPosition(e);
  2758. clearTimeout(sb.dragTimeout);
  2759. sb.track.transition(0);
  2760. if (s.params.scrollbarHide) {
  2761. sb.track.css('opacity', 1);
  2762. }
  2763. s.wrapper.transition(100);
  2764. sb.drag.transition(100);
  2765. s.emit('onScrollbarDragStart', s);
  2766. },
  2767. dragMove: function (e) {
  2768. var sb = s.scrollbar;
  2769. if (!sb.isTouched) return;
  2770. if (e.preventDefault) e.preventDefault();
  2771. else e.returnValue = false;
  2772. sb.setDragPosition(e);
  2773. s.wrapper.transition(0);
  2774. sb.track.transition(0);
  2775. sb.drag.transition(0);
  2776. s.emit('onScrollbarDragMove', s);
  2777. },
  2778. dragEnd: function (e) {
  2779. var sb = s.scrollbar;
  2780. if (!sb.isTouched) return;
  2781. sb.isTouched = false;
  2782. if (s.params.scrollbarHide) {
  2783. clearTimeout(sb.dragTimeout);
  2784. sb.dragTimeout = setTimeout(function () {
  2785. sb.track.css('opacity', 0);
  2786. sb.track.transition(400);
  2787. }, 1000);
  2788. }
  2789. s.emit('onScrollbarDragEnd', s);
  2790. if (s.params.scrollbarSnapOnRelease) {
  2791. s.slideReset();
  2792. }
  2793. },
  2794. draggableEvents: (function () {
  2795. if ((s.params.simulateTouch === false && !s.support.touch)) return s.touchEventsDesktop;
  2796. else return s.touchEvents;
  2797. })(),
  2798. enableDraggable: function () {
  2799. var sb = s.scrollbar;
  2800. var target = s.support.touch ? sb.track : document;
  2801. $(sb.track).on(sb.draggableEvents.start, sb.dragStart);
  2802. $(target).on(sb.draggableEvents.move, sb.dragMove);
  2803. $(target).on(sb.draggableEvents.end, sb.dragEnd);
  2804. },
  2805. disableDraggable: function () {
  2806. var sb = s.scrollbar;
  2807. var target = s.support.touch ? sb.track : document;
  2808. $(sb.track).off(sb.draggableEvents.start, sb.dragStart);
  2809. $(target).off(sb.draggableEvents.move, sb.dragMove);
  2810. $(target).off(sb.draggableEvents.end, sb.dragEnd);
  2811. },
  2812. set: function () {
  2813. if (!s.params.scrollbar) return;
  2814. var sb = s.scrollbar;
  2815. sb.track = $(s.params.scrollbar);
  2816. if (s.params.uniqueNavElements && typeof s.params.scrollbar === 'string' && sb.track.length > 1 && s.container.find(s.params.scrollbar).length === 1) {
  2817. sb.track = s.container.find(s.params.scrollbar);
  2818. }
  2819. sb.drag = sb.track.find('.swiper-scrollbar-drag');
  2820. if (sb.drag.length === 0) {
  2821. sb.drag = $('<div class="swiper-scrollbar-drag"></div>');
  2822. sb.track.append(sb.drag);
  2823. }
  2824. sb.drag[0].style.width = '';
  2825. sb.drag[0].style.height = '';
  2826. sb.trackSize = s.isHorizontal() ? sb.track[0].offsetWidth : sb.track[0].offsetHeight;
  2827. sb.divider = s.size / s.virtualSize;
  2828. sb.moveDivider = sb.divider * (sb.trackSize / s.size);
  2829. sb.dragSize = sb.trackSize * sb.divider;
  2830. if (s.isHorizontal()) {
  2831. sb.drag[0].style.width = sb.dragSize + 'px';
  2832. }
  2833. else {
  2834. sb.drag[0].style.height = sb.dragSize + 'px';
  2835. }
  2836. if (sb.divider >= 1) {
  2837. sb.track[0].style.display = 'none';
  2838. }
  2839. else {
  2840. sb.track[0].style.display = '';
  2841. }
  2842. if (s.params.scrollbarHide) {
  2843. sb.track[0].style.opacity = 0;
  2844. }
  2845. },
  2846. setTranslate: function () {
  2847. if (!s.params.scrollbar) return;
  2848. var diff;
  2849. var sb = s.scrollbar;
  2850. var translate = s.translate || 0;
  2851. var newPos;
  2852. var newSize = sb.dragSize;
  2853. newPos = (sb.trackSize - sb.dragSize) * s.progress;
  2854. if (s.rtl && s.isHorizontal()) {
  2855. newPos = -newPos;
  2856. if (newPos > 0) {
  2857. newSize = sb.dragSize - newPos;
  2858. newPos = 0;
  2859. }
  2860. else if (-newPos + sb.dragSize > sb.trackSize) {
  2861. newSize = sb.trackSize + newPos;
  2862. }
  2863. }
  2864. else {
  2865. if (newPos < 0) {
  2866. newSize = sb.dragSize + newPos;
  2867. newPos = 0;
  2868. }
  2869. else if (newPos + sb.dragSize > sb.trackSize) {
  2870. newSize = sb.trackSize - newPos;
  2871. }
  2872. }
  2873. if (s.isHorizontal()) {
  2874. if (s.support.transforms3d) {
  2875. sb.drag.transform('translate3d(' + (newPos) + 'px, 0, 0)');
  2876. }
  2877. else {
  2878. sb.drag.transform('translateX(' + (newPos) + 'px)');
  2879. }
  2880. sb.drag[0].style.width = newSize + 'px';
  2881. }
  2882. else {
  2883. if (s.support.transforms3d) {
  2884. sb.drag.transform('translate3d(0px, ' + (newPos) + 'px, 0)');
  2885. }
  2886. else {
  2887. sb.drag.transform('translateY(' + (newPos) + 'px)');
  2888. }
  2889. sb.drag[0].style.height = newSize + 'px';
  2890. }
  2891. if (s.params.scrollbarHide) {
  2892. clearTimeout(sb.timeout);
  2893. sb.track[0].style.opacity = 1;
  2894. sb.timeout = setTimeout(function () {
  2895. sb.track[0].style.opacity = 0;
  2896. sb.track.transition(400);
  2897. }, 1000);
  2898. }
  2899. },
  2900. setTransition: function (duration) {
  2901. if (!s.params.scrollbar) return;
  2902. s.scrollbar.drag.transition(duration);
  2903. }
  2904. };
  2905. /*=========================
  2906. Controller
  2907. ===========================*/
  2908. s.controller = {
  2909. LinearSpline: function (x, y) {
  2910. this.x = x;
  2911. this.y = y;
  2912. this.lastIndex = x.length - 1;
  2913. // Given an x value (x2), return the expected y2 value:
  2914. // (x1,y1) is the known point before given value,
  2915. // (x3,y3) is the known point after given value.
  2916. var i1, i3;
  2917. var l = this.x.length;
  2918. this.interpolate = function (x2) {
  2919. if (!x2) return 0;
  2920. // Get the indexes of x1 and x3 (the array indexes before and after given x2):
  2921. i3 = binarySearch(this.x, x2);
  2922. i1 = i3 - 1;
  2923. // We have our indexes i1 & i3, so we can calculate already:
  2924. // y2 := ((x2−x1) × (y3−y1)) ÷ (x3−x1) + y1
  2925. return ((x2 - this.x[i1]) * (this.y[i3] - this.y[i1])) / (this.x[i3] - this.x[i1]) + this.y[i1];
  2926. };
  2927. var binarySearch = (function() {
  2928. var maxIndex, minIndex, guess;
  2929. return function(array, val) {
  2930. minIndex = -1;
  2931. maxIndex = array.length;
  2932. while (maxIndex - minIndex > 1)
  2933. if (array[guess = maxIndex + minIndex >> 1] <= val) {
  2934. minIndex = guess;
  2935. } else {
  2936. maxIndex = guess;
  2937. }
  2938. return maxIndex;
  2939. };
  2940. })();
  2941. },
  2942. //xxx: for now i will just save one spline function to to
  2943. getInterpolateFunction: function(c){
  2944. if(!s.controller.spline) s.controller.spline = s.params.loop ?
  2945. new s.controller.LinearSpline(s.slidesGrid, c.slidesGrid) :
  2946. new s.controller.LinearSpline(s.snapGrid, c.snapGrid);
  2947. },
  2948. setTranslate: function (translate, byController) {
  2949. var controlled = s.params.control;
  2950. var multiplier, controlledTranslate;
  2951. function setControlledTranslate(c) {
  2952. // this will create an Interpolate function based on the snapGrids
  2953. // x is the Grid of the scrolled scroller and y will be the controlled scroller
  2954. // it makes sense to create this only once and recall it for the interpolation
  2955. // the function does a lot of value caching for performance
  2956. translate = c.rtl && c.params.direction === 'horizontal' ? -s.translate : s.translate;
  2957. if (s.params.controlBy === 'slide') {
  2958. s.controller.getInterpolateFunction(c);
  2959. // i am not sure why the values have to be multiplicated this way, tried to invert the snapGrid
  2960. // but it did not work out
  2961. controlledTranslate = -s.controller.spline.interpolate(-translate);
  2962. }
  2963. if(!controlledTranslate || s.params.controlBy === 'container'){
  2964. multiplier = (c.maxTranslate() - c.minTranslate()) / (s.maxTranslate() - s.minTranslate());
  2965. controlledTranslate = (translate - s.minTranslate()) * multiplier + c.minTranslate();
  2966. }
  2967. if (s.params.controlInverse) {
  2968. controlledTranslate = c.maxTranslate() - controlledTranslate;
  2969. }
  2970. c.updateProgress(controlledTranslate);
  2971. c.setWrapperTranslate(controlledTranslate, false, s);
  2972. c.updateActiveIndex();
  2973. }
  2974. if (s.isArray(controlled)) {
  2975. for (var i = 0; i < controlled.length; i++) {
  2976. if (controlled[i] !== byController && controlled[i] instanceof Swiper) {
  2977. setControlledTranslate(controlled[i]);
  2978. }
  2979. }
  2980. }
  2981. else if (controlled instanceof Swiper && byController !== controlled) {
  2982. setControlledTranslate(controlled);
  2983. }
  2984. },
  2985. setTransition: function (duration, byController) {
  2986. var controlled = s.params.control;
  2987. var i;
  2988. function setControlledTransition(c) {
  2989. c.setWrapperTransition(duration, s);
  2990. if (duration !== 0) {
  2991. c.onTransitionStart();
  2992. c.wrapper.transitionEnd(function(){
  2993. if (!controlled) return;
  2994. if (c.params.loop && s.params.controlBy === 'slide') {
  2995. c.fixLoop();
  2996. }
  2997. c.onTransitionEnd();
  2998. });
  2999. }
  3000. }
  3001. if (s.isArray(controlled)) {
  3002. for (i = 0; i < controlled.length; i++) {
  3003. if (controlled[i] !== byController && controlled[i] instanceof Swiper) {
  3004. setControlledTransition(controlled[i]);
  3005. }
  3006. }
  3007. }
  3008. else if (controlled instanceof Swiper && byController !== controlled) {
  3009. setControlledTransition(controlled);
  3010. }
  3011. }
  3012. };
  3013. /*=========================
  3014. Hash Navigation
  3015. ===========================*/
  3016. s.hashnav = {
  3017. onHashCange: function (e, a) {
  3018. var newHash = document.location.hash.replace('#', '');
  3019. var activeSlideHash = s.slides.eq(s.activeIndex).attr('data-hash');
  3020. if (newHash !== activeSlideHash) {
  3021. s.slideTo(s.wrapper.children('.' + s.params.slideClass + '[data-hash="' + (newHash) + '"]').index());
  3022. }
  3023. },
  3024. attachEvents: function (detach) {
  3025. var action = detach ? 'off' : 'on';
  3026. $(window)[action]('hashchange', s.hashnav.onHashCange);
  3027. },
  3028. setHash: function () {
  3029. if (!s.hashnav.initialized || !s.params.hashnav) return;
  3030. if (s.params.replaceState && window.history && window.history.replaceState) {
  3031. window.history.replaceState(null, null, ('#' + s.slides.eq(s.activeIndex).attr('data-hash') || ''));
  3032. } else {
  3033. var slide = s.slides.eq(s.activeIndex);
  3034. var hash = slide.attr('data-hash') || slide.attr('data-history');
  3035. document.location.hash = hash || '';
  3036. }
  3037. },
  3038. init: function () {
  3039. if (!s.params.hashnav || s.params.history) return;
  3040. s.hashnav.initialized = true;
  3041. var hash = document.location.hash.replace('#', '');
  3042. if (hash) {
  3043. var speed = 0;
  3044. for (var i = 0, length = s.slides.length; i < length; i++) {
  3045. var slide = s.slides.eq(i);
  3046. var slideHash = slide.attr('data-hash') || slide.attr('data-history');
  3047. if (slideHash === hash && !slide.hasClass(s.params.slideDuplicateClass)) {
  3048. var index = slide.index();
  3049. s.slideTo(index, speed, s.params.runCallbacksOnInit, true);
  3050. }
  3051. }
  3052. }
  3053. if (s.params.hashnavWatchState) s.hashnav.attachEvents();
  3054. },
  3055. destroy: function () {
  3056. if (s.params.hashnavWatchState) s.hashnav.attachEvents(true);
  3057. }
  3058. };
  3059. /*=========================
  3060. History Api with fallback to Hashnav
  3061. ===========================*/
  3062. s.history = {
  3063. init: function () {
  3064. if (!s.params.history) return;
  3065. if (!window.history || !window.history.pushState) {
  3066. s.params.history = false;
  3067. s.params.hashnav = true;
  3068. return;
  3069. }
  3070. s.history.initialized = true;
  3071. this.paths = this.getPathValues();
  3072. if (!this.paths.key && !this.paths.value) return;
  3073. this.scrollToSlide(0, this.paths.value, s.params.runCallbacksOnInit);
  3074. if (!s.params.replaceState) {
  3075. window.addEventListener('popstate', this.setHistoryPopState);
  3076. }
  3077. },
  3078. setHistoryPopState: function() {
  3079. s.history.paths = s.history.getPathValues();
  3080. s.history.scrollToSlide(s.params.speed, s.history.paths.value, false);
  3081. },
  3082. getPathValues: function() {
  3083. var pathArray = window.location.pathname.slice(1).split('/');
  3084. var total = pathArray.length;
  3085. var key = pathArray[total - 2];
  3086. var value = pathArray[total - 1];
  3087. return { key: key, value: value };
  3088. },
  3089. setHistory: function (key, index) {
  3090. if (!s.history.initialized || !s.params.history) return;
  3091. var slide = s.slides.eq(index);
  3092. var value = this.slugify(slide.attr('data-history'));
  3093. if (!window.location.pathname.includes(key)) {
  3094. value = key + '/' + value;
  3095. }
  3096. if (s.params.replaceState) {
  3097. window.history.replaceState(null, null, value);
  3098. } else {
  3099. window.history.pushState(null, null, value);
  3100. }
  3101. },
  3102. slugify: function(text) {
  3103. return text.toString().toLowerCase()
  3104. .replace(/\s+/g, '-')
  3105. .replace(/[^\w\-]+/g, '')
  3106. .replace(/\-\-+/g, '-')
  3107. .replace(/^-+/, '')
  3108. .replace(/-+$/, '');
  3109. },
  3110. scrollToSlide: function(speed, value, runCallbacks) {
  3111. if (value) {
  3112. for (var i = 0, length = s.slides.length; i < length; i++) {
  3113. var slide = s.slides.eq(i);
  3114. var slideHistory = this.slugify(slide.attr('data-history'));
  3115. if (slideHistory === value && !slide.hasClass(s.params.slideDuplicateClass)) {
  3116. var index = slide.index();
  3117. s.slideTo(index, speed, runCallbacks);
  3118. }
  3119. }
  3120. } else {
  3121. s.slideTo(0, speed, runCallbacks);
  3122. }
  3123. }
  3124. };
  3125. /*=========================
  3126. Keyboard Control
  3127. ===========================*/
  3128. function handleKeyboard(e) {
  3129. if (e.originalEvent) e = e.originalEvent; //jquery fix
  3130. var kc = e.keyCode || e.charCode;
  3131. // Directions locks
  3132. if (!s.params.allowSwipeToNext && (s.isHorizontal() && kc === 39 || !s.isHorizontal() && kc === 40)) {
  3133. return false;
  3134. }
  3135. if (!s.params.allowSwipeToPrev && (s.isHorizontal() && kc === 37 || !s.isHorizontal() && kc === 38)) {
  3136. return false;
  3137. }
  3138. if (e.shiftKey || e.altKey || e.ctrlKey || e.metaKey) {
  3139. return;
  3140. }
  3141. if (document.activeElement && document.activeElement.nodeName && (document.activeElement.nodeName.toLowerCase() === 'input' || document.activeElement.nodeName.toLowerCase() === 'textarea')) {
  3142. return;
  3143. }
  3144. if (kc === 37 || kc === 39 || kc === 38 || kc === 40) {
  3145. var inView = false;
  3146. //Check that swiper should be inside of visible area of window
  3147. if (s.container.parents('.' + s.params.slideClass).length > 0 && s.container.parents('.' + s.params.slideActiveClass).length === 0) {
  3148. return;
  3149. }
  3150. var windowScroll = {
  3151. left: window.pageXOffset,
  3152. top: window.pageYOffset
  3153. };
  3154. var windowWidth = window.innerWidth;
  3155. var windowHeight = window.innerHeight;
  3156. var swiperOffset = s.container.offset();
  3157. if (s.rtl) swiperOffset.left = swiperOffset.left - s.container[0].scrollLeft;
  3158. var swiperCoord = [
  3159. [swiperOffset.left, swiperOffset.top],
  3160. [swiperOffset.left + s.width, swiperOffset.top],
  3161. [swiperOffset.left, swiperOffset.top + s.height],
  3162. [swiperOffset.left + s.width, swiperOffset.top + s.height]
  3163. ];
  3164. for (var i = 0; i < swiperCoord.length; i++) {
  3165. var point = swiperCoord[i];
  3166. if (
  3167. point[0] >= windowScroll.left && point[0] <= windowScroll.left + windowWidth &&
  3168. point[1] >= windowScroll.top && point[1] <= windowScroll.top + windowHeight
  3169. ) {
  3170. inView = true;
  3171. }
  3172. }
  3173. if (!inView) return;
  3174. }
  3175. if (s.isHorizontal()) {
  3176. if (kc === 37 || kc === 39) {
  3177. if (e.preventDefault) e.preventDefault();
  3178. else e.returnValue = false;
  3179. }
  3180. if ((kc === 39 && !s.rtl) || (kc === 37 && s.rtl)) s.slideNext();
  3181. if ((kc === 37 && !s.rtl) || (kc === 39 && s.rtl)) s.slidePrev();
  3182. }
  3183. else {
  3184. if (kc === 38 || kc === 40) {
  3185. if (e.preventDefault) e.preventDefault();
  3186. else e.returnValue = false;
  3187. }
  3188. if (kc === 40) s.slideNext();
  3189. if (kc === 38) s.slidePrev();
  3190. }
  3191. }
  3192. s.disableKeyboardControl = function () {
  3193. s.params.keyboardControl = false;
  3194. $(document).off('keydown', handleKeyboard);
  3195. };
  3196. s.enableKeyboardControl = function () {
  3197. s.params.keyboardControl = true;
  3198. $(document).on('keydown', handleKeyboard);
  3199. };
  3200. /*=========================
  3201. Mousewheel Control
  3202. ===========================*/
  3203. s.mousewheel = {
  3204. event: false,
  3205. lastScrollTime: (new window.Date()).getTime()
  3206. };
  3207. if (s.params.mousewheelControl) {
  3208. /**
  3209. * The best combination if you prefer spinX + spinY normalization. It favors
  3210. * the older DOMMouseScroll for Firefox, as FF does not include wheelDelta with
  3211. * 'wheel' event, making spin speed determination impossible.
  3212. */
  3213. s.mousewheel.event = (navigator.userAgent.indexOf('firefox') > -1) ?
  3214. 'DOMMouseScroll' :
  3215. isEventSupported() ?
  3216. 'wheel' : 'mousewheel';
  3217. }
  3218. function isEventSupported() {
  3219. var eventName = 'onwheel';
  3220. var isSupported = eventName in document;
  3221. if (!isSupported) {
  3222. var element = document.createElement('div');
  3223. element.setAttribute(eventName, 'return;');
  3224. isSupported = typeof element[eventName] === 'function';
  3225. }
  3226. if (!isSupported &&
  3227. document.implementation &&
  3228. document.implementation.hasFeature &&
  3229. // always returns true in newer browsers as per the standard.
  3230. // @see http://dom.spec.whatwg.org/#dom-domimplementation-hasfeature
  3231. document.implementation.hasFeature('', '') !== true ) {
  3232. // This is the only way to test support for the `wheel` event in IE9+.
  3233. isSupported = document.implementation.hasFeature('Events.wheel', '3.0');
  3234. }
  3235. return isSupported;
  3236. }
  3237. function handleMousewheel(e) {
  3238. if (e.originalEvent) e = e.originalEvent; //jquery fix
  3239. var delta = 0;
  3240. var rtlFactor = s.rtl ? -1 : 1;
  3241. var data = normalizeWheel( e );
  3242. if (s.params.mousewheelForceToAxis) {
  3243. if (s.isHorizontal()) {
  3244. if (Math.abs(data.pixelX) > Math.abs(data.pixelY)) delta = data.pixelX * rtlFactor;
  3245. else return;
  3246. }
  3247. else {
  3248. if (Math.abs(data.pixelY) > Math.abs(data.pixelX)) delta = data.pixelY;
  3249. else return;
  3250. }
  3251. }
  3252. else {
  3253. delta = Math.abs(data.pixelX) > Math.abs(data.pixelY) ? - data.pixelX * rtlFactor : - data.pixelY;
  3254. }
  3255. if (delta === 0) return;
  3256. if (s.params.mousewheelInvert) delta = -delta;
  3257. if (!s.params.freeMode) {
  3258. if ((new window.Date()).getTime() - s.mousewheel.lastScrollTime > 60) {
  3259. if (delta < 0) {
  3260. if ((!s.isEnd || s.params.loop) && !s.animating) {
  3261. s.slideNext();
  3262. s.emit('onScroll', s, e);
  3263. }
  3264. else if (s.params.mousewheelReleaseOnEdges) return true;
  3265. }
  3266. else {
  3267. if ((!s.isBeginning || s.params.loop) && !s.animating) {
  3268. s.slidePrev();
  3269. s.emit('onScroll', s, e);
  3270. }
  3271. else if (s.params.mousewheelReleaseOnEdges) return true;
  3272. }
  3273. }
  3274. s.mousewheel.lastScrollTime = (new window.Date()).getTime();
  3275. }
  3276. else {
  3277. //Freemode or scrollContainer:
  3278. var position = s.getWrapperTranslate() + delta * s.params.mousewheelSensitivity;
  3279. var wasBeginning = s.isBeginning,
  3280. wasEnd = s.isEnd;
  3281. if (position >= s.minTranslate()) position = s.minTranslate();
  3282. if (position <= s.maxTranslate()) position = s.maxTranslate();
  3283. s.setWrapperTransition(0);
  3284. s.setWrapperTranslate(position);
  3285. s.updateProgress();
  3286. s.updateActiveIndex();
  3287. if (!wasBeginning && s.isBeginning || !wasEnd && s.isEnd) {
  3288. s.updateClasses();
  3289. }
  3290. if (s.params.freeModeSticky) {
  3291. clearTimeout(s.mousewheel.timeout);
  3292. s.mousewheel.timeout = setTimeout(function () {
  3293. s.slideReset();
  3294. }, 300);
  3295. }
  3296. else {
  3297. if (s.params.lazyLoading && s.lazy) {
  3298. s.lazy.load();
  3299. }
  3300. }
  3301. // Emit event
  3302. s.emit('onScroll', s, e);
  3303. // Stop autoplay
  3304. if (s.params.autoplay && s.params.autoplayDisableOnInteraction) s.stopAutoplay();
  3305. // Return page scroll on edge positions
  3306. if (position === 0 || position === s.maxTranslate()) return;
  3307. }
  3308. if (e.preventDefault) e.preventDefault();
  3309. else e.returnValue = false;
  3310. return false;
  3311. }
  3312. s.disableMousewheelControl = function () {
  3313. if (!s.mousewheel.event) return false;
  3314. var target = s.container;
  3315. if (s.params.mousewheelEventsTarged !== 'container') {
  3316. target = $(s.params.mousewheelEventsTarged);
  3317. }
  3318. target.off(s.mousewheel.event, handleMousewheel);
  3319. return true;
  3320. };
  3321. s.enableMousewheelControl = function () {
  3322. if (!s.mousewheel.event) return false;
  3323. var target = s.container;
  3324. if (s.params.mousewheelEventsTarged !== 'container') {
  3325. target = $(s.params.mousewheelEventsTarged);
  3326. }
  3327. target.on(s.mousewheel.event, handleMousewheel);
  3328. return true;
  3329. };
  3330. /**
  3331. * Mouse wheel (and 2-finger trackpad) support on the web sucks. It is
  3332. * complicated, thus this doc is long and (hopefully) detailed enough to answer
  3333. * your questions.
  3334. *
  3335. * If you need to react to the mouse wheel in a predictable way, this code is
  3336. * like your bestest friend. * hugs *
  3337. *
  3338. * As of today, there are 4 DOM event types you can listen to:
  3339. *
  3340. * 'wheel' -- Chrome(31+), FF(17+), IE(9+)
  3341. * 'mousewheel' -- Chrome, IE(6+), Opera, Safari
  3342. * 'MozMousePixelScroll' -- FF(3.5 only!) (2010-2013) -- don't bother!
  3343. * 'DOMMouseScroll' -- FF(0.9.7+) since 2003
  3344. *
  3345. * So what to do? The is the best:
  3346. *
  3347. * normalizeWheel.getEventType();
  3348. *
  3349. * In your event callback, use this code to get sane interpretation of the
  3350. * deltas. This code will return an object with properties:
  3351. *
  3352. * spinX -- normalized spin speed (use for zoom) - x plane
  3353. * spinY -- " - y plane
  3354. * pixelX -- normalized distance (to pixels) - x plane
  3355. * pixelY -- " - y plane
  3356. *
  3357. * Wheel values are provided by the browser assuming you are using the wheel to
  3358. * scroll a web page by a number of lines or pixels (or pages). Values can vary
  3359. * significantly on different platforms and browsers, forgetting that you can
  3360. * scroll at different speeds. Some devices (like trackpads) emit more events
  3361. * at smaller increments with fine granularity, and some emit massive jumps with
  3362. * linear speed or acceleration.
  3363. *
  3364. * This code does its best to normalize the deltas for you:
  3365. *
  3366. * - spin is trying to normalize how far the wheel was spun (or trackpad
  3367. * dragged). This is super useful for zoom support where you want to
  3368. * throw away the chunky scroll steps on the PC and make those equal to
  3369. * the slow and smooth tiny steps on the Mac. Key data: This code tries to
  3370. * resolve a single slow step on a wheel to 1.
  3371. *
  3372. * - pixel is normalizing the desired scroll delta in pixel units. You'll
  3373. * get the crazy differences between browsers, but at least it'll be in
  3374. * pixels!
  3375. *
  3376. * - positive value indicates scrolling DOWN/RIGHT, negative UP/LEFT. This
  3377. * should translate to positive value zooming IN, negative zooming OUT.
  3378. * This matches the newer 'wheel' event.
  3379. *
  3380. * Why are there spinX, spinY (or pixels)?
  3381. *
  3382. * - spinX is a 2-finger side drag on the trackpad, and a shift + wheel turn
  3383. * with a mouse. It results in side-scrolling in the browser by default.
  3384. *
  3385. * - spinY is what you expect -- it's the classic axis of a mouse wheel.
  3386. *
  3387. * - I dropped spinZ/pixelZ. It is supported by the DOM 3 'wheel' event and
  3388. * probably is by browsers in conjunction with fancy 3D controllers .. but
  3389. * you know.
  3390. *
  3391. * Implementation info:
  3392. *
  3393. * Examples of 'wheel' event if you scroll slowly (down) by one step with an
  3394. * average mouse:
  3395. *
  3396. * OS X + Chrome (mouse) - 4 pixel delta (wheelDelta -120)
  3397. * OS X + Safari (mouse) - N/A pixel delta (wheelDelta -12)
  3398. * OS X + Firefox (mouse) - 0.1 line delta (wheelDelta N/A)
  3399. * Win8 + Chrome (mouse) - 100 pixel delta (wheelDelta -120)
  3400. * Win8 + Firefox (mouse) - 3 line delta (wheelDelta -120)
  3401. *
  3402. * On the trackpad:
  3403. *
  3404. * OS X + Chrome (trackpad) - 2 pixel delta (wheelDelta -6)
  3405. * OS X + Firefox (trackpad) - 1 pixel delta (wheelDelta N/A)
  3406. *
  3407. * On other/older browsers.. it's more complicated as there can be multiple and
  3408. * also missing delta values.
  3409. *
  3410. * The 'wheel' event is more standard:
  3411. *
  3412. * http://www.w3.org/TR/DOM-Level-3-Events/#events-wheelevents
  3413. *
  3414. * The basics is that it includes a unit, deltaMode (pixels, lines, pages), and
  3415. * deltaX, deltaY and deltaZ. Some browsers provide other values to maintain
  3416. * backward compatibility with older events. Those other values help us
  3417. * better normalize spin speed. Example of what the browsers provide:
  3418. *
  3419. * | event.wheelDelta | event.detail
  3420. * ------------------+------------------+--------------
  3421. * Safari v5/OS X | -120 | 0
  3422. * Safari v5/Win7 | -120 | 0
  3423. * Chrome v17/OS X | -120 | 0
  3424. * Chrome v17/Win7 | -120 | 0
  3425. * IE9/Win7 | -120 | undefined
  3426. * Firefox v4/OS X | undefined | 1
  3427. * Firefox v4/Win7 | undefined | 3
  3428. *
  3429. */
  3430. function normalizeWheel( /*object*/ event ) /*object*/ {
  3431. // Reasonable defaults
  3432. var PIXEL_STEP = 10;
  3433. var LINE_HEIGHT = 40;
  3434. var PAGE_HEIGHT = 800;
  3435. var sX = 0, sY = 0, // spinX, spinY
  3436. pX = 0, pY = 0; // pixelX, pixelY
  3437. // Legacy
  3438. if( 'detail' in event ) {
  3439. sY = event.detail;
  3440. }
  3441. if( 'wheelDelta' in event ) {
  3442. sY = -event.wheelDelta / 120;
  3443. }
  3444. if( 'wheelDeltaY' in event ) {
  3445. sY = -event.wheelDeltaY / 120;
  3446. }
  3447. if( 'wheelDeltaX' in event ) {
  3448. sX = -event.wheelDeltaX / 120;
  3449. }
  3450. // side scrolling on FF with DOMMouseScroll
  3451. if( 'axis' in event && event.axis === event.HORIZONTAL_AXIS ) {
  3452. sX = sY;
  3453. sY = 0;
  3454. }
  3455. pX = sX * PIXEL_STEP;
  3456. pY = sY * PIXEL_STEP;
  3457. if( 'deltaY' in event ) {
  3458. pY = event.deltaY;
  3459. }
  3460. if( 'deltaX' in event ) {
  3461. pX = event.deltaX;
  3462. }
  3463. if( (pX || pY) && event.deltaMode ) {
  3464. if( event.deltaMode === 1 ) { // delta in LINE units
  3465. pX *= LINE_HEIGHT;
  3466. pY *= LINE_HEIGHT;
  3467. } else { // delta in PAGE units
  3468. pX *= PAGE_HEIGHT;
  3469. pY *= PAGE_HEIGHT;
  3470. }
  3471. }
  3472. // Fall-back if spin cannot be determined
  3473. if( pX && !sX ) {
  3474. sX = (pX < 1) ? -1 : 1;
  3475. }
  3476. if( pY && !sY ) {
  3477. sY = (pY < 1) ? -1 : 1;
  3478. }
  3479. return {
  3480. spinX: sX,
  3481. spinY: sY,
  3482. pixelX: pX,
  3483. pixelY: pY
  3484. };
  3485. }
  3486. /*=========================
  3487. Parallax
  3488. ===========================*/
  3489. function setParallaxTransform(el, progress) {
  3490. el = $(el);
  3491. var p, pX, pY;
  3492. var rtlFactor = s.rtl ? -1 : 1;
  3493. p = el.attr('data-swiper-parallax') || '0';
  3494. pX = el.attr('data-swiper-parallax-x');
  3495. pY = el.attr('data-swiper-parallax-y');
  3496. if (pX || pY) {
  3497. pX = pX || '0';
  3498. pY = pY || '0';
  3499. }
  3500. else {
  3501. if (s.isHorizontal()) {
  3502. pX = p;
  3503. pY = '0';
  3504. }
  3505. else {
  3506. pY = p;
  3507. pX = '0';
  3508. }
  3509. }
  3510. if ((pX).indexOf('%') >= 0) {
  3511. pX = parseInt(pX, 10) * progress * rtlFactor + '%';
  3512. }
  3513. else {
  3514. pX = pX * progress * rtlFactor + 'px' ;
  3515. }
  3516. if ((pY).indexOf('%') >= 0) {
  3517. pY = parseInt(pY, 10) * progress + '%';
  3518. }
  3519. else {
  3520. pY = pY * progress + 'px' ;
  3521. }
  3522. el.transform('translate3d(' + pX + ', ' + pY + ',0px)');
  3523. }
  3524. s.parallax = {
  3525. setTranslate: function () {
  3526. s.container.children('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y]').each(function(){
  3527. setParallaxTransform(this, s.progress);
  3528. });
  3529. s.slides.each(function () {
  3530. var slide = $(this);
  3531. slide.find('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y]').each(function () {
  3532. var progress = Math.min(Math.max(slide[0].progress, -1), 1);
  3533. setParallaxTransform(this, progress);
  3534. });
  3535. });
  3536. },
  3537. setTransition: function (duration) {
  3538. if (typeof duration === 'undefined') duration = s.params.speed;
  3539. s.container.find('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y]').each(function(){
  3540. var el = $(this);
  3541. var parallaxDuration = parseInt(el.attr('data-swiper-parallax-duration'), 10) || duration;
  3542. if (duration === 0) parallaxDuration = 0;
  3543. el.transition(parallaxDuration);
  3544. });
  3545. }
  3546. };
  3547. /*=========================
  3548. Zoom
  3549. ===========================*/
  3550. s.zoom = {
  3551. // "Global" Props
  3552. scale: 1,
  3553. currentScale: 1,
  3554. isScaling: false,
  3555. gesture: {
  3556. slide: undefined,
  3557. slideWidth: undefined,
  3558. slideHeight: undefined,
  3559. image: undefined,
  3560. imageWrap: undefined,
  3561. zoomMax: s.params.zoomMax
  3562. },
  3563. image: {
  3564. isTouched: undefined,
  3565. isMoved: undefined,
  3566. currentX: undefined,
  3567. currentY: undefined,
  3568. minX: undefined,
  3569. minY: undefined,
  3570. maxX: undefined,
  3571. maxY: undefined,
  3572. width: undefined,
  3573. height: undefined,
  3574. startX: undefined,
  3575. startY: undefined,
  3576. touchesStart: {},
  3577. touchesCurrent: {}
  3578. },
  3579. velocity: {
  3580. x: undefined,
  3581. y: undefined,
  3582. prevPositionX: undefined,
  3583. prevPositionY: undefined,
  3584. prevTime: undefined
  3585. },
  3586. // Calc Scale From Multi-touches
  3587. getDistanceBetweenTouches: function (e) {
  3588. if (e.targetTouches.length < 2) return 1;
  3589. var x1 = e.targetTouches[0].pageX,
  3590. y1 = e.targetTouches[0].pageY,
  3591. x2 = e.targetTouches[1].pageX,
  3592. y2 = e.targetTouches[1].pageY;
  3593. var distance = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
  3594. return distance;
  3595. },
  3596. // Events
  3597. onGestureStart: function (e) {
  3598. var z = s.zoom;
  3599. if (!s.support.gestures) {
  3600. if (e.type !== 'touchstart' || e.type === 'touchstart' && e.targetTouches.length < 2) {
  3601. return;
  3602. }
  3603. z.gesture.scaleStart = z.getDistanceBetweenTouches(e);
  3604. }
  3605. if (!z.gesture.slide || !z.gesture.slide.length) {
  3606. z.gesture.slide = $(this);
  3607. if (z.gesture.slide.length === 0) z.gesture.slide = s.slides.eq(s.activeIndex);
  3608. z.gesture.image = z.gesture.slide.find('img, svg, canvas');
  3609. z.gesture.imageWrap = z.gesture.image.parent('.' + s.params.zoomContainerClass);
  3610. z.gesture.zoomMax = z.gesture.imageWrap.attr('data-swiper-zoom') || s.params.zoomMax ;
  3611. if (z.gesture.imageWrap.length === 0) {
  3612. z.gesture.image = undefined;
  3613. return;
  3614. }
  3615. }
  3616. z.gesture.image.transition(0);
  3617. z.isScaling = true;
  3618. },
  3619. onGestureChange: function (e) {
  3620. var z = s.zoom;
  3621. if (!s.support.gestures) {
  3622. if (e.type !== 'touchmove' || e.type === 'touchmove' && e.targetTouches.length < 2) {
  3623. return;
  3624. }
  3625. z.gesture.scaleMove = z.getDistanceBetweenTouches(e);
  3626. }
  3627. if (!z.gesture.image || z.gesture.image.length === 0) return;
  3628. if (s.support.gestures) {
  3629. z.scale = e.scale * z.currentScale;
  3630. }
  3631. else {
  3632. z.scale = (z.gesture.scaleMove / z.gesture.scaleStart) * z.currentScale;
  3633. }
  3634. if (z.scale > z.gesture.zoomMax) {
  3635. z.scale = z.gesture.zoomMax - 1 + Math.pow((z.scale - z.gesture.zoomMax + 1), 0.5);
  3636. }
  3637. if (z.scale < s.params.zoomMin) {
  3638. z.scale = s.params.zoomMin + 1 - Math.pow((s.params.zoomMin - z.scale + 1), 0.5);
  3639. }
  3640. z.gesture.image.transform('translate3d(0,0,0) scale(' + z.scale + ')');
  3641. },
  3642. onGestureEnd: function (e) {
  3643. var z = s.zoom;
  3644. if (!s.support.gestures) {
  3645. if (e.type !== 'touchend' || e.type === 'touchend' && e.changedTouches.length < 2) {
  3646. return;
  3647. }
  3648. }
  3649. if (!z.gesture.image || z.gesture.image.length === 0) return;
  3650. z.scale = Math.max(Math.min(z.scale, z.gesture.zoomMax), s.params.zoomMin);
  3651. z.gesture.image.transition(s.params.speed).transform('translate3d(0,0,0) scale(' + z.scale + ')');
  3652. z.currentScale = z.scale;
  3653. z.isScaling = false;
  3654. if (z.scale === 1) z.gesture.slide = undefined;
  3655. },
  3656. onTouchStart: function (s, e) {
  3657. var z = s.zoom;
  3658. if (!z.gesture.image || z.gesture.image.length === 0) return;
  3659. if (z.image.isTouched) return;
  3660. if (s.device.os === 'android') e.preventDefault();
  3661. z.image.isTouched = true;
  3662. z.image.touchesStart.x = e.type === 'touchstart' ? e.targetTouches[0].pageX : e.pageX;
  3663. z.image.touchesStart.y = e.type === 'touchstart' ? e.targetTouches[0].pageY : e.pageY;
  3664. },
  3665. onTouchMove: function (e) {
  3666. var z = s.zoom;
  3667. if (!z.gesture.image || z.gesture.image.length === 0) return;
  3668. s.allowClick = false;
  3669. if (!z.image.isTouched || !z.gesture.slide) return;
  3670. if (!z.image.isMoved) {
  3671. z.image.width = z.gesture.image[0].offsetWidth;
  3672. z.image.height = z.gesture.image[0].offsetHeight;
  3673. z.image.startX = s.getTranslate(z.gesture.imageWrap[0], 'x') || 0;
  3674. z.image.startY = s.getTranslate(z.gesture.imageWrap[0], 'y') || 0;
  3675. z.gesture.slideWidth = z.gesture.slide[0].offsetWidth;
  3676. z.gesture.slideHeight = z.gesture.slide[0].offsetHeight;
  3677. z.gesture.imageWrap.transition(0);
  3678. if (s.rtl) z.image.startX = -z.image.startX;
  3679. if (s.rtl) z.image.startY = -z.image.startY;
  3680. }
  3681. // Define if we need image drag
  3682. var scaledWidth = z.image.width * z.scale;
  3683. var scaledHeight = z.image.height * z.scale;
  3684. if (scaledWidth < z.gesture.slideWidth && scaledHeight < z.gesture.slideHeight) return;
  3685. z.image.minX = Math.min((z.gesture.slideWidth / 2 - scaledWidth / 2), 0);
  3686. z.image.maxX = -z.image.minX;
  3687. z.image.minY = Math.min((z.gesture.slideHeight / 2 - scaledHeight / 2), 0);
  3688. z.image.maxY = -z.image.minY;
  3689. z.image.touchesCurrent.x = e.type === 'touchmove' ? e.targetTouches[0].pageX : e.pageX;
  3690. z.image.touchesCurrent.y = e.type === 'touchmove' ? e.targetTouches[0].pageY : e.pageY;
  3691. if (!z.image.isMoved && !z.isScaling) {
  3692. if (s.isHorizontal() &&
  3693. (Math.floor(z.image.minX) === Math.floor(z.image.startX) && z.image.touchesCurrent.x < z.image.touchesStart.x) ||
  3694. (Math.floor(z.image.maxX) === Math.floor(z.image.startX) && z.image.touchesCurrent.x > z.image.touchesStart.x)
  3695. ) {
  3696. z.image.isTouched = false;
  3697. return;
  3698. }
  3699. else if (!s.isHorizontal() &&
  3700. (Math.floor(z.image.minY) === Math.floor(z.image.startY) && z.image.touchesCurrent.y < z.image.touchesStart.y) ||
  3701. (Math.floor(z.image.maxY) === Math.floor(z.image.startY) && z.image.touchesCurrent.y > z.image.touchesStart.y)
  3702. ) {
  3703. z.image.isTouched = false;
  3704. return;
  3705. }
  3706. }
  3707. e.preventDefault();
  3708. e.stopPropagation();
  3709. z.image.isMoved = true;
  3710. z.image.currentX = z.image.touchesCurrent.x - z.image.touchesStart.x + z.image.startX;
  3711. z.image.currentY = z.image.touchesCurrent.y - z.image.touchesStart.y + z.image.startY;
  3712. if (z.image.currentX < z.image.minX) {
  3713. z.image.currentX = z.image.minX + 1 - Math.pow((z.image.minX - z.image.currentX + 1), 0.8);
  3714. }
  3715. if (z.image.currentX > z.image.maxX) {
  3716. z.image.currentX = z.image.maxX - 1 + Math.pow((z.image.currentX - z.image.maxX + 1), 0.8);
  3717. }
  3718. if (z.image.currentY < z.image.minY) {
  3719. z.image.currentY = z.image.minY + 1 - Math.pow((z.image.minY - z.image.currentY + 1), 0.8);
  3720. }
  3721. if (z.image.currentY > z.image.maxY) {
  3722. z.image.currentY = z.image.maxY - 1 + Math.pow((z.image.currentY - z.image.maxY + 1), 0.8);
  3723. }
  3724. //Velocity
  3725. if (!z.velocity.prevPositionX) z.velocity.prevPositionX = z.image.touchesCurrent.x;
  3726. if (!z.velocity.prevPositionY) z.velocity.prevPositionY = z.image.touchesCurrent.y;
  3727. if (!z.velocity.prevTime) z.velocity.prevTime = Date.now();
  3728. z.velocity.x = (z.image.touchesCurrent.x - z.velocity.prevPositionX) / (Date.now() - z.velocity.prevTime) / 2;
  3729. z.velocity.y = (z.image.touchesCurrent.y - z.velocity.prevPositionY) / (Date.now() - z.velocity.prevTime) / 2;
  3730. if (Math.abs(z.image.touchesCurrent.x - z.velocity.prevPositionX) < 2) z.velocity.x = 0;
  3731. if (Math.abs(z.image.touchesCurrent.y - z.velocity.prevPositionY) < 2) z.velocity.y = 0;
  3732. z.velocity.prevPositionX = z.image.touchesCurrent.x;
  3733. z.velocity.prevPositionY = z.image.touchesCurrent.y;
  3734. z.velocity.prevTime = Date.now();
  3735. z.gesture.imageWrap.transform('translate3d(' + z.image.currentX + 'px, ' + z.image.currentY + 'px,0)');
  3736. },
  3737. onTouchEnd: function (s, e) {
  3738. var z = s.zoom;
  3739. if (!z.gesture.image || z.gesture.image.length === 0) return;
  3740. if (!z.image.isTouched || !z.image.isMoved) {
  3741. z.image.isTouched = false;
  3742. z.image.isMoved = false;
  3743. return;
  3744. }
  3745. z.image.isTouched = false;
  3746. z.image.isMoved = false;
  3747. var momentumDurationX = 300;
  3748. var momentumDurationY = 300;
  3749. var momentumDistanceX = z.velocity.x * momentumDurationX;
  3750. var newPositionX = z.image.currentX + momentumDistanceX;
  3751. var momentumDistanceY = z.velocity.y * momentumDurationY;
  3752. var newPositionY = z.image.currentY + momentumDistanceY;
  3753. //Fix duration
  3754. if (z.velocity.x !== 0) momentumDurationX = Math.abs((newPositionX - z.image.currentX) / z.velocity.x);
  3755. if (z.velocity.y !== 0) momentumDurationY = Math.abs((newPositionY - z.image.currentY) / z.velocity.y);
  3756. var momentumDuration = Math.max(momentumDurationX, momentumDurationY);
  3757. z.image.currentX = newPositionX;
  3758. z.image.currentY = newPositionY;
  3759. // Define if we need image drag
  3760. var scaledWidth = z.image.width * z.scale;
  3761. var scaledHeight = z.image.height * z.scale;
  3762. z.image.minX = Math.min((z.gesture.slideWidth / 2 - scaledWidth / 2), 0);
  3763. z.image.maxX = -z.image.minX;
  3764. z.image.minY = Math.min((z.gesture.slideHeight / 2 - scaledHeight / 2), 0);
  3765. z.image.maxY = -z.image.minY;
  3766. z.image.currentX = Math.max(Math.min(z.image.currentX, z.image.maxX), z.image.minX);
  3767. z.image.currentY = Math.max(Math.min(z.image.currentY, z.image.maxY), z.image.minY);
  3768. z.gesture.imageWrap.transition(momentumDuration).transform('translate3d(' + z.image.currentX + 'px, ' + z.image.currentY + 'px,0)');
  3769. },
  3770. onTransitionEnd: function (s) {
  3771. var z = s.zoom;
  3772. if (z.gesture.slide && s.previousIndex !== s.activeIndex) {
  3773. z.gesture.image.transform('translate3d(0,0,0) scale(1)');
  3774. z.gesture.imageWrap.transform('translate3d(0,0,0)');
  3775. z.gesture.slide = z.gesture.image = z.gesture.imageWrap = undefined;
  3776. z.scale = z.currentScale = 1;
  3777. }
  3778. },
  3779. // Toggle Zoom
  3780. toggleZoom: function (s, e) {
  3781. var z = s.zoom;
  3782. if (!z.gesture.slide) {
  3783. z.gesture.slide = s.clickedSlide ? $(s.clickedSlide) : s.slides.eq(s.activeIndex);
  3784. z.gesture.image = z.gesture.slide.find('img, svg, canvas');
  3785. z.gesture.imageWrap = z.gesture.image.parent('.' + s.params.zoomContainerClass);
  3786. }
  3787. if (!z.gesture.image || z.gesture.image.length === 0) return;
  3788. var touchX, touchY, offsetX, offsetY, diffX, diffY, translateX, translateY, imageWidth, imageHeight, scaledWidth, scaledHeight, translateMinX, translateMinY, translateMaxX, translateMaxY, slideWidth, slideHeight;
  3789. if (typeof z.image.touchesStart.x === 'undefined' && e) {
  3790. touchX = e.type === 'touchend' ? e.changedTouches[0].pageX : e.pageX;
  3791. touchY = e.type === 'touchend' ? e.changedTouches[0].pageY : e.pageY;
  3792. }
  3793. else {
  3794. touchX = z.image.touchesStart.x;
  3795. touchY = z.image.touchesStart.y;
  3796. }
  3797. if (z.scale && z.scale !== 1) {
  3798. // Zoom Out
  3799. z.scale = z.currentScale = 1;
  3800. z.gesture.imageWrap.transition(300).transform('translate3d(0,0,0)');
  3801. z.gesture.image.transition(300).transform('translate3d(0,0,0) scale(1)');
  3802. z.gesture.slide = undefined;
  3803. }
  3804. else {
  3805. // Zoom In
  3806. z.scale = z.currentScale = z.gesture.imageWrap.attr('data-swiper-zoom') || s.params.zoomMax;
  3807. if (e) {
  3808. slideWidth = z.gesture.slide[0].offsetWidth;
  3809. slideHeight = z.gesture.slide[0].offsetHeight;
  3810. offsetX = z.gesture.slide.offset().left;
  3811. offsetY = z.gesture.slide.offset().top;
  3812. diffX = offsetX + slideWidth/2 - touchX;
  3813. diffY = offsetY + slideHeight/2 - touchY;
  3814. imageWidth = z.gesture.image[0].offsetWidth;
  3815. imageHeight = z.gesture.image[0].offsetHeight;
  3816. scaledWidth = imageWidth * z.scale;
  3817. scaledHeight = imageHeight * z.scale;
  3818. translateMinX = Math.min((slideWidth / 2 - scaledWidth / 2), 0);
  3819. translateMinY = Math.min((slideHeight / 2 - scaledHeight / 2), 0);
  3820. translateMaxX = -translateMinX;
  3821. translateMaxY = -translateMinY;
  3822. translateX = diffX * z.scale;
  3823. translateY = diffY * z.scale;
  3824. if (translateX < translateMinX) {
  3825. translateX = translateMinX;
  3826. }
  3827. if (translateX > translateMaxX) {
  3828. translateX = translateMaxX;
  3829. }
  3830. if (translateY < translateMinY) {
  3831. translateY = translateMinY;
  3832. }
  3833. if (translateY > translateMaxY) {
  3834. translateY = translateMaxY;
  3835. }
  3836. }
  3837. else {
  3838. translateX = 0;
  3839. translateY = 0;
  3840. }
  3841. z.gesture.imageWrap.transition(300).transform('translate3d(' + translateX + 'px, ' + translateY + 'px,0)');
  3842. z.gesture.image.transition(300).transform('translate3d(0,0,0) scale(' + z.scale + ')');
  3843. }
  3844. },
  3845. // Attach/Detach Events
  3846. attachEvents: function (detach) {
  3847. var action = detach ? 'off' : 'on';
  3848. if (s.params.zoom) {
  3849. var target = s.slides;
  3850. var passiveListener = s.touchEvents.start === 'touchstart' && s.support.passiveListener && s.params.passiveListeners ? {passive: true, capture: false} : false;
  3851. // Scale image
  3852. if (s.support.gestures) {
  3853. s.slides[action]('gesturestart', s.zoom.onGestureStart, passiveListener);
  3854. s.slides[action]('gesturechange', s.zoom.onGestureChange, passiveListener);
  3855. s.slides[action]('gestureend', s.zoom.onGestureEnd, passiveListener);
  3856. }
  3857. else if (s.touchEvents.start === 'touchstart') {
  3858. s.slides[action](s.touchEvents.start, s.zoom.onGestureStart, passiveListener);
  3859. s.slides[action](s.touchEvents.move, s.zoom.onGestureChange, passiveListener);
  3860. s.slides[action](s.touchEvents.end, s.zoom.onGestureEnd, passiveListener);
  3861. }
  3862. // Move image
  3863. s[action]('touchStart', s.zoom.onTouchStart);
  3864. s.slides.each(function (index, slide){
  3865. if ($(slide).find('.' + s.params.zoomContainerClass).length > 0) {
  3866. $(slide)[action](s.touchEvents.move, s.zoom.onTouchMove);
  3867. }
  3868. });
  3869. s[action]('touchEnd', s.zoom.onTouchEnd);
  3870. // Scale Out
  3871. s[action]('transitionEnd', s.zoom.onTransitionEnd);
  3872. if (s.params.zoomToggle) {
  3873. s.on('doubleTap', s.zoom.toggleZoom);
  3874. }
  3875. }
  3876. },
  3877. init: function () {
  3878. s.zoom.attachEvents();
  3879. },
  3880. destroy: function () {
  3881. s.zoom.attachEvents(true);
  3882. }
  3883. };
  3884. /*=========================
  3885. Plugins API. Collect all and init all plugins
  3886. ===========================*/
  3887. s._plugins = [];
  3888. for (var plugin in s.plugins) {
  3889. var p = s.plugins[plugin](s, s.params[plugin]);
  3890. if (p) s._plugins.push(p);
  3891. }
  3892. // Method to call all plugins event/method
  3893. s.callPlugins = function (eventName) {
  3894. for (var i = 0; i < s._plugins.length; i++) {
  3895. if (eventName in s._plugins[i]) {
  3896. s._plugins[i][eventName](arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
  3897. }
  3898. }
  3899. };
  3900. /*=========================
  3901. Events/Callbacks/Plugins Emitter
  3902. ===========================*/
  3903. function normalizeEventName (eventName) {
  3904. if (eventName.indexOf('on') !== 0) {
  3905. if (eventName[0] !== eventName[0].toUpperCase()) {
  3906. eventName = 'on' + eventName[0].toUpperCase() + eventName.substring(1);
  3907. }
  3908. else {
  3909. eventName = 'on' + eventName;
  3910. }
  3911. }
  3912. return eventName;
  3913. }
  3914. s.emitterEventListeners = {
  3915. };
  3916. s.emit = function (eventName) {
  3917. // Trigger callbacks
  3918. if (s.params[eventName]) {
  3919. s.params[eventName](arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
  3920. }
  3921. var i;
  3922. // Trigger events
  3923. if (s.emitterEventListeners[eventName]) {
  3924. for (i = 0; i < s.emitterEventListeners[eventName].length; i++) {
  3925. s.emitterEventListeners[eventName][i](arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
  3926. }
  3927. }
  3928. // Trigger plugins
  3929. if (s.callPlugins) s.callPlugins(eventName, arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
  3930. };
  3931. s.on = function (eventName, handler) {
  3932. eventName = normalizeEventName(eventName);
  3933. if (!s.emitterEventListeners[eventName]) s.emitterEventListeners[eventName] = [];
  3934. s.emitterEventListeners[eventName].push(handler);
  3935. return s;
  3936. };
  3937. s.off = function (eventName, handler) {
  3938. var i;
  3939. eventName = normalizeEventName(eventName);
  3940. if (typeof handler === 'undefined') {
  3941. // Remove all handlers for such event
  3942. s.emitterEventListeners[eventName] = [];
  3943. return s;
  3944. }
  3945. if (!s.emitterEventListeners[eventName] || s.emitterEventListeners[eventName].length === 0) return;
  3946. for (i = 0; i < s.emitterEventListeners[eventName].length; i++) {
  3947. if(s.emitterEventListeners[eventName][i] === handler) s.emitterEventListeners[eventName].splice(i, 1);
  3948. }
  3949. return s;
  3950. };
  3951. s.once = function (eventName, handler) {
  3952. eventName = normalizeEventName(eventName);
  3953. var _handler = function () {
  3954. handler(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4]);
  3955. s.off(eventName, _handler);
  3956. };
  3957. s.on(eventName, _handler);
  3958. return s;
  3959. };
  3960. // Accessibility tools
  3961. s.a11y = {
  3962. makeFocusable: function ($el) {
  3963. $el.attr('tabIndex', '0');
  3964. return $el;
  3965. },
  3966. addRole: function ($el, role) {
  3967. $el.attr('role', role);
  3968. return $el;
  3969. },
  3970. addLabel: function ($el, label) {
  3971. $el.attr('aria-label', label);
  3972. return $el;
  3973. },
  3974. disable: function ($el) {
  3975. $el.attr('aria-disabled', true);
  3976. return $el;
  3977. },
  3978. enable: function ($el) {
  3979. $el.attr('aria-disabled', false);
  3980. return $el;
  3981. },
  3982. onEnterKey: function (event) {
  3983. if (event.keyCode !== 13) return;
  3984. if ($(event.target).is(s.params.nextButton)) {
  3985. s.onClickNext(event);
  3986. if (s.isEnd) {
  3987. s.a11y.notify(s.params.lastSlideMessage);
  3988. }
  3989. else {
  3990. s.a11y.notify(s.params.nextSlideMessage);
  3991. }
  3992. }
  3993. else if ($(event.target).is(s.params.prevButton)) {
  3994. s.onClickPrev(event);
  3995. if (s.isBeginning) {
  3996. s.a11y.notify(s.params.firstSlideMessage);
  3997. }
  3998. else {
  3999. s.a11y.notify(s.params.prevSlideMessage);
  4000. }
  4001. }
  4002. if ($(event.target).is('.' + s.params.bulletClass)) {
  4003. $(event.target)[0].click();
  4004. }
  4005. },
  4006. liveRegion: $('<span class="' + s.params.notificationClass + '" aria-live="assertive" aria-atomic="true"></span>'),
  4007. notify: function (message) {
  4008. var notification = s.a11y.liveRegion;
  4009. if (notification.length === 0) return;
  4010. notification.html('');
  4011. notification.html(message);
  4012. },
  4013. init: function () {
  4014. // Setup accessibility
  4015. if (s.params.nextButton && s.nextButton && s.nextButton.length > 0) {
  4016. s.a11y.makeFocusable(s.nextButton);
  4017. s.a11y.addRole(s.nextButton, 'button');
  4018. s.a11y.addLabel(s.nextButton, s.params.nextSlideMessage);
  4019. }
  4020. if (s.params.prevButton && s.prevButton && s.prevButton.length > 0) {
  4021. s.a11y.makeFocusable(s.prevButton);
  4022. s.a11y.addRole(s.prevButton, 'button');
  4023. s.a11y.addLabel(s.prevButton, s.params.prevSlideMessage);
  4024. }
  4025. $(s.container).append(s.a11y.liveRegion);
  4026. },
  4027. initPagination: function () {
  4028. if (s.params.pagination && s.params.paginationClickable && s.bullets && s.bullets.length) {
  4029. s.bullets.each(function () {
  4030. var bullet = $(this);
  4031. s.a11y.makeFocusable(bullet);
  4032. s.a11y.addRole(bullet, 'button');
  4033. s.a11y.addLabel(bullet, s.params.paginationBulletMessage.replace(/{{index}}/, bullet.index() + 1));
  4034. });
  4035. }
  4036. },
  4037. destroy: function () {
  4038. if (s.a11y.liveRegion && s.a11y.liveRegion.length > 0) s.a11y.liveRegion.remove();
  4039. }
  4040. };
  4041. /*=========================
  4042. Init/Destroy
  4043. ===========================*/
  4044. s.init = function () {
  4045. if (s.params.loop) s.createLoop();
  4046. s.updateContainerSize();
  4047. s.updateSlidesSize();
  4048. s.updatePagination();
  4049. if (s.params.scrollbar && s.scrollbar) {
  4050. s.scrollbar.set();
  4051. if (s.params.scrollbarDraggable) {
  4052. s.scrollbar.enableDraggable();
  4053. }
  4054. }
  4055. if (s.params.effect !== 'slide' && s.effects[s.params.effect]) {
  4056. if (!s.params.loop) s.updateProgress();
  4057. s.effects[s.params.effect].setTranslate();
  4058. }
  4059. if (s.params.loop) {
  4060. s.slideTo(s.params.initialSlide + s.loopedSlides, 0, s.params.runCallbacksOnInit);
  4061. }
  4062. else {
  4063. s.slideTo(s.params.initialSlide, 0, s.params.runCallbacksOnInit);
  4064. if (s.params.initialSlide === 0) {
  4065. if (s.parallax && s.params.parallax) s.parallax.setTranslate();
  4066. if (s.lazy && s.params.lazyLoading) {
  4067. s.lazy.load();
  4068. s.lazy.initialImageLoaded = true;
  4069. }
  4070. }
  4071. }
  4072. s.attachEvents();
  4073. if (s.params.observer && s.support.observer) {
  4074. s.initObservers();
  4075. }
  4076. if (s.params.preloadImages && !s.params.lazyLoading) {
  4077. s.preloadImages();
  4078. }
  4079. if (s.params.zoom && s.zoom) {
  4080. s.zoom.init();
  4081. }
  4082. if (s.params.autoplay) {
  4083. s.startAutoplay();
  4084. }
  4085. if (s.params.keyboardControl) {
  4086. if (s.enableKeyboardControl) s.enableKeyboardControl();
  4087. }
  4088. if (s.params.mousewheelControl) {
  4089. if (s.enableMousewheelControl) s.enableMousewheelControl();
  4090. }
  4091. // Deprecated hashnavReplaceState changed to replaceState for use in hashnav and history
  4092. if (s.params.hashnavReplaceState) {
  4093. s.params.replaceState = s.params.hashnavReplaceState;
  4094. }
  4095. if (s.params.history) {
  4096. if (s.history) s.history.init();
  4097. }
  4098. if (s.params.hashnav) {
  4099. if (s.hashnav) s.hashnav.init();
  4100. }
  4101. if (s.params.a11y && s.a11y) s.a11y.init();
  4102. s.emit('onInit', s);
  4103. };
  4104. // Cleanup dynamic styles
  4105. s.cleanupStyles = function () {
  4106. // Container
  4107. s.container.removeClass(s.classNames.join(' ')).removeAttr('style');
  4108. // Wrapper
  4109. s.wrapper.removeAttr('style');
  4110. // Slides
  4111. if (s.slides && s.slides.length) {
  4112. s.slides
  4113. .removeClass([
  4114. s.params.slideVisibleClass,
  4115. s.params.slideActiveClass,
  4116. s.params.slideNextClass,
  4117. s.params.slidePrevClass
  4118. ].join(' '))
  4119. .removeAttr('style')
  4120. .removeAttr('data-swiper-column')
  4121. .removeAttr('data-swiper-row');
  4122. }
  4123. // Pagination/Bullets
  4124. if (s.paginationContainer && s.paginationContainer.length) {
  4125. s.paginationContainer.removeClass(s.params.paginationHiddenClass);
  4126. }
  4127. if (s.bullets && s.bullets.length) {
  4128. s.bullets.removeClass(s.params.bulletActiveClass);
  4129. }
  4130. // Buttons
  4131. if (s.params.prevButton) $(s.params.prevButton).removeClass(s.params.buttonDisabledClass);
  4132. if (s.params.nextButton) $(s.params.nextButton).removeClass(s.params.buttonDisabledClass);
  4133. // Scrollbar
  4134. if (s.params.scrollbar && s.scrollbar) {
  4135. if (s.scrollbar.track && s.scrollbar.track.length) s.scrollbar.track.removeAttr('style');
  4136. if (s.scrollbar.drag && s.scrollbar.drag.length) s.scrollbar.drag.removeAttr('style');
  4137. }
  4138. };
  4139. // Destroy
  4140. s.destroy = function (deleteInstance, cleanupStyles) {
  4141. // Detach evebts
  4142. s.detachEvents();
  4143. // Stop autoplay
  4144. s.stopAutoplay();
  4145. // Disable draggable
  4146. if (s.params.scrollbar && s.scrollbar) {
  4147. if (s.params.scrollbarDraggable) {
  4148. s.scrollbar.disableDraggable();
  4149. }
  4150. }
  4151. // Destroy loop
  4152. if (s.params.loop) {
  4153. s.destroyLoop();
  4154. }
  4155. // Cleanup styles
  4156. if (cleanupStyles) {
  4157. s.cleanupStyles();
  4158. }
  4159. // Disconnect observer
  4160. s.disconnectObservers();
  4161. // Destroy zoom
  4162. if (s.params.zoom && s.zoom) {
  4163. s.zoom.destroy();
  4164. }
  4165. // Disable keyboard/mousewheel
  4166. if (s.params.keyboardControl) {
  4167. if (s.disableKeyboardControl) s.disableKeyboardControl();
  4168. }
  4169. if (s.params.mousewheelControl) {
  4170. if (s.disableMousewheelControl) s.disableMousewheelControl();
  4171. }
  4172. // Disable a11y
  4173. if (s.params.a11y && s.a11y) s.a11y.destroy();
  4174. // Delete history popstate
  4175. if (s.params.history && !s.params.replaceState) {
  4176. window.removeEventListener('popstate', s.history.setHistoryPopState);
  4177. }
  4178. if (s.params.hashnav && s.hashnav) {
  4179. s.hashnav.destroy();
  4180. }
  4181. // Destroy callback
  4182. s.emit('onDestroy');
  4183. // Delete instance
  4184. if (deleteInstance !== false) s = null;
  4185. };
  4186. s.init();
  4187. // Return swiper instance
  4188. return s;
  4189. };
  4190. /*==================================================
  4191. Prototype
  4192. ====================================================*/
  4193. Swiper.prototype = {
  4194. isSafari: (function () {
  4195. var ua = window.navigator.userAgent.toLowerCase();
  4196. return (ua.indexOf('safari') >= 0 && ua.indexOf('chrome') < 0 && ua.indexOf('android') < 0);
  4197. })(),
  4198. isUiWebView: /(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(window.navigator.userAgent),
  4199. isArray: function (arr) {
  4200. return Object.prototype.toString.apply(arr) === '[object Array]';
  4201. },
  4202. /*==================================================
  4203. Browser
  4204. ====================================================*/
  4205. browser: {
  4206. ie: window.navigator.pointerEnabled || window.navigator.msPointerEnabled,
  4207. ieTouch: (window.navigator.msPointerEnabled && window.navigator.msMaxTouchPoints > 1) || (window.navigator.pointerEnabled && window.navigator.maxTouchPoints > 1),
  4208. lteIE9: (function() {
  4209. // create temporary DIV
  4210. var div = document.createElement('div');
  4211. // add content to tmp DIV which is wrapped into the IE HTML conditional statement
  4212. div.innerHTML = '<!--[if lte IE 9]><i></i><![endif]-->';
  4213. // return true / false value based on what will browser render
  4214. return div.getElementsByTagName('i').length === 1;
  4215. })()
  4216. },
  4217. /*==================================================
  4218. Devices
  4219. ====================================================*/
  4220. device: (function () {
  4221. var ua = window.navigator.userAgent;
  4222. var android = ua.match(/(Android);?[\s\/]+([\d.]+)?/);
  4223. var ipad = ua.match(/(iPad).*OS\s([\d_]+)/);
  4224. var ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/);
  4225. var iphone = !ipad && ua.match(/(iPhone\sOS|iOS)\s([\d_]+)/);
  4226. return {
  4227. ios: ipad || iphone || ipod,
  4228. android: android
  4229. };
  4230. })(),
  4231. /*==================================================
  4232. Feature Detection
  4233. ====================================================*/
  4234. support: {
  4235. touch : (window.Modernizr && Modernizr.touch === true) || (function () {
  4236. return !!(('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch);
  4237. })(),
  4238. transforms3d : (window.Modernizr && Modernizr.csstransforms3d === true) || (function () {
  4239. var div = document.createElement('div').style;
  4240. return ('webkitPerspective' in div || 'MozPerspective' in div || 'OPerspective' in div || 'MsPerspective' in div || 'perspective' in div);
  4241. })(),
  4242. flexbox: (function () {
  4243. var div = document.createElement('div').style;
  4244. var styles = ('alignItems webkitAlignItems webkitBoxAlign msFlexAlign mozBoxAlign webkitFlexDirection msFlexDirection mozBoxDirection mozBoxOrient webkitBoxDirection webkitBoxOrient').split(' ');
  4245. for (var i = 0; i < styles.length; i++) {
  4246. if (styles[i] in div) return true;
  4247. }
  4248. })(),
  4249. observer: (function () {
  4250. return ('MutationObserver' in window || 'WebkitMutationObserver' in window);
  4251. })(),
  4252. passiveListener: (function () {
  4253. var supportsPassive = false;
  4254. try {
  4255. var opts = Object.defineProperty({}, 'passive', {
  4256. get: function() {
  4257. supportsPassive = true;
  4258. }
  4259. });
  4260. window.addEventListener('testPassiveListener', null, opts);
  4261. } catch (e) {}
  4262. return supportsPassive;
  4263. })(),
  4264. gestures: (function () {
  4265. return 'ongesturestart' in window;
  4266. })()
  4267. },
  4268. /*==================================================
  4269. Plugins
  4270. ====================================================*/
  4271. plugins: {}
  4272. };
  4273. /*===========================
  4274. Get Dom libraries
  4275. ===========================*/
  4276. var swiperDomPlugins = ['jQuery', 'Zepto', 'Dom7'];
  4277. for (var i = 0; i < swiperDomPlugins.length; i++) {
  4278. if (window[swiperDomPlugins[i]]) {
  4279. addLibraryPlugin(window[swiperDomPlugins[i]]);
  4280. }
  4281. }
  4282. // Required DOM Plugins
  4283. var domLib;
  4284. if (typeof Dom7 === 'undefined') {
  4285. domLib = window.Dom7 || window.Zepto || window.jQuery;
  4286. }
  4287. else {
  4288. domLib = Dom7;
  4289. }
  4290. /*===========================
  4291. Add .swiper plugin from Dom libraries
  4292. ===========================*/
  4293. function addLibraryPlugin(lib) {
  4294. lib.fn.swiper = function (params) {
  4295. var firstInstance;
  4296. lib(this).each(function () {
  4297. var s = new Swiper(this, params);
  4298. if (!firstInstance) firstInstance = s;
  4299. });
  4300. return firstInstance;
  4301. };
  4302. }
  4303. if (domLib) {
  4304. if (!('transitionEnd' in domLib.fn)) {
  4305. domLib.fn.transitionEnd = function (callback) {
  4306. var events = ['webkitTransitionEnd', 'transitionend', 'oTransitionEnd', 'MSTransitionEnd', 'msTransitionEnd'],
  4307. i, j, dom = this;
  4308. function fireCallBack(e) {
  4309. /*jshint validthis:true */
  4310. if (e.target !== this) return;
  4311. callback.call(this, e);
  4312. for (i = 0; i < events.length; i++) {
  4313. dom.off(events[i], fireCallBack);
  4314. }
  4315. }
  4316. if (callback) {
  4317. for (i = 0; i < events.length; i++) {
  4318. dom.on(events[i], fireCallBack);
  4319. }
  4320. }
  4321. return this;
  4322. };
  4323. }
  4324. if (!('transform' in domLib.fn)) {
  4325. domLib.fn.transform = function (transform) {
  4326. for (var i = 0; i < this.length; i++) {
  4327. var elStyle = this[i].style;
  4328. elStyle.webkitTransform = elStyle.MsTransform = elStyle.msTransform = elStyle.MozTransform = elStyle.OTransform = elStyle.transform = transform;
  4329. }
  4330. return this;
  4331. };
  4332. }
  4333. if (!('transition' in domLib.fn)) {
  4334. domLib.fn.transition = function (duration) {
  4335. if (typeof duration !== 'string') {
  4336. duration = duration + 'ms';
  4337. }
  4338. for (var i = 0; i < this.length; i++) {
  4339. var elStyle = this[i].style;
  4340. elStyle.webkitTransitionDuration = elStyle.MsTransitionDuration = elStyle.msTransitionDuration = elStyle.MozTransitionDuration = elStyle.OTransitionDuration = elStyle.transitionDuration = duration;
  4341. }
  4342. return this;
  4343. };
  4344. }
  4345. if (!('outerWidth' in domLib.fn)) {
  4346. domLib.fn.outerWidth = function (includeMargins) {
  4347. if (this.length > 0) {
  4348. if (includeMargins)
  4349. return this[0].offsetWidth + parseFloat(this.css('margin-right')) + parseFloat(this.css('margin-left'));
  4350. else
  4351. return this[0].offsetWidth;
  4352. }
  4353. else return null;
  4354. };
  4355. }
  4356. }
  4357. window.Swiper = Swiper;
  4358. })();
  4359. /*===========================
  4360. Swiper AMD Export
  4361. ===========================*/
  4362. if (typeof(module) !== 'undefined')
  4363. {
  4364. module.exports = window.Swiper;
  4365. }
  4366. else if (typeof define === 'function' && define.amd) {
  4367. define([], function () {
  4368. 'use strict';
  4369. return window.Swiper;
  4370. });
  4371. }
  4372. //# sourceMappingURL=maps/swiper.jquery.js.map