swiper.js 188 KB

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