swiper.esm.js 245 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662
  1. /**
  2. * Swiper 5.3.6
  3. * Most modern mobile touch slider and framework with hardware accelerated transitions
  4. * http://swiperjs.com
  5. *
  6. * Copyright 2014-2020 Vladimir Kharlampidi
  7. *
  8. * Released under the MIT License
  9. *
  10. * Released on: February 29, 2020
  11. */
  12. import { $, addClass, removeClass, hasClass, toggleClass, attr, removeAttr, data, transform, transition as transition$1, on, off, trigger, transitionEnd as transitionEnd$1, outerWidth, outerHeight, offset, css, each, html, text, is, index, eq, append, prepend, next, nextAll, prev, prevAll, parent, parents, closest, find, children, filter, remove, add, styles } from 'dom7/dist/dom7.modular';
  13. import { window, document as document$1 } from 'ssr-window';
  14. const Methods = {
  15. addClass,
  16. removeClass,
  17. hasClass,
  18. toggleClass,
  19. attr,
  20. removeAttr,
  21. data,
  22. transform,
  23. transition: transition$1,
  24. on,
  25. off,
  26. trigger,
  27. transitionEnd: transitionEnd$1,
  28. outerWidth,
  29. outerHeight,
  30. offset,
  31. css,
  32. each,
  33. html,
  34. text,
  35. is,
  36. index,
  37. eq,
  38. append,
  39. prepend,
  40. next,
  41. nextAll,
  42. prev,
  43. prevAll,
  44. parent,
  45. parents,
  46. closest,
  47. find,
  48. children,
  49. filter,
  50. remove,
  51. add,
  52. styles,
  53. };
  54. Object.keys(Methods).forEach((methodName) => {
  55. $.fn[methodName] = $.fn[methodName] || Methods[methodName];
  56. });
  57. const Utils = {
  58. deleteProps(obj) {
  59. const object = obj;
  60. Object.keys(object).forEach((key) => {
  61. try {
  62. object[key] = null;
  63. } catch (e) {
  64. // no getter for object
  65. }
  66. try {
  67. delete object[key];
  68. } catch (e) {
  69. // something got wrong
  70. }
  71. });
  72. },
  73. nextTick(callback, delay = 0) {
  74. return setTimeout(callback, delay);
  75. },
  76. now() {
  77. return Date.now();
  78. },
  79. getTranslate(el, axis = 'x') {
  80. let matrix;
  81. let curTransform;
  82. let transformMatrix;
  83. const curStyle = window.getComputedStyle(el, null);
  84. if (window.WebKitCSSMatrix) {
  85. curTransform = curStyle.transform || curStyle.webkitTransform;
  86. if (curTransform.split(',').length > 6) {
  87. curTransform = curTransform.split(', ').map((a) => a.replace(',', '.')).join(', ');
  88. }
  89. // Some old versions of Webkit choke when 'none' is passed; pass
  90. // empty string instead in this case
  91. transformMatrix = new window.WebKitCSSMatrix(curTransform === 'none' ? '' : curTransform);
  92. } else {
  93. transformMatrix = curStyle.MozTransform || curStyle.OTransform || curStyle.MsTransform || curStyle.msTransform || curStyle.transform || curStyle.getPropertyValue('transform').replace('translate(', 'matrix(1, 0, 0, 1,');
  94. matrix = transformMatrix.toString().split(',');
  95. }
  96. if (axis === 'x') {
  97. // Latest Chrome and webkits Fix
  98. if (window.WebKitCSSMatrix) curTransform = transformMatrix.m41;
  99. // Crazy IE10 Matrix
  100. else if (matrix.length === 16) curTransform = parseFloat(matrix[12]);
  101. // Normal Browsers
  102. else curTransform = parseFloat(matrix[4]);
  103. }
  104. if (axis === 'y') {
  105. // Latest Chrome and webkits Fix
  106. if (window.WebKitCSSMatrix) curTransform = transformMatrix.m42;
  107. // Crazy IE10 Matrix
  108. else if (matrix.length === 16) curTransform = parseFloat(matrix[13]);
  109. // Normal Browsers
  110. else curTransform = parseFloat(matrix[5]);
  111. }
  112. return curTransform || 0;
  113. },
  114. parseUrlQuery(url) {
  115. const query = {};
  116. let urlToParse = url || window.location.href;
  117. let i;
  118. let params;
  119. let param;
  120. let length;
  121. if (typeof urlToParse === 'string' && urlToParse.length) {
  122. urlToParse = urlToParse.indexOf('?') > -1 ? urlToParse.replace(/\S*\?/, '') : '';
  123. params = urlToParse.split('&').filter((paramsPart) => paramsPart !== '');
  124. length = params.length;
  125. for (i = 0; i < length; i += 1) {
  126. param = params[i].replace(/#\S+/g, '').split('=');
  127. query[decodeURIComponent(param[0])] = typeof param[1] === 'undefined' ? undefined : decodeURIComponent(param[1]) || '';
  128. }
  129. }
  130. return query;
  131. },
  132. isObject(o) {
  133. return typeof o === 'object' && o !== null && o.constructor && o.constructor === Object;
  134. },
  135. extend(...args) {
  136. const to = Object(args[0]);
  137. for (let i = 1; i < args.length; i += 1) {
  138. const nextSource = args[i];
  139. if (nextSource !== undefined && nextSource !== null) {
  140. const keysArray = Object.keys(Object(nextSource));
  141. for (let nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex += 1) {
  142. const nextKey = keysArray[nextIndex];
  143. const desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
  144. if (desc !== undefined && desc.enumerable) {
  145. if (Utils.isObject(to[nextKey]) && Utils.isObject(nextSource[nextKey])) {
  146. Utils.extend(to[nextKey], nextSource[nextKey]);
  147. } else if (!Utils.isObject(to[nextKey]) && Utils.isObject(nextSource[nextKey])) {
  148. to[nextKey] = {};
  149. Utils.extend(to[nextKey], nextSource[nextKey]);
  150. } else {
  151. to[nextKey] = nextSource[nextKey];
  152. }
  153. }
  154. }
  155. }
  156. }
  157. return to;
  158. },
  159. };
  160. const Support = (function Support() {
  161. return {
  162. touch: (window.Modernizr && window.Modernizr.touch === true) || (function checkTouch() {
  163. return !!((window.navigator.maxTouchPoints > 0) || ('ontouchstart' in window) || (window.DocumentTouch && document$1 instanceof window.DocumentTouch));
  164. }()),
  165. pointerEvents: !!window.PointerEvent && ('maxTouchPoints' in window.navigator) && window.navigator.maxTouchPoints > 0,
  166. observer: (function checkObserver() {
  167. return ('MutationObserver' in window || 'WebkitMutationObserver' in window);
  168. }()),
  169. passiveListener: (function checkPassiveListener() {
  170. let supportsPassive = false;
  171. try {
  172. const opts = Object.defineProperty({}, 'passive', {
  173. // eslint-disable-next-line
  174. get() {
  175. supportsPassive = true;
  176. },
  177. });
  178. window.addEventListener('testPassiveListener', null, opts);
  179. } catch (e) {
  180. // No support
  181. }
  182. return supportsPassive;
  183. }()),
  184. gestures: (function checkGestures() {
  185. return 'ongesturestart' in window;
  186. }()),
  187. };
  188. }());
  189. class SwiperClass {
  190. constructor(params = {}) {
  191. const self = this;
  192. self.params = params;
  193. // Events
  194. self.eventsListeners = {};
  195. if (self.params && self.params.on) {
  196. Object.keys(self.params.on).forEach((eventName) => {
  197. self.on(eventName, self.params.on[eventName]);
  198. });
  199. }
  200. }
  201. on(events, handler, priority) {
  202. const self = this;
  203. if (typeof handler !== 'function') return self;
  204. const method = priority ? 'unshift' : 'push';
  205. events.split(' ').forEach((event) => {
  206. if (!self.eventsListeners[event]) self.eventsListeners[event] = [];
  207. self.eventsListeners[event][method](handler);
  208. });
  209. return self;
  210. }
  211. once(events, handler, priority) {
  212. const self = this;
  213. if (typeof handler !== 'function') return self;
  214. function onceHandler(...args) {
  215. self.off(events, onceHandler);
  216. if (onceHandler.f7proxy) {
  217. delete onceHandler.f7proxy;
  218. }
  219. handler.apply(self, args);
  220. }
  221. onceHandler.f7proxy = handler;
  222. return self.on(events, onceHandler, priority);
  223. }
  224. off(events, handler) {
  225. const self = this;
  226. if (!self.eventsListeners) return self;
  227. events.split(' ').forEach((event) => {
  228. if (typeof handler === 'undefined') {
  229. self.eventsListeners[event] = [];
  230. } else if (self.eventsListeners[event] && self.eventsListeners[event].length) {
  231. self.eventsListeners[event].forEach((eventHandler, index) => {
  232. if (eventHandler === handler || (eventHandler.f7proxy && eventHandler.f7proxy === handler)) {
  233. self.eventsListeners[event].splice(index, 1);
  234. }
  235. });
  236. }
  237. });
  238. return self;
  239. }
  240. emit(...args) {
  241. const self = this;
  242. if (!self.eventsListeners) return self;
  243. let events;
  244. let data;
  245. let context;
  246. if (typeof args[0] === 'string' || Array.isArray(args[0])) {
  247. events = args[0];
  248. data = args.slice(1, args.length);
  249. context = self;
  250. } else {
  251. events = args[0].events;
  252. data = args[0].data;
  253. context = args[0].context || self;
  254. }
  255. const eventsArray = Array.isArray(events) ? events : events.split(' ');
  256. eventsArray.forEach((event) => {
  257. if (self.eventsListeners && self.eventsListeners[event]) {
  258. const handlers = [];
  259. self.eventsListeners[event].forEach((eventHandler) => {
  260. handlers.push(eventHandler);
  261. });
  262. handlers.forEach((eventHandler) => {
  263. eventHandler.apply(context, data);
  264. });
  265. }
  266. });
  267. return self;
  268. }
  269. useModulesParams(instanceParams) {
  270. const instance = this;
  271. if (!instance.modules) return;
  272. Object.keys(instance.modules).forEach((moduleName) => {
  273. const module = instance.modules[moduleName];
  274. // Extend params
  275. if (module.params) {
  276. Utils.extend(instanceParams, module.params);
  277. }
  278. });
  279. }
  280. useModules(modulesParams = {}) {
  281. const instance = this;
  282. if (!instance.modules) return;
  283. Object.keys(instance.modules).forEach((moduleName) => {
  284. const module = instance.modules[moduleName];
  285. const moduleParams = modulesParams[moduleName] || {};
  286. // Extend instance methods and props
  287. if (module.instance) {
  288. Object.keys(module.instance).forEach((modulePropName) => {
  289. const moduleProp = module.instance[modulePropName];
  290. if (typeof moduleProp === 'function') {
  291. instance[modulePropName] = moduleProp.bind(instance);
  292. } else {
  293. instance[modulePropName] = moduleProp;
  294. }
  295. });
  296. }
  297. // Add event listeners
  298. if (module.on && instance.on) {
  299. Object.keys(module.on).forEach((moduleEventName) => {
  300. instance.on(moduleEventName, module.on[moduleEventName]);
  301. });
  302. }
  303. // Module create callback
  304. if (module.create) {
  305. module.create.bind(instance)(moduleParams);
  306. }
  307. });
  308. }
  309. static set components(components) {
  310. const Class = this;
  311. if (!Class.use) return;
  312. Class.use(components);
  313. }
  314. static installModule(module, ...params) {
  315. const Class = this;
  316. if (!Class.prototype.modules) Class.prototype.modules = {};
  317. const name = module.name || (`${Object.keys(Class.prototype.modules).length}_${Utils.now()}`);
  318. Class.prototype.modules[name] = module;
  319. // Prototype
  320. if (module.proto) {
  321. Object.keys(module.proto).forEach((key) => {
  322. Class.prototype[key] = module.proto[key];
  323. });
  324. }
  325. // Class
  326. if (module.static) {
  327. Object.keys(module.static).forEach((key) => {
  328. Class[key] = module.static[key];
  329. });
  330. }
  331. // Callback
  332. if (module.install) {
  333. module.install.apply(Class, params);
  334. }
  335. return Class;
  336. }
  337. static use(module, ...params) {
  338. const Class = this;
  339. if (Array.isArray(module)) {
  340. module.forEach((m) => Class.installModule(m));
  341. return Class;
  342. }
  343. return Class.installModule(module, ...params);
  344. }
  345. }
  346. function updateSize () {
  347. const swiper = this;
  348. let width;
  349. let height;
  350. const $el = swiper.$el;
  351. if (typeof swiper.params.width !== 'undefined') {
  352. width = swiper.params.width;
  353. } else {
  354. width = $el[0].clientWidth;
  355. }
  356. if (typeof swiper.params.height !== 'undefined') {
  357. height = swiper.params.height;
  358. } else {
  359. height = $el[0].clientHeight;
  360. }
  361. if ((width === 0 && swiper.isHorizontal()) || (height === 0 && swiper.isVertical())) {
  362. return;
  363. }
  364. // Subtract paddings
  365. width = width - parseInt($el.css('padding-left'), 10) - parseInt($el.css('padding-right'), 10);
  366. height = height - parseInt($el.css('padding-top'), 10) - parseInt($el.css('padding-bottom'), 10);
  367. Utils.extend(swiper, {
  368. width,
  369. height,
  370. size: swiper.isHorizontal() ? width : height,
  371. });
  372. }
  373. function updateSlides () {
  374. const swiper = this;
  375. const params = swiper.params;
  376. const {
  377. $wrapperEl, size: swiperSize, rtlTranslate: rtl, wrongRTL,
  378. } = swiper;
  379. const isVirtual = swiper.virtual && params.virtual.enabled;
  380. const previousSlidesLength = isVirtual ? swiper.virtual.slides.length : swiper.slides.length;
  381. const slides = $wrapperEl.children(`.${swiper.params.slideClass}`);
  382. const slidesLength = isVirtual ? swiper.virtual.slides.length : slides.length;
  383. let snapGrid = [];
  384. const slidesGrid = [];
  385. const slidesSizesGrid = [];
  386. function slidesForMargin(slideIndex) {
  387. if (!params.cssMode) return true;
  388. if (slideIndex === slides.length - 1) {
  389. return false;
  390. }
  391. return true;
  392. }
  393. let offsetBefore = params.slidesOffsetBefore;
  394. if (typeof offsetBefore === 'function') {
  395. offsetBefore = params.slidesOffsetBefore.call(swiper);
  396. }
  397. let offsetAfter = params.slidesOffsetAfter;
  398. if (typeof offsetAfter === 'function') {
  399. offsetAfter = params.slidesOffsetAfter.call(swiper);
  400. }
  401. const previousSnapGridLength = swiper.snapGrid.length;
  402. const previousSlidesGridLength = swiper.snapGrid.length;
  403. let spaceBetween = params.spaceBetween;
  404. let slidePosition = -offsetBefore;
  405. let prevSlideSize = 0;
  406. let index = 0;
  407. if (typeof swiperSize === 'undefined') {
  408. return;
  409. }
  410. if (typeof spaceBetween === 'string' && spaceBetween.indexOf('%') >= 0) {
  411. spaceBetween = (parseFloat(spaceBetween.replace('%', '')) / 100) * swiperSize;
  412. }
  413. swiper.virtualSize = -spaceBetween;
  414. // reset margins
  415. if (rtl) slides.css({ marginLeft: '', marginTop: '' });
  416. else slides.css({ marginRight: '', marginBottom: '' });
  417. let slidesNumberEvenToRows;
  418. if (params.slidesPerColumn > 1) {
  419. if (Math.floor(slidesLength / params.slidesPerColumn) === slidesLength / swiper.params.slidesPerColumn) {
  420. slidesNumberEvenToRows = slidesLength;
  421. } else {
  422. slidesNumberEvenToRows = Math.ceil(slidesLength / params.slidesPerColumn) * params.slidesPerColumn;
  423. }
  424. if (params.slidesPerView !== 'auto' && params.slidesPerColumnFill === 'row') {
  425. slidesNumberEvenToRows = Math.max(slidesNumberEvenToRows, params.slidesPerView * params.slidesPerColumn);
  426. }
  427. }
  428. // Calc slides
  429. let slideSize;
  430. const slidesPerColumn = params.slidesPerColumn;
  431. const slidesPerRow = slidesNumberEvenToRows / slidesPerColumn;
  432. const numFullColumns = Math.floor(slidesLength / params.slidesPerColumn);
  433. for (let i = 0; i < slidesLength; i += 1) {
  434. slideSize = 0;
  435. const slide = slides.eq(i);
  436. if (params.slidesPerColumn > 1) {
  437. // Set slides order
  438. let newSlideOrderIndex;
  439. let column;
  440. let row;
  441. if (params.slidesPerColumnFill === 'row' && params.slidesPerGroup > 1) {
  442. const groupIndex = Math.floor(i / (params.slidesPerGroup * params.slidesPerColumn));
  443. const slideIndexInGroup = i - params.slidesPerColumn * params.slidesPerGroup * groupIndex;
  444. const columnsInGroup = groupIndex === 0
  445. ? params.slidesPerGroup
  446. : Math.min(Math.ceil((slidesLength - groupIndex * slidesPerColumn * params.slidesPerGroup) / slidesPerColumn), params.slidesPerGroup);
  447. row = Math.floor(slideIndexInGroup / columnsInGroup);
  448. column = (slideIndexInGroup - row * columnsInGroup) + groupIndex * params.slidesPerGroup;
  449. newSlideOrderIndex = column + ((row * slidesNumberEvenToRows) / slidesPerColumn);
  450. slide
  451. .css({
  452. '-webkit-box-ordinal-group': newSlideOrderIndex,
  453. '-moz-box-ordinal-group': newSlideOrderIndex,
  454. '-ms-flex-order': newSlideOrderIndex,
  455. '-webkit-order': newSlideOrderIndex,
  456. order: newSlideOrderIndex,
  457. });
  458. } else if (params.slidesPerColumnFill === 'column') {
  459. column = Math.floor(i / slidesPerColumn);
  460. row = i - (column * slidesPerColumn);
  461. if (column > numFullColumns || (column === numFullColumns && row === slidesPerColumn - 1)) {
  462. row += 1;
  463. if (row >= slidesPerColumn) {
  464. row = 0;
  465. column += 1;
  466. }
  467. }
  468. } else {
  469. row = Math.floor(i / slidesPerRow);
  470. column = i - (row * slidesPerRow);
  471. }
  472. slide.css(
  473. `margin-${swiper.isHorizontal() ? 'top' : 'left'}`,
  474. (row !== 0 && params.spaceBetween) && (`${params.spaceBetween}px`)
  475. );
  476. }
  477. if (slide.css('display') === 'none') continue; // eslint-disable-line
  478. if (params.slidesPerView === 'auto') {
  479. const slideStyles = window.getComputedStyle(slide[0], null);
  480. const currentTransform = slide[0].style.transform;
  481. const currentWebKitTransform = slide[0].style.webkitTransform;
  482. if (currentTransform) {
  483. slide[0].style.transform = 'none';
  484. }
  485. if (currentWebKitTransform) {
  486. slide[0].style.webkitTransform = 'none';
  487. }
  488. if (params.roundLengths) {
  489. slideSize = swiper.isHorizontal()
  490. ? slide.outerWidth(true)
  491. : slide.outerHeight(true);
  492. } else {
  493. // eslint-disable-next-line
  494. if (swiper.isHorizontal()) {
  495. const width = parseFloat(slideStyles.getPropertyValue('width'));
  496. const paddingLeft = parseFloat(slideStyles.getPropertyValue('padding-left'));
  497. const paddingRight = parseFloat(slideStyles.getPropertyValue('padding-right'));
  498. const marginLeft = parseFloat(slideStyles.getPropertyValue('margin-left'));
  499. const marginRight = parseFloat(slideStyles.getPropertyValue('margin-right'));
  500. const boxSizing = slideStyles.getPropertyValue('box-sizing');
  501. if (boxSizing && boxSizing === 'border-box') {
  502. slideSize = width + marginLeft + marginRight;
  503. } else {
  504. slideSize = width + paddingLeft + paddingRight + marginLeft + marginRight;
  505. }
  506. } else {
  507. const height = parseFloat(slideStyles.getPropertyValue('height'));
  508. const paddingTop = parseFloat(slideStyles.getPropertyValue('padding-top'));
  509. const paddingBottom = parseFloat(slideStyles.getPropertyValue('padding-bottom'));
  510. const marginTop = parseFloat(slideStyles.getPropertyValue('margin-top'));
  511. const marginBottom = parseFloat(slideStyles.getPropertyValue('margin-bottom'));
  512. const boxSizing = slideStyles.getPropertyValue('box-sizing');
  513. if (boxSizing && boxSizing === 'border-box') {
  514. slideSize = height + marginTop + marginBottom;
  515. } else {
  516. slideSize = height + paddingTop + paddingBottom + marginTop + marginBottom;
  517. }
  518. }
  519. }
  520. if (currentTransform) {
  521. slide[0].style.transform = currentTransform;
  522. }
  523. if (currentWebKitTransform) {
  524. slide[0].style.webkitTransform = currentWebKitTransform;
  525. }
  526. if (params.roundLengths) slideSize = Math.floor(slideSize);
  527. } else {
  528. slideSize = (swiperSize - ((params.slidesPerView - 1) * spaceBetween)) / params.slidesPerView;
  529. if (params.roundLengths) slideSize = Math.floor(slideSize);
  530. if (slides[i]) {
  531. if (swiper.isHorizontal()) {
  532. slides[i].style.width = `${slideSize}px`;
  533. } else {
  534. slides[i].style.height = `${slideSize}px`;
  535. }
  536. }
  537. }
  538. if (slides[i]) {
  539. slides[i].swiperSlideSize = slideSize;
  540. }
  541. slidesSizesGrid.push(slideSize);
  542. if (params.centeredSlides) {
  543. slidePosition = slidePosition + (slideSize / 2) + (prevSlideSize / 2) + spaceBetween;
  544. if (prevSlideSize === 0 && i !== 0) slidePosition = slidePosition - (swiperSize / 2) - spaceBetween;
  545. if (i === 0) slidePosition = slidePosition - (swiperSize / 2) - spaceBetween;
  546. if (Math.abs(slidePosition) < 1 / 1000) slidePosition = 0;
  547. if (params.roundLengths) slidePosition = Math.floor(slidePosition);
  548. if ((index) % params.slidesPerGroup === 0) snapGrid.push(slidePosition);
  549. slidesGrid.push(slidePosition);
  550. } else {
  551. if (params.roundLengths) slidePosition = Math.floor(slidePosition);
  552. if ((index - Math.min(swiper.params.slidesPerGroupSkip, index)) % swiper.params.slidesPerGroup === 0) snapGrid.push(slidePosition);
  553. slidesGrid.push(slidePosition);
  554. slidePosition = slidePosition + slideSize + spaceBetween;
  555. }
  556. swiper.virtualSize += slideSize + spaceBetween;
  557. prevSlideSize = slideSize;
  558. index += 1;
  559. }
  560. swiper.virtualSize = Math.max(swiper.virtualSize, swiperSize) + offsetAfter;
  561. let newSlidesGrid;
  562. if (
  563. rtl && wrongRTL && (params.effect === 'slide' || params.effect === 'coverflow')) {
  564. $wrapperEl.css({ width: `${swiper.virtualSize + params.spaceBetween}px` });
  565. }
  566. if (params.setWrapperSize) {
  567. if (swiper.isHorizontal()) $wrapperEl.css({ width: `${swiper.virtualSize + params.spaceBetween}px` });
  568. else $wrapperEl.css({ height: `${swiper.virtualSize + params.spaceBetween}px` });
  569. }
  570. if (params.slidesPerColumn > 1) {
  571. swiper.virtualSize = (slideSize + params.spaceBetween) * slidesNumberEvenToRows;
  572. swiper.virtualSize = Math.ceil(swiper.virtualSize / params.slidesPerColumn) - params.spaceBetween;
  573. if (swiper.isHorizontal()) $wrapperEl.css({ width: `${swiper.virtualSize + params.spaceBetween}px` });
  574. else $wrapperEl.css({ height: `${swiper.virtualSize + params.spaceBetween}px` });
  575. if (params.centeredSlides) {
  576. newSlidesGrid = [];
  577. for (let i = 0; i < snapGrid.length; i += 1) {
  578. let slidesGridItem = snapGrid[i];
  579. if (params.roundLengths) slidesGridItem = Math.floor(slidesGridItem);
  580. if (snapGrid[i] < swiper.virtualSize + snapGrid[0]) newSlidesGrid.push(slidesGridItem);
  581. }
  582. snapGrid = newSlidesGrid;
  583. }
  584. }
  585. // Remove last grid elements depending on width
  586. if (!params.centeredSlides) {
  587. newSlidesGrid = [];
  588. for (let i = 0; i < snapGrid.length; i += 1) {
  589. let slidesGridItem = snapGrid[i];
  590. if (params.roundLengths) slidesGridItem = Math.floor(slidesGridItem);
  591. if (snapGrid[i] <= swiper.virtualSize - swiperSize) {
  592. newSlidesGrid.push(slidesGridItem);
  593. }
  594. }
  595. snapGrid = newSlidesGrid;
  596. if (Math.floor(swiper.virtualSize - swiperSize) - Math.floor(snapGrid[snapGrid.length - 1]) > 1) {
  597. snapGrid.push(swiper.virtualSize - swiperSize);
  598. }
  599. }
  600. if (snapGrid.length === 0) snapGrid = [0];
  601. if (params.spaceBetween !== 0) {
  602. if (swiper.isHorizontal()) {
  603. if (rtl) slides.filter(slidesForMargin).css({ marginLeft: `${spaceBetween}px` });
  604. else slides.filter(slidesForMargin).css({ marginRight: `${spaceBetween}px` });
  605. } else slides.filter(slidesForMargin).css({ marginBottom: `${spaceBetween}px` });
  606. }
  607. if (params.centeredSlides && params.centeredSlidesBounds) {
  608. let allSlidesSize = 0;
  609. slidesSizesGrid.forEach((slideSizeValue) => {
  610. allSlidesSize += slideSizeValue + (params.spaceBetween ? params.spaceBetween : 0);
  611. });
  612. allSlidesSize -= params.spaceBetween;
  613. const maxSnap = allSlidesSize - swiperSize;
  614. snapGrid = snapGrid.map((snap) => {
  615. if (snap < 0) return -offsetBefore;
  616. if (snap > maxSnap) return maxSnap + offsetAfter;
  617. return snap;
  618. });
  619. }
  620. if (params.centerInsufficientSlides) {
  621. let allSlidesSize = 0;
  622. slidesSizesGrid.forEach((slideSizeValue) => {
  623. allSlidesSize += slideSizeValue + (params.spaceBetween ? params.spaceBetween : 0);
  624. });
  625. allSlidesSize -= params.spaceBetween;
  626. if (allSlidesSize < swiperSize) {
  627. const allSlidesOffset = (swiperSize - allSlidesSize) / 2;
  628. snapGrid.forEach((snap, snapIndex) => {
  629. snapGrid[snapIndex] = snap - allSlidesOffset;
  630. });
  631. slidesGrid.forEach((snap, snapIndex) => {
  632. slidesGrid[snapIndex] = snap + allSlidesOffset;
  633. });
  634. }
  635. }
  636. Utils.extend(swiper, {
  637. slides,
  638. snapGrid,
  639. slidesGrid,
  640. slidesSizesGrid,
  641. });
  642. if (slidesLength !== previousSlidesLength) {
  643. swiper.emit('slidesLengthChange');
  644. }
  645. if (snapGrid.length !== previousSnapGridLength) {
  646. if (swiper.params.watchOverflow) swiper.checkOverflow();
  647. swiper.emit('snapGridLengthChange');
  648. }
  649. if (slidesGrid.length !== previousSlidesGridLength) {
  650. swiper.emit('slidesGridLengthChange');
  651. }
  652. if (params.watchSlidesProgress || params.watchSlidesVisibility) {
  653. swiper.updateSlidesOffset();
  654. }
  655. }
  656. function updateAutoHeight (speed) {
  657. const swiper = this;
  658. const activeSlides = [];
  659. let newHeight = 0;
  660. let i;
  661. if (typeof speed === 'number') {
  662. swiper.setTransition(speed);
  663. } else if (speed === true) {
  664. swiper.setTransition(swiper.params.speed);
  665. }
  666. // Find slides currently in view
  667. if (swiper.params.slidesPerView !== 'auto' && swiper.params.slidesPerView > 1) {
  668. if (swiper.params.centeredSlides) activeSlides.push(...swiper.visibleSlides);
  669. else {
  670. for (i = 0; i < Math.ceil(swiper.params.slidesPerView); i += 1) {
  671. const index = swiper.activeIndex + i;
  672. if (index > swiper.slides.length) break;
  673. activeSlides.push(swiper.slides.eq(index)[0]);
  674. }
  675. }
  676. } else {
  677. activeSlides.push(swiper.slides.eq(swiper.activeIndex)[0]);
  678. }
  679. // Find new height from highest slide in view
  680. for (i = 0; i < activeSlides.length; i += 1) {
  681. if (typeof activeSlides[i] !== 'undefined') {
  682. const height = activeSlides[i].offsetHeight;
  683. newHeight = height > newHeight ? height : newHeight;
  684. }
  685. }
  686. // Update Height
  687. if (newHeight) swiper.$wrapperEl.css('height', `${newHeight}px`);
  688. }
  689. function updateSlidesOffset () {
  690. const swiper = this;
  691. const slides = swiper.slides;
  692. for (let i = 0; i < slides.length; i += 1) {
  693. slides[i].swiperSlideOffset = swiper.isHorizontal() ? slides[i].offsetLeft : slides[i].offsetTop;
  694. }
  695. }
  696. function updateSlidesProgress (translate = (this && this.translate) || 0) {
  697. const swiper = this;
  698. const params = swiper.params;
  699. const { slides, rtlTranslate: rtl } = swiper;
  700. if (slides.length === 0) return;
  701. if (typeof slides[0].swiperSlideOffset === 'undefined') swiper.updateSlidesOffset();
  702. let offsetCenter = -translate;
  703. if (rtl) offsetCenter = translate;
  704. // Visible Slides
  705. slides.removeClass(params.slideVisibleClass);
  706. swiper.visibleSlidesIndexes = [];
  707. swiper.visibleSlides = [];
  708. for (let i = 0; i < slides.length; i += 1) {
  709. const slide = slides[i];
  710. const slideProgress = (
  711. (offsetCenter + (params.centeredSlides ? swiper.minTranslate() : 0)) - slide.swiperSlideOffset
  712. ) / (slide.swiperSlideSize + params.spaceBetween);
  713. if (params.watchSlidesVisibility || (params.centeredSlides && params.autoHeight)) {
  714. const slideBefore = -(offsetCenter - slide.swiperSlideOffset);
  715. const slideAfter = slideBefore + swiper.slidesSizesGrid[i];
  716. const isVisible = (slideBefore >= 0 && slideBefore < swiper.size - 1)
  717. || (slideAfter > 1 && slideAfter <= swiper.size)
  718. || (slideBefore <= 0 && slideAfter >= swiper.size);
  719. if (isVisible) {
  720. swiper.visibleSlides.push(slide);
  721. swiper.visibleSlidesIndexes.push(i);
  722. slides.eq(i).addClass(params.slideVisibleClass);
  723. }
  724. }
  725. slide.progress = rtl ? -slideProgress : slideProgress;
  726. }
  727. swiper.visibleSlides = $(swiper.visibleSlides);
  728. }
  729. function updateProgress (translate) {
  730. const swiper = this;
  731. if (typeof translate === 'undefined') {
  732. const multiplier = swiper.rtlTranslate ? -1 : 1;
  733. // eslint-disable-next-line
  734. translate = (swiper && swiper.translate && (swiper.translate * multiplier)) || 0;
  735. }
  736. const params = swiper.params;
  737. const translatesDiff = swiper.maxTranslate() - swiper.minTranslate();
  738. let { progress, isBeginning, isEnd } = swiper;
  739. const wasBeginning = isBeginning;
  740. const wasEnd = isEnd;
  741. if (translatesDiff === 0) {
  742. progress = 0;
  743. isBeginning = true;
  744. isEnd = true;
  745. } else {
  746. progress = (translate - swiper.minTranslate()) / (translatesDiff);
  747. isBeginning = progress <= 0;
  748. isEnd = progress >= 1;
  749. }
  750. Utils.extend(swiper, {
  751. progress,
  752. isBeginning,
  753. isEnd,
  754. });
  755. if (params.watchSlidesProgress || params.watchSlidesVisibility || (params.centeredSlides && params.autoHeight)) swiper.updateSlidesProgress(translate);
  756. if (isBeginning && !wasBeginning) {
  757. swiper.emit('reachBeginning toEdge');
  758. }
  759. if (isEnd && !wasEnd) {
  760. swiper.emit('reachEnd toEdge');
  761. }
  762. if ((wasBeginning && !isBeginning) || (wasEnd && !isEnd)) {
  763. swiper.emit('fromEdge');
  764. }
  765. swiper.emit('progress', progress);
  766. }
  767. function updateSlidesClasses () {
  768. const swiper = this;
  769. const {
  770. slides, params, $wrapperEl, activeIndex, realIndex,
  771. } = swiper;
  772. const isVirtual = swiper.virtual && params.virtual.enabled;
  773. slides.removeClass(`${params.slideActiveClass} ${params.slideNextClass} ${params.slidePrevClass} ${params.slideDuplicateActiveClass} ${params.slideDuplicateNextClass} ${params.slideDuplicatePrevClass}`);
  774. let activeSlide;
  775. if (isVirtual) {
  776. activeSlide = swiper.$wrapperEl.find(`.${params.slideClass}[data-swiper-slide-index="${activeIndex}"]`);
  777. } else {
  778. activeSlide = slides.eq(activeIndex);
  779. }
  780. // Active classes
  781. activeSlide.addClass(params.slideActiveClass);
  782. if (params.loop) {
  783. // Duplicate to all looped slides
  784. if (activeSlide.hasClass(params.slideDuplicateClass)) {
  785. $wrapperEl
  786. .children(`.${params.slideClass}:not(.${params.slideDuplicateClass})[data-swiper-slide-index="${realIndex}"]`)
  787. .addClass(params.slideDuplicateActiveClass);
  788. } else {
  789. $wrapperEl
  790. .children(`.${params.slideClass}.${params.slideDuplicateClass}[data-swiper-slide-index="${realIndex}"]`)
  791. .addClass(params.slideDuplicateActiveClass);
  792. }
  793. }
  794. // Next Slide
  795. let nextSlide = activeSlide.nextAll(`.${params.slideClass}`).eq(0).addClass(params.slideNextClass);
  796. if (params.loop && nextSlide.length === 0) {
  797. nextSlide = slides.eq(0);
  798. nextSlide.addClass(params.slideNextClass);
  799. }
  800. // Prev Slide
  801. let prevSlide = activeSlide.prevAll(`.${params.slideClass}`).eq(0).addClass(params.slidePrevClass);
  802. if (params.loop && prevSlide.length === 0) {
  803. prevSlide = slides.eq(-1);
  804. prevSlide.addClass(params.slidePrevClass);
  805. }
  806. if (params.loop) {
  807. // Duplicate to all looped slides
  808. if (nextSlide.hasClass(params.slideDuplicateClass)) {
  809. $wrapperEl
  810. .children(`.${params.slideClass}:not(.${params.slideDuplicateClass})[data-swiper-slide-index="${nextSlide.attr('data-swiper-slide-index')}"]`)
  811. .addClass(params.slideDuplicateNextClass);
  812. } else {
  813. $wrapperEl
  814. .children(`.${params.slideClass}.${params.slideDuplicateClass}[data-swiper-slide-index="${nextSlide.attr('data-swiper-slide-index')}"]`)
  815. .addClass(params.slideDuplicateNextClass);
  816. }
  817. if (prevSlide.hasClass(params.slideDuplicateClass)) {
  818. $wrapperEl
  819. .children(`.${params.slideClass}:not(.${params.slideDuplicateClass})[data-swiper-slide-index="${prevSlide.attr('data-swiper-slide-index')}"]`)
  820. .addClass(params.slideDuplicatePrevClass);
  821. } else {
  822. $wrapperEl
  823. .children(`.${params.slideClass}.${params.slideDuplicateClass}[data-swiper-slide-index="${prevSlide.attr('data-swiper-slide-index')}"]`)
  824. .addClass(params.slideDuplicatePrevClass);
  825. }
  826. }
  827. }
  828. function updateActiveIndex (newActiveIndex) {
  829. const swiper = this;
  830. const translate = swiper.rtlTranslate ? swiper.translate : -swiper.translate;
  831. const {
  832. slidesGrid, snapGrid, params, activeIndex: previousIndex, realIndex: previousRealIndex, snapIndex: previousSnapIndex,
  833. } = swiper;
  834. let activeIndex = newActiveIndex;
  835. let snapIndex;
  836. if (typeof activeIndex === 'undefined') {
  837. for (let i = 0; i < slidesGrid.length; i += 1) {
  838. if (typeof slidesGrid[i + 1] !== 'undefined') {
  839. if (translate >= slidesGrid[i] && translate < slidesGrid[i + 1] - ((slidesGrid[i + 1] - slidesGrid[i]) / 2)) {
  840. activeIndex = i;
  841. } else if (translate >= slidesGrid[i] && translate < slidesGrid[i + 1]) {
  842. activeIndex = i + 1;
  843. }
  844. } else if (translate >= slidesGrid[i]) {
  845. activeIndex = i;
  846. }
  847. }
  848. // Normalize slideIndex
  849. if (params.normalizeSlideIndex) {
  850. if (activeIndex < 0 || typeof activeIndex === 'undefined') activeIndex = 0;
  851. }
  852. }
  853. if (snapGrid.indexOf(translate) >= 0) {
  854. snapIndex = snapGrid.indexOf(translate);
  855. } else {
  856. const skip = Math.min(params.slidesPerGroupSkip, activeIndex);
  857. snapIndex = skip + Math.floor((activeIndex - skip) / params.slidesPerGroup);
  858. }
  859. if (snapIndex >= snapGrid.length) snapIndex = snapGrid.length - 1;
  860. if (activeIndex === previousIndex) {
  861. if (snapIndex !== previousSnapIndex) {
  862. swiper.snapIndex = snapIndex;
  863. swiper.emit('snapIndexChange');
  864. }
  865. return;
  866. }
  867. // Get real index
  868. const realIndex = parseInt(swiper.slides.eq(activeIndex).attr('data-swiper-slide-index') || activeIndex, 10);
  869. Utils.extend(swiper, {
  870. snapIndex,
  871. realIndex,
  872. previousIndex,
  873. activeIndex,
  874. });
  875. swiper.emit('activeIndexChange');
  876. swiper.emit('snapIndexChange');
  877. if (previousRealIndex !== realIndex) {
  878. swiper.emit('realIndexChange');
  879. }
  880. if (swiper.initialized || swiper.runCallbacksOnInit) {
  881. swiper.emit('slideChange');
  882. }
  883. }
  884. function updateClickedSlide (e) {
  885. const swiper = this;
  886. const params = swiper.params;
  887. const slide = $(e.target).closest(`.${params.slideClass}`)[0];
  888. let slideFound = false;
  889. if (slide) {
  890. for (let i = 0; i < swiper.slides.length; i += 1) {
  891. if (swiper.slides[i] === slide) slideFound = true;
  892. }
  893. }
  894. if (slide && slideFound) {
  895. swiper.clickedSlide = slide;
  896. if (swiper.virtual && swiper.params.virtual.enabled) {
  897. swiper.clickedIndex = parseInt($(slide).attr('data-swiper-slide-index'), 10);
  898. } else {
  899. swiper.clickedIndex = $(slide).index();
  900. }
  901. } else {
  902. swiper.clickedSlide = undefined;
  903. swiper.clickedIndex = undefined;
  904. return;
  905. }
  906. if (params.slideToClickedSlide && swiper.clickedIndex !== undefined && swiper.clickedIndex !== swiper.activeIndex) {
  907. swiper.slideToClickedSlide();
  908. }
  909. }
  910. var update = {
  911. updateSize,
  912. updateSlides,
  913. updateAutoHeight,
  914. updateSlidesOffset,
  915. updateSlidesProgress,
  916. updateProgress,
  917. updateSlidesClasses,
  918. updateActiveIndex,
  919. updateClickedSlide,
  920. };
  921. function getTranslate (axis = this.isHorizontal() ? 'x' : 'y') {
  922. const swiper = this;
  923. const {
  924. params, rtlTranslate: rtl, translate, $wrapperEl,
  925. } = swiper;
  926. if (params.virtualTranslate) {
  927. return rtl ? -translate : translate;
  928. }
  929. if (params.cssMode) {
  930. return translate;
  931. }
  932. let currentTranslate = Utils.getTranslate($wrapperEl[0], axis);
  933. if (rtl) currentTranslate = -currentTranslate;
  934. return currentTranslate || 0;
  935. }
  936. function setTranslate (translate, byController) {
  937. const swiper = this;
  938. const {
  939. rtlTranslate: rtl, params, $wrapperEl, wrapperEl, progress,
  940. } = swiper;
  941. let x = 0;
  942. let y = 0;
  943. const z = 0;
  944. if (swiper.isHorizontal()) {
  945. x = rtl ? -translate : translate;
  946. } else {
  947. y = translate;
  948. }
  949. if (params.roundLengths) {
  950. x = Math.floor(x);
  951. y = Math.floor(y);
  952. }
  953. if (params.cssMode) {
  954. wrapperEl[swiper.isHorizontal() ? 'scrollLeft' : 'scrollTop'] = swiper.isHorizontal() ? -x : -y;
  955. } else if (!params.virtualTranslate) {
  956. $wrapperEl.transform(`translate3d(${x}px, ${y}px, ${z}px)`);
  957. }
  958. swiper.previousTranslate = swiper.translate;
  959. swiper.translate = swiper.isHorizontal() ? x : y;
  960. // Check if we need to update progress
  961. let newProgress;
  962. const translatesDiff = swiper.maxTranslate() - swiper.minTranslate();
  963. if (translatesDiff === 0) {
  964. newProgress = 0;
  965. } else {
  966. newProgress = (translate - swiper.minTranslate()) / (translatesDiff);
  967. }
  968. if (newProgress !== progress) {
  969. swiper.updateProgress(translate);
  970. }
  971. swiper.emit('setTranslate', swiper.translate, byController);
  972. }
  973. function minTranslate () {
  974. return (-this.snapGrid[0]);
  975. }
  976. function maxTranslate () {
  977. return (-this.snapGrid[this.snapGrid.length - 1]);
  978. }
  979. function translateTo (translate = 0, speed = this.params.speed, runCallbacks = true, translateBounds = true, internal) {
  980. const swiper = this;
  981. const {
  982. params,
  983. wrapperEl,
  984. } = swiper;
  985. if (swiper.animating && params.preventInteractionOnTransition) {
  986. return false;
  987. }
  988. const minTranslate = swiper.minTranslate();
  989. const maxTranslate = swiper.maxTranslate();
  990. let newTranslate;
  991. if (translateBounds && translate > minTranslate) newTranslate = minTranslate;
  992. else if (translateBounds && translate < maxTranslate) newTranslate = maxTranslate;
  993. else newTranslate = translate;
  994. // Update progress
  995. swiper.updateProgress(newTranslate);
  996. if (params.cssMode) {
  997. const isH = swiper.isHorizontal();
  998. if (speed === 0) {
  999. wrapperEl[isH ? 'scrollLeft' : 'scrollTop'] = -newTranslate;
  1000. } else {
  1001. // eslint-disable-next-line
  1002. if (wrapperEl.scrollTo) {
  1003. wrapperEl.scrollTo({
  1004. [isH ? 'left' : 'top']: -newTranslate,
  1005. behavior: 'smooth',
  1006. });
  1007. } else {
  1008. wrapperEl[isH ? 'scrollLeft' : 'scrollTop'] = -newTranslate;
  1009. }
  1010. }
  1011. return true;
  1012. }
  1013. if (speed === 0) {
  1014. swiper.setTransition(0);
  1015. swiper.setTranslate(newTranslate);
  1016. if (runCallbacks) {
  1017. swiper.emit('beforeTransitionStart', speed, internal);
  1018. swiper.emit('transitionEnd');
  1019. }
  1020. } else {
  1021. swiper.setTransition(speed);
  1022. swiper.setTranslate(newTranslate);
  1023. if (runCallbacks) {
  1024. swiper.emit('beforeTransitionStart', speed, internal);
  1025. swiper.emit('transitionStart');
  1026. }
  1027. if (!swiper.animating) {
  1028. swiper.animating = true;
  1029. if (!swiper.onTranslateToWrapperTransitionEnd) {
  1030. swiper.onTranslateToWrapperTransitionEnd = function transitionEnd(e) {
  1031. if (!swiper || swiper.destroyed) return;
  1032. if (e.target !== this) return;
  1033. swiper.$wrapperEl[0].removeEventListener('transitionend', swiper.onTranslateToWrapperTransitionEnd);
  1034. swiper.$wrapperEl[0].removeEventListener('webkitTransitionEnd', swiper.onTranslateToWrapperTransitionEnd);
  1035. swiper.onTranslateToWrapperTransitionEnd = null;
  1036. delete swiper.onTranslateToWrapperTransitionEnd;
  1037. if (runCallbacks) {
  1038. swiper.emit('transitionEnd');
  1039. }
  1040. };
  1041. }
  1042. swiper.$wrapperEl[0].addEventListener('transitionend', swiper.onTranslateToWrapperTransitionEnd);
  1043. swiper.$wrapperEl[0].addEventListener('webkitTransitionEnd', swiper.onTranslateToWrapperTransitionEnd);
  1044. }
  1045. }
  1046. return true;
  1047. }
  1048. var translate = {
  1049. getTranslate,
  1050. setTranslate,
  1051. minTranslate,
  1052. maxTranslate,
  1053. translateTo,
  1054. };
  1055. function setTransition (duration, byController) {
  1056. const swiper = this;
  1057. if (!swiper.params.cssMode) {
  1058. swiper.$wrapperEl.transition(duration);
  1059. }
  1060. swiper.emit('setTransition', duration, byController);
  1061. }
  1062. function transitionStart (runCallbacks = true, direction) {
  1063. const swiper = this;
  1064. const { activeIndex, params, previousIndex } = swiper;
  1065. if (params.cssMode) return;
  1066. if (params.autoHeight) {
  1067. swiper.updateAutoHeight();
  1068. }
  1069. let dir = direction;
  1070. if (!dir) {
  1071. if (activeIndex > previousIndex) dir = 'next';
  1072. else if (activeIndex < previousIndex) dir = 'prev';
  1073. else dir = 'reset';
  1074. }
  1075. swiper.emit('transitionStart');
  1076. if (runCallbacks && activeIndex !== previousIndex) {
  1077. if (dir === 'reset') {
  1078. swiper.emit('slideResetTransitionStart');
  1079. return;
  1080. }
  1081. swiper.emit('slideChangeTransitionStart');
  1082. if (dir === 'next') {
  1083. swiper.emit('slideNextTransitionStart');
  1084. } else {
  1085. swiper.emit('slidePrevTransitionStart');
  1086. }
  1087. }
  1088. }
  1089. function transitionEnd (runCallbacks = true, direction) {
  1090. const swiper = this;
  1091. const { activeIndex, previousIndex, params } = swiper;
  1092. swiper.animating = false;
  1093. if (params.cssMode) return;
  1094. swiper.setTransition(0);
  1095. let dir = direction;
  1096. if (!dir) {
  1097. if (activeIndex > previousIndex) dir = 'next';
  1098. else if (activeIndex < previousIndex) dir = 'prev';
  1099. else dir = 'reset';
  1100. }
  1101. swiper.emit('transitionEnd');
  1102. if (runCallbacks && activeIndex !== previousIndex) {
  1103. if (dir === 'reset') {
  1104. swiper.emit('slideResetTransitionEnd');
  1105. return;
  1106. }
  1107. swiper.emit('slideChangeTransitionEnd');
  1108. if (dir === 'next') {
  1109. swiper.emit('slideNextTransitionEnd');
  1110. } else {
  1111. swiper.emit('slidePrevTransitionEnd');
  1112. }
  1113. }
  1114. }
  1115. var transition = {
  1116. setTransition,
  1117. transitionStart,
  1118. transitionEnd,
  1119. };
  1120. function slideTo (index = 0, speed = this.params.speed, runCallbacks = true, internal) {
  1121. const swiper = this;
  1122. let slideIndex = index;
  1123. if (slideIndex < 0) slideIndex = 0;
  1124. const {
  1125. params, snapGrid, slidesGrid, previousIndex, activeIndex, rtlTranslate: rtl, wrapperEl,
  1126. } = swiper;
  1127. if (swiper.animating && params.preventInteractionOnTransition) {
  1128. return false;
  1129. }
  1130. const skip = Math.min(swiper.params.slidesPerGroupSkip, slideIndex);
  1131. let snapIndex = skip + Math.floor((slideIndex - skip) / swiper.params.slidesPerGroup);
  1132. if (snapIndex >= snapGrid.length) snapIndex = snapGrid.length - 1;
  1133. if ((activeIndex || params.initialSlide || 0) === (previousIndex || 0) && runCallbacks) {
  1134. swiper.emit('beforeSlideChangeStart');
  1135. }
  1136. const translate = -snapGrid[snapIndex];
  1137. // Update progress
  1138. swiper.updateProgress(translate);
  1139. // Normalize slideIndex
  1140. if (params.normalizeSlideIndex) {
  1141. for (let i = 0; i < slidesGrid.length; i += 1) {
  1142. if (-Math.floor(translate * 100) >= Math.floor(slidesGrid[i] * 100)) {
  1143. slideIndex = i;
  1144. }
  1145. }
  1146. }
  1147. // Directions locks
  1148. if (swiper.initialized && slideIndex !== activeIndex) {
  1149. if (!swiper.allowSlideNext && translate < swiper.translate && translate < swiper.minTranslate()) {
  1150. return false;
  1151. }
  1152. if (!swiper.allowSlidePrev && translate > swiper.translate && translate > swiper.maxTranslate()) {
  1153. if ((activeIndex || 0) !== slideIndex) return false;
  1154. }
  1155. }
  1156. let direction;
  1157. if (slideIndex > activeIndex) direction = 'next';
  1158. else if (slideIndex < activeIndex) direction = 'prev';
  1159. else direction = 'reset';
  1160. // Update Index
  1161. if ((rtl && -translate === swiper.translate) || (!rtl && translate === swiper.translate)) {
  1162. swiper.updateActiveIndex(slideIndex);
  1163. // Update Height
  1164. if (params.autoHeight) {
  1165. swiper.updateAutoHeight();
  1166. }
  1167. swiper.updateSlidesClasses();
  1168. if (params.effect !== 'slide') {
  1169. swiper.setTranslate(translate);
  1170. }
  1171. if (direction !== 'reset') {
  1172. swiper.transitionStart(runCallbacks, direction);
  1173. swiper.transitionEnd(runCallbacks, direction);
  1174. }
  1175. return false;
  1176. }
  1177. if (params.cssMode) {
  1178. const isH = swiper.isHorizontal();
  1179. if (speed === 0) {
  1180. wrapperEl[isH ? 'scrollLeft' : 'scrollTop'] = -translate;
  1181. } else {
  1182. // eslint-disable-next-line
  1183. if (wrapperEl.scrollTo) {
  1184. wrapperEl.scrollTo({
  1185. [isH ? 'left' : 'top']: -translate,
  1186. behavior: 'smooth',
  1187. });
  1188. } else {
  1189. wrapperEl[isH ? 'scrollLeft' : 'scrollTop'] = -translate;
  1190. }
  1191. }
  1192. return true;
  1193. }
  1194. if (speed === 0) {
  1195. swiper.setTransition(0);
  1196. swiper.setTranslate(translate);
  1197. swiper.updateActiveIndex(slideIndex);
  1198. swiper.updateSlidesClasses();
  1199. swiper.emit('beforeTransitionStart', speed, internal);
  1200. swiper.transitionStart(runCallbacks, direction);
  1201. swiper.transitionEnd(runCallbacks, direction);
  1202. } else {
  1203. swiper.setTransition(speed);
  1204. swiper.setTranslate(translate);
  1205. swiper.updateActiveIndex(slideIndex);
  1206. swiper.updateSlidesClasses();
  1207. swiper.emit('beforeTransitionStart', speed, internal);
  1208. swiper.transitionStart(runCallbacks, direction);
  1209. if (!swiper.animating) {
  1210. swiper.animating = true;
  1211. if (!swiper.onSlideToWrapperTransitionEnd) {
  1212. swiper.onSlideToWrapperTransitionEnd = function transitionEnd(e) {
  1213. if (!swiper || swiper.destroyed) return;
  1214. if (e.target !== this) return;
  1215. swiper.$wrapperEl[0].removeEventListener('transitionend', swiper.onSlideToWrapperTransitionEnd);
  1216. swiper.$wrapperEl[0].removeEventListener('webkitTransitionEnd', swiper.onSlideToWrapperTransitionEnd);
  1217. swiper.onSlideToWrapperTransitionEnd = null;
  1218. delete swiper.onSlideToWrapperTransitionEnd;
  1219. swiper.transitionEnd(runCallbacks, direction);
  1220. };
  1221. }
  1222. swiper.$wrapperEl[0].addEventListener('transitionend', swiper.onSlideToWrapperTransitionEnd);
  1223. swiper.$wrapperEl[0].addEventListener('webkitTransitionEnd', swiper.onSlideToWrapperTransitionEnd);
  1224. }
  1225. }
  1226. return true;
  1227. }
  1228. function slideToLoop (index = 0, speed = this.params.speed, runCallbacks = true, internal) {
  1229. const swiper = this;
  1230. let newIndex = index;
  1231. if (swiper.params.loop) {
  1232. newIndex += swiper.loopedSlides;
  1233. }
  1234. return swiper.slideTo(newIndex, speed, runCallbacks, internal);
  1235. }
  1236. /* eslint no-unused-vars: "off" */
  1237. function slideNext (speed = this.params.speed, runCallbacks = true, internal) {
  1238. const swiper = this;
  1239. const { params, animating } = swiper;
  1240. const increment = swiper.activeIndex < params.slidesPerGroupSkip ? 1 : params.slidesPerGroup;
  1241. if (params.loop) {
  1242. if (animating) return false;
  1243. swiper.loopFix();
  1244. // eslint-disable-next-line
  1245. swiper._clientLeft = swiper.$wrapperEl[0].clientLeft;
  1246. }
  1247. return swiper.slideTo(swiper.activeIndex + increment, speed, runCallbacks, internal);
  1248. }
  1249. /* eslint no-unused-vars: "off" */
  1250. function slidePrev (speed = this.params.speed, runCallbacks = true, internal) {
  1251. const swiper = this;
  1252. const {
  1253. params, animating, snapGrid, slidesGrid, rtlTranslate,
  1254. } = swiper;
  1255. if (params.loop) {
  1256. if (animating) return false;
  1257. swiper.loopFix();
  1258. // eslint-disable-next-line
  1259. swiper._clientLeft = swiper.$wrapperEl[0].clientLeft;
  1260. }
  1261. const translate = rtlTranslate ? swiper.translate : -swiper.translate;
  1262. function normalize(val) {
  1263. if (val < 0) return -Math.floor(Math.abs(val));
  1264. return Math.floor(val);
  1265. }
  1266. const normalizedTranslate = normalize(translate);
  1267. const normalizedSnapGrid = snapGrid.map((val) => normalize(val));
  1268. const normalizedSlidesGrid = slidesGrid.map((val) => normalize(val));
  1269. const currentSnap = snapGrid[normalizedSnapGrid.indexOf(normalizedTranslate)];
  1270. let prevSnap = snapGrid[normalizedSnapGrid.indexOf(normalizedTranslate) - 1];
  1271. if (typeof prevSnap === 'undefined' && params.cssMode) {
  1272. snapGrid.forEach((snap) => {
  1273. if (!prevSnap && normalizedTranslate >= snap) prevSnap = snap;
  1274. });
  1275. }
  1276. let prevIndex;
  1277. if (typeof prevSnap !== 'undefined') {
  1278. prevIndex = slidesGrid.indexOf(prevSnap);
  1279. if (prevIndex < 0) prevIndex = swiper.activeIndex - 1;
  1280. }
  1281. return swiper.slideTo(prevIndex, speed, runCallbacks, internal);
  1282. }
  1283. /* eslint no-unused-vars: "off" */
  1284. function slideReset (speed = this.params.speed, runCallbacks = true, internal) {
  1285. const swiper = this;
  1286. return swiper.slideTo(swiper.activeIndex, speed, runCallbacks, internal);
  1287. }
  1288. /* eslint no-unused-vars: "off" */
  1289. function slideToClosest (speed = this.params.speed, runCallbacks = true, internal, threshold = 0.5) {
  1290. const swiper = this;
  1291. let index = swiper.activeIndex;
  1292. const skip = Math.min(swiper.params.slidesPerGroupSkip, index);
  1293. const snapIndex = skip + Math.floor((index - skip) / swiper.params.slidesPerGroup);
  1294. const translate = swiper.rtlTranslate ? swiper.translate : -swiper.translate;
  1295. if (translate >= swiper.snapGrid[snapIndex]) {
  1296. // The current translate is on or after the current snap index, so the choice
  1297. // is between the current index and the one after it.
  1298. const currentSnap = swiper.snapGrid[snapIndex];
  1299. const nextSnap = swiper.snapGrid[snapIndex + 1];
  1300. if ((translate - currentSnap) > (nextSnap - currentSnap) * threshold) {
  1301. index += swiper.params.slidesPerGroup;
  1302. }
  1303. } else {
  1304. // The current translate is before the current snap index, so the choice
  1305. // is between the current index and the one before it.
  1306. const prevSnap = swiper.snapGrid[snapIndex - 1];
  1307. const currentSnap = swiper.snapGrid[snapIndex];
  1308. if ((translate - prevSnap) <= (currentSnap - prevSnap) * threshold) {
  1309. index -= swiper.params.slidesPerGroup;
  1310. }
  1311. }
  1312. index = Math.max(index, 0);
  1313. index = Math.min(index, swiper.slidesGrid.length - 1);
  1314. return swiper.slideTo(index, speed, runCallbacks, internal);
  1315. }
  1316. function slideToClickedSlide () {
  1317. const swiper = this;
  1318. const { params, $wrapperEl } = swiper;
  1319. const slidesPerView = params.slidesPerView === 'auto' ? swiper.slidesPerViewDynamic() : params.slidesPerView;
  1320. let slideToIndex = swiper.clickedIndex;
  1321. let realIndex;
  1322. if (params.loop) {
  1323. if (swiper.animating) return;
  1324. realIndex = parseInt($(swiper.clickedSlide).attr('data-swiper-slide-index'), 10);
  1325. if (params.centeredSlides) {
  1326. if (
  1327. (slideToIndex < swiper.loopedSlides - (slidesPerView / 2))
  1328. || (slideToIndex > (swiper.slides.length - swiper.loopedSlides) + (slidesPerView / 2))
  1329. ) {
  1330. swiper.loopFix();
  1331. slideToIndex = $wrapperEl
  1332. .children(`.${params.slideClass}[data-swiper-slide-index="${realIndex}"]:not(.${params.slideDuplicateClass})`)
  1333. .eq(0)
  1334. .index();
  1335. Utils.nextTick(() => {
  1336. swiper.slideTo(slideToIndex);
  1337. });
  1338. } else {
  1339. swiper.slideTo(slideToIndex);
  1340. }
  1341. } else if (slideToIndex > swiper.slides.length - slidesPerView) {
  1342. swiper.loopFix();
  1343. slideToIndex = $wrapperEl
  1344. .children(`.${params.slideClass}[data-swiper-slide-index="${realIndex}"]:not(.${params.slideDuplicateClass})`)
  1345. .eq(0)
  1346. .index();
  1347. Utils.nextTick(() => {
  1348. swiper.slideTo(slideToIndex);
  1349. });
  1350. } else {
  1351. swiper.slideTo(slideToIndex);
  1352. }
  1353. } else {
  1354. swiper.slideTo(slideToIndex);
  1355. }
  1356. }
  1357. var slide = {
  1358. slideTo,
  1359. slideToLoop,
  1360. slideNext,
  1361. slidePrev,
  1362. slideReset,
  1363. slideToClosest,
  1364. slideToClickedSlide,
  1365. };
  1366. function loopCreate () {
  1367. const swiper = this;
  1368. const { params, $wrapperEl } = swiper;
  1369. // Remove duplicated slides
  1370. $wrapperEl.children(`.${params.slideClass}.${params.slideDuplicateClass}`).remove();
  1371. let slides = $wrapperEl.children(`.${params.slideClass}`);
  1372. if (params.loopFillGroupWithBlank) {
  1373. const blankSlidesNum = params.slidesPerGroup - (slides.length % params.slidesPerGroup);
  1374. if (blankSlidesNum !== params.slidesPerGroup) {
  1375. for (let i = 0; i < blankSlidesNum; i += 1) {
  1376. const blankNode = $(document$1.createElement('div')).addClass(`${params.slideClass} ${params.slideBlankClass}`);
  1377. $wrapperEl.append(blankNode);
  1378. }
  1379. slides = $wrapperEl.children(`.${params.slideClass}`);
  1380. }
  1381. }
  1382. if (params.slidesPerView === 'auto' && !params.loopedSlides) params.loopedSlides = slides.length;
  1383. swiper.loopedSlides = Math.ceil(parseFloat(params.loopedSlides || params.slidesPerView, 10));
  1384. swiper.loopedSlides += params.loopAdditionalSlides;
  1385. if (swiper.loopedSlides > slides.length) {
  1386. swiper.loopedSlides = slides.length;
  1387. }
  1388. const prependSlides = [];
  1389. const appendSlides = [];
  1390. slides.each((index, el) => {
  1391. const slide = $(el);
  1392. if (index < swiper.loopedSlides) appendSlides.push(el);
  1393. if (index < slides.length && index >= slides.length - swiper.loopedSlides) prependSlides.push(el);
  1394. slide.attr('data-swiper-slide-index', index);
  1395. });
  1396. for (let i = 0; i < appendSlides.length; i += 1) {
  1397. $wrapperEl.append($(appendSlides[i].cloneNode(true)).addClass(params.slideDuplicateClass));
  1398. }
  1399. for (let i = prependSlides.length - 1; i >= 0; i -= 1) {
  1400. $wrapperEl.prepend($(prependSlides[i].cloneNode(true)).addClass(params.slideDuplicateClass));
  1401. }
  1402. }
  1403. function loopFix () {
  1404. const swiper = this;
  1405. swiper.emit('beforeLoopFix');
  1406. const {
  1407. activeIndex, slides, loopedSlides, allowSlidePrev, allowSlideNext, snapGrid, rtlTranslate: rtl,
  1408. } = swiper;
  1409. let newIndex;
  1410. swiper.allowSlidePrev = true;
  1411. swiper.allowSlideNext = true;
  1412. const snapTranslate = -snapGrid[activeIndex];
  1413. const diff = snapTranslate - swiper.getTranslate();
  1414. // Fix For Negative Oversliding
  1415. if (activeIndex < loopedSlides) {
  1416. newIndex = (slides.length - (loopedSlides * 3)) + activeIndex;
  1417. newIndex += loopedSlides;
  1418. const slideChanged = swiper.slideTo(newIndex, 0, false, true);
  1419. if (slideChanged && diff !== 0) {
  1420. swiper.setTranslate((rtl ? -swiper.translate : swiper.translate) - diff);
  1421. }
  1422. } else if (activeIndex >= slides.length - loopedSlides) {
  1423. // Fix For Positive Oversliding
  1424. newIndex = -slides.length + activeIndex + loopedSlides;
  1425. newIndex += loopedSlides;
  1426. const slideChanged = swiper.slideTo(newIndex, 0, false, true);
  1427. if (slideChanged && diff !== 0) {
  1428. swiper.setTranslate((rtl ? -swiper.translate : swiper.translate) - diff);
  1429. }
  1430. }
  1431. swiper.allowSlidePrev = allowSlidePrev;
  1432. swiper.allowSlideNext = allowSlideNext;
  1433. swiper.emit('loopFix');
  1434. }
  1435. function loopDestroy () {
  1436. const swiper = this;
  1437. const { $wrapperEl, params, slides } = swiper;
  1438. $wrapperEl.children(`.${params.slideClass}.${params.slideDuplicateClass},.${params.slideClass}.${params.slideBlankClass}`).remove();
  1439. slides.removeAttr('data-swiper-slide-index');
  1440. }
  1441. var loop = {
  1442. loopCreate,
  1443. loopFix,
  1444. loopDestroy,
  1445. };
  1446. function setGrabCursor (moving) {
  1447. const swiper = this;
  1448. if (Support.touch || !swiper.params.simulateTouch || (swiper.params.watchOverflow && swiper.isLocked) || swiper.params.cssMode) return;
  1449. const el = swiper.el;
  1450. el.style.cursor = 'move';
  1451. el.style.cursor = moving ? '-webkit-grabbing' : '-webkit-grab';
  1452. el.style.cursor = moving ? '-moz-grabbin' : '-moz-grab';
  1453. el.style.cursor = moving ? 'grabbing' : 'grab';
  1454. }
  1455. function unsetGrabCursor () {
  1456. const swiper = this;
  1457. if (Support.touch || (swiper.params.watchOverflow && swiper.isLocked) || swiper.params.cssMode) return;
  1458. swiper.el.style.cursor = '';
  1459. }
  1460. var grabCursor = {
  1461. setGrabCursor,
  1462. unsetGrabCursor,
  1463. };
  1464. function appendSlide (slides) {
  1465. const swiper = this;
  1466. const { $wrapperEl, params } = swiper;
  1467. if (params.loop) {
  1468. swiper.loopDestroy();
  1469. }
  1470. if (typeof slides === 'object' && 'length' in slides) {
  1471. for (let i = 0; i < slides.length; i += 1) {
  1472. if (slides[i]) $wrapperEl.append(slides[i]);
  1473. }
  1474. } else {
  1475. $wrapperEl.append(slides);
  1476. }
  1477. if (params.loop) {
  1478. swiper.loopCreate();
  1479. }
  1480. if (!(params.observer && Support.observer)) {
  1481. swiper.update();
  1482. }
  1483. }
  1484. function prependSlide (slides) {
  1485. const swiper = this;
  1486. const { params, $wrapperEl, activeIndex } = swiper;
  1487. if (params.loop) {
  1488. swiper.loopDestroy();
  1489. }
  1490. let newActiveIndex = activeIndex + 1;
  1491. if (typeof slides === 'object' && 'length' in slides) {
  1492. for (let i = 0; i < slides.length; i += 1) {
  1493. if (slides[i]) $wrapperEl.prepend(slides[i]);
  1494. }
  1495. newActiveIndex = activeIndex + slides.length;
  1496. } else {
  1497. $wrapperEl.prepend(slides);
  1498. }
  1499. if (params.loop) {
  1500. swiper.loopCreate();
  1501. }
  1502. if (!(params.observer && Support.observer)) {
  1503. swiper.update();
  1504. }
  1505. swiper.slideTo(newActiveIndex, 0, false);
  1506. }
  1507. function addSlide (index, slides) {
  1508. const swiper = this;
  1509. const { $wrapperEl, params, activeIndex } = swiper;
  1510. let activeIndexBuffer = activeIndex;
  1511. if (params.loop) {
  1512. activeIndexBuffer -= swiper.loopedSlides;
  1513. swiper.loopDestroy();
  1514. swiper.slides = $wrapperEl.children(`.${params.slideClass}`);
  1515. }
  1516. const baseLength = swiper.slides.length;
  1517. if (index <= 0) {
  1518. swiper.prependSlide(slides);
  1519. return;
  1520. }
  1521. if (index >= baseLength) {
  1522. swiper.appendSlide(slides);
  1523. return;
  1524. }
  1525. let newActiveIndex = activeIndexBuffer > index ? activeIndexBuffer + 1 : activeIndexBuffer;
  1526. const slidesBuffer = [];
  1527. for (let i = baseLength - 1; i >= index; i -= 1) {
  1528. const currentSlide = swiper.slides.eq(i);
  1529. currentSlide.remove();
  1530. slidesBuffer.unshift(currentSlide);
  1531. }
  1532. if (typeof slides === 'object' && 'length' in slides) {
  1533. for (let i = 0; i < slides.length; i += 1) {
  1534. if (slides[i]) $wrapperEl.append(slides[i]);
  1535. }
  1536. newActiveIndex = activeIndexBuffer > index ? activeIndexBuffer + slides.length : activeIndexBuffer;
  1537. } else {
  1538. $wrapperEl.append(slides);
  1539. }
  1540. for (let i = 0; i < slidesBuffer.length; i += 1) {
  1541. $wrapperEl.append(slidesBuffer[i]);
  1542. }
  1543. if (params.loop) {
  1544. swiper.loopCreate();
  1545. }
  1546. if (!(params.observer && Support.observer)) {
  1547. swiper.update();
  1548. }
  1549. if (params.loop) {
  1550. swiper.slideTo(newActiveIndex + swiper.loopedSlides, 0, false);
  1551. } else {
  1552. swiper.slideTo(newActiveIndex, 0, false);
  1553. }
  1554. }
  1555. function removeSlide (slidesIndexes) {
  1556. const swiper = this;
  1557. const { params, $wrapperEl, activeIndex } = swiper;
  1558. let activeIndexBuffer = activeIndex;
  1559. if (params.loop) {
  1560. activeIndexBuffer -= swiper.loopedSlides;
  1561. swiper.loopDestroy();
  1562. swiper.slides = $wrapperEl.children(`.${params.slideClass}`);
  1563. }
  1564. let newActiveIndex = activeIndexBuffer;
  1565. let indexToRemove;
  1566. if (typeof slidesIndexes === 'object' && 'length' in slidesIndexes) {
  1567. for (let i = 0; i < slidesIndexes.length; i += 1) {
  1568. indexToRemove = slidesIndexes[i];
  1569. if (swiper.slides[indexToRemove]) swiper.slides.eq(indexToRemove).remove();
  1570. if (indexToRemove < newActiveIndex) newActiveIndex -= 1;
  1571. }
  1572. newActiveIndex = Math.max(newActiveIndex, 0);
  1573. } else {
  1574. indexToRemove = slidesIndexes;
  1575. if (swiper.slides[indexToRemove]) swiper.slides.eq(indexToRemove).remove();
  1576. if (indexToRemove < newActiveIndex) newActiveIndex -= 1;
  1577. newActiveIndex = Math.max(newActiveIndex, 0);
  1578. }
  1579. if (params.loop) {
  1580. swiper.loopCreate();
  1581. }
  1582. if (!(params.observer && Support.observer)) {
  1583. swiper.update();
  1584. }
  1585. if (params.loop) {
  1586. swiper.slideTo(newActiveIndex + swiper.loopedSlides, 0, false);
  1587. } else {
  1588. swiper.slideTo(newActiveIndex, 0, false);
  1589. }
  1590. }
  1591. function removeAllSlides () {
  1592. const swiper = this;
  1593. const slidesIndexes = [];
  1594. for (let i = 0; i < swiper.slides.length; i += 1) {
  1595. slidesIndexes.push(i);
  1596. }
  1597. swiper.removeSlide(slidesIndexes);
  1598. }
  1599. var manipulation = {
  1600. appendSlide,
  1601. prependSlide,
  1602. addSlide,
  1603. removeSlide,
  1604. removeAllSlides,
  1605. };
  1606. const Device = (function Device() {
  1607. const platform = window.navigator.platform;
  1608. const ua = window.navigator.userAgent;
  1609. const device = {
  1610. ios: false,
  1611. android: false,
  1612. androidChrome: false,
  1613. desktop: false,
  1614. iphone: false,
  1615. ipod: false,
  1616. ipad: false,
  1617. edge: false,
  1618. ie: false,
  1619. firefox: false,
  1620. macos: false,
  1621. windows: false,
  1622. cordova: !!(window.cordova || window.phonegap),
  1623. phonegap: !!(window.cordova || window.phonegap),
  1624. electron: false,
  1625. };
  1626. const screenWidth = window.screen.width;
  1627. const screenHeight = window.screen.height;
  1628. const android = ua.match(/(Android);?[\s\/]+([\d.]+)?/); // eslint-disable-line
  1629. let ipad = ua.match(/(iPad).*OS\s([\d_]+)/);
  1630. const ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/);
  1631. const iphone = !ipad && ua.match(/(iPhone\sOS|iOS)\s([\d_]+)/);
  1632. const ie = ua.indexOf('MSIE ') >= 0 || ua.indexOf('Trident/') >= 0;
  1633. const edge = ua.indexOf('Edge/') >= 0;
  1634. const firefox = ua.indexOf('Gecko/') >= 0 && ua.indexOf('Firefox/') >= 0;
  1635. const windows = platform === 'Win32';
  1636. const electron = ua.toLowerCase().indexOf('electron') >= 0;
  1637. let macos = platform === 'MacIntel';
  1638. // iPadOs 13 fix
  1639. if (!ipad
  1640. && macos
  1641. && Support.touch
  1642. && (
  1643. (screenWidth === 1024 && screenHeight === 1366) // Pro 12.9
  1644. || (screenWidth === 834 && screenHeight === 1194) // Pro 11
  1645. || (screenWidth === 834 && screenHeight === 1112) // Pro 10.5
  1646. || (screenWidth === 768 && screenHeight === 1024) // other
  1647. )
  1648. ) {
  1649. ipad = ua.match(/(Version)\/([\d.]+)/);
  1650. macos = false;
  1651. }
  1652. device.ie = ie;
  1653. device.edge = edge;
  1654. device.firefox = firefox;
  1655. // Android
  1656. if (android && !windows) {
  1657. device.os = 'android';
  1658. device.osVersion = android[2];
  1659. device.android = true;
  1660. device.androidChrome = ua.toLowerCase().indexOf('chrome') >= 0;
  1661. }
  1662. if (ipad || iphone || ipod) {
  1663. device.os = 'ios';
  1664. device.ios = true;
  1665. }
  1666. // iOS
  1667. if (iphone && !ipod) {
  1668. device.osVersion = iphone[2].replace(/_/g, '.');
  1669. device.iphone = true;
  1670. }
  1671. if (ipad) {
  1672. device.osVersion = ipad[2].replace(/_/g, '.');
  1673. device.ipad = true;
  1674. }
  1675. if (ipod) {
  1676. device.osVersion = ipod[3] ? ipod[3].replace(/_/g, '.') : null;
  1677. device.ipod = true;
  1678. }
  1679. // iOS 8+ changed UA
  1680. if (device.ios && device.osVersion && ua.indexOf('Version/') >= 0) {
  1681. if (device.osVersion.split('.')[0] === '10') {
  1682. device.osVersion = ua.toLowerCase().split('version/')[1].split(' ')[0];
  1683. }
  1684. }
  1685. // Webview
  1686. device.webView = !!((iphone || ipad || ipod) && (ua.match(/.*AppleWebKit(?!.*Safari)/i) || window.navigator.standalone))
  1687. || (window.matchMedia && window.matchMedia('(display-mode: standalone)').matches);
  1688. device.webview = device.webView;
  1689. device.standalone = device.webView;
  1690. // Desktop
  1691. device.desktop = !(device.ios || device.android) || electron;
  1692. if (device.desktop) {
  1693. device.electron = electron;
  1694. device.macos = macos;
  1695. device.windows = windows;
  1696. if (device.macos) {
  1697. device.os = 'macos';
  1698. }
  1699. if (device.windows) {
  1700. device.os = 'windows';
  1701. }
  1702. }
  1703. // Pixel Ratio
  1704. device.pixelRatio = window.devicePixelRatio || 1;
  1705. // Export object
  1706. return device;
  1707. }());
  1708. function onTouchStart (event) {
  1709. const swiper = this;
  1710. const data = swiper.touchEventsData;
  1711. const { params, touches } = swiper;
  1712. if (swiper.animating && params.preventInteractionOnTransition) {
  1713. return;
  1714. }
  1715. let e = event;
  1716. if (e.originalEvent) e = e.originalEvent;
  1717. const $targetEl = $(e.target);
  1718. if (params.touchEventsTarget === 'wrapper') {
  1719. if (!$targetEl.closest(swiper.wrapperEl).length) return;
  1720. }
  1721. data.isTouchEvent = e.type === 'touchstart';
  1722. if (!data.isTouchEvent && 'which' in e && e.which === 3) return;
  1723. if (!data.isTouchEvent && 'button' in e && e.button > 0) return;
  1724. if (data.isTouched && data.isMoved) return;
  1725. if (params.noSwiping && $targetEl.closest(params.noSwipingSelector ? params.noSwipingSelector : `.${params.noSwipingClass}`)[0]) {
  1726. swiper.allowClick = true;
  1727. return;
  1728. }
  1729. if (params.swipeHandler) {
  1730. if (!$targetEl.closest(params.swipeHandler)[0]) return;
  1731. }
  1732. touches.currentX = e.type === 'touchstart' ? e.targetTouches[0].pageX : e.pageX;
  1733. touches.currentY = e.type === 'touchstart' ? e.targetTouches[0].pageY : e.pageY;
  1734. const startX = touches.currentX;
  1735. const startY = touches.currentY;
  1736. // Do NOT start if iOS edge swipe is detected. Otherwise iOS app (UIWebView) cannot swipe-to-go-back anymore
  1737. const edgeSwipeDetection = params.edgeSwipeDetection || params.iOSEdgeSwipeDetection;
  1738. const edgeSwipeThreshold = params.edgeSwipeThreshold || params.iOSEdgeSwipeThreshold;
  1739. if (
  1740. edgeSwipeDetection
  1741. && ((startX <= edgeSwipeThreshold)
  1742. || (startX >= window.screen.width - edgeSwipeThreshold))
  1743. ) {
  1744. return;
  1745. }
  1746. Utils.extend(data, {
  1747. isTouched: true,
  1748. isMoved: false,
  1749. allowTouchCallbacks: true,
  1750. isScrolling: undefined,
  1751. startMoving: undefined,
  1752. });
  1753. touches.startX = startX;
  1754. touches.startY = startY;
  1755. data.touchStartTime = Utils.now();
  1756. swiper.allowClick = true;
  1757. swiper.updateSize();
  1758. swiper.swipeDirection = undefined;
  1759. if (params.threshold > 0) data.allowThresholdMove = false;
  1760. if (e.type !== 'touchstart') {
  1761. let preventDefault = true;
  1762. if ($targetEl.is(data.formElements)) preventDefault = false;
  1763. if (
  1764. document$1.activeElement
  1765. && $(document$1.activeElement).is(data.formElements)
  1766. && document$1.activeElement !== $targetEl[0]
  1767. ) {
  1768. document$1.activeElement.blur();
  1769. }
  1770. const shouldPreventDefault = preventDefault && swiper.allowTouchMove && params.touchStartPreventDefault;
  1771. if (params.touchStartForcePreventDefault || shouldPreventDefault) {
  1772. e.preventDefault();
  1773. }
  1774. }
  1775. swiper.emit('touchStart', e);
  1776. }
  1777. function onTouchMove (event) {
  1778. const swiper = this;
  1779. const data = swiper.touchEventsData;
  1780. const { params, touches, rtlTranslate: rtl } = swiper;
  1781. let e = event;
  1782. if (e.originalEvent) e = e.originalEvent;
  1783. if (!data.isTouched) {
  1784. if (data.startMoving && data.isScrolling) {
  1785. swiper.emit('touchMoveOpposite', e);
  1786. }
  1787. return;
  1788. }
  1789. if (data.isTouchEvent && e.type === 'mousemove') return;
  1790. const targetTouch = e.type === 'touchmove' && e.targetTouches && (e.targetTouches[0] || e.changedTouches[0]);
  1791. const pageX = e.type === 'touchmove' ? targetTouch.pageX : e.pageX;
  1792. const pageY = e.type === 'touchmove' ? targetTouch.pageY : e.pageY;
  1793. if (e.preventedByNestedSwiper) {
  1794. touches.startX = pageX;
  1795. touches.startY = pageY;
  1796. return;
  1797. }
  1798. if (!swiper.allowTouchMove) {
  1799. // isMoved = true;
  1800. swiper.allowClick = false;
  1801. if (data.isTouched) {
  1802. Utils.extend(touches, {
  1803. startX: pageX,
  1804. startY: pageY,
  1805. currentX: pageX,
  1806. currentY: pageY,
  1807. });
  1808. data.touchStartTime = Utils.now();
  1809. }
  1810. return;
  1811. }
  1812. if (data.isTouchEvent && params.touchReleaseOnEdges && !params.loop) {
  1813. if (swiper.isVertical()) {
  1814. // Vertical
  1815. if (
  1816. (pageY < touches.startY && swiper.translate <= swiper.maxTranslate())
  1817. || (pageY > touches.startY && swiper.translate >= swiper.minTranslate())
  1818. ) {
  1819. data.isTouched = false;
  1820. data.isMoved = false;
  1821. return;
  1822. }
  1823. } else if (
  1824. (pageX < touches.startX && swiper.translate <= swiper.maxTranslate())
  1825. || (pageX > touches.startX && swiper.translate >= swiper.minTranslate())
  1826. ) {
  1827. return;
  1828. }
  1829. }
  1830. if (data.isTouchEvent && document$1.activeElement) {
  1831. if (e.target === document$1.activeElement && $(e.target).is(data.formElements)) {
  1832. data.isMoved = true;
  1833. swiper.allowClick = false;
  1834. return;
  1835. }
  1836. }
  1837. if (data.allowTouchCallbacks) {
  1838. swiper.emit('touchMove', e);
  1839. }
  1840. if (e.targetTouches && e.targetTouches.length > 1) return;
  1841. touches.currentX = pageX;
  1842. touches.currentY = pageY;
  1843. const diffX = touches.currentX - touches.startX;
  1844. const diffY = touches.currentY - touches.startY;
  1845. if (swiper.params.threshold && Math.sqrt((diffX ** 2) + (diffY ** 2)) < swiper.params.threshold) return;
  1846. if (typeof data.isScrolling === 'undefined') {
  1847. let touchAngle;
  1848. if ((swiper.isHorizontal() && touches.currentY === touches.startY) || (swiper.isVertical() && touches.currentX === touches.startX)) {
  1849. data.isScrolling = false;
  1850. } else {
  1851. // eslint-disable-next-line
  1852. if ((diffX * diffX) + (diffY * diffY) >= 25) {
  1853. touchAngle = (Math.atan2(Math.abs(diffY), Math.abs(diffX)) * 180) / Math.PI;
  1854. data.isScrolling = swiper.isHorizontal() ? touchAngle > params.touchAngle : (90 - touchAngle > params.touchAngle);
  1855. }
  1856. }
  1857. }
  1858. if (data.isScrolling) {
  1859. swiper.emit('touchMoveOpposite', e);
  1860. }
  1861. if (typeof data.startMoving === 'undefined') {
  1862. if (touches.currentX !== touches.startX || touches.currentY !== touches.startY) {
  1863. data.startMoving = true;
  1864. }
  1865. }
  1866. if (data.isScrolling) {
  1867. data.isTouched = false;
  1868. return;
  1869. }
  1870. if (!data.startMoving) {
  1871. return;
  1872. }
  1873. swiper.allowClick = false;
  1874. if (!params.cssMode) {
  1875. e.preventDefault();
  1876. }
  1877. if (params.touchMoveStopPropagation && !params.nested) {
  1878. e.stopPropagation();
  1879. }
  1880. if (!data.isMoved) {
  1881. if (params.loop) {
  1882. swiper.loopFix();
  1883. }
  1884. data.startTranslate = swiper.getTranslate();
  1885. swiper.setTransition(0);
  1886. if (swiper.animating) {
  1887. swiper.$wrapperEl.trigger('webkitTransitionEnd transitionend');
  1888. }
  1889. data.allowMomentumBounce = false;
  1890. // Grab Cursor
  1891. if (params.grabCursor && (swiper.allowSlideNext === true || swiper.allowSlidePrev === true)) {
  1892. swiper.setGrabCursor(true);
  1893. }
  1894. swiper.emit('sliderFirstMove', e);
  1895. }
  1896. swiper.emit('sliderMove', e);
  1897. data.isMoved = true;
  1898. let diff = swiper.isHorizontal() ? diffX : diffY;
  1899. touches.diff = diff;
  1900. diff *= params.touchRatio;
  1901. if (rtl) diff = -diff;
  1902. swiper.swipeDirection = diff > 0 ? 'prev' : 'next';
  1903. data.currentTranslate = diff + data.startTranslate;
  1904. let disableParentSwiper = true;
  1905. let resistanceRatio = params.resistanceRatio;
  1906. if (params.touchReleaseOnEdges) {
  1907. resistanceRatio = 0;
  1908. }
  1909. if ((diff > 0 && data.currentTranslate > swiper.minTranslate())) {
  1910. disableParentSwiper = false;
  1911. if (params.resistance) data.currentTranslate = (swiper.minTranslate() - 1) + ((-swiper.minTranslate() + data.startTranslate + diff) ** resistanceRatio);
  1912. } else if (diff < 0 && data.currentTranslate < swiper.maxTranslate()) {
  1913. disableParentSwiper = false;
  1914. if (params.resistance) data.currentTranslate = (swiper.maxTranslate() + 1) - ((swiper.maxTranslate() - data.startTranslate - diff) ** resistanceRatio);
  1915. }
  1916. if (disableParentSwiper) {
  1917. e.preventedByNestedSwiper = true;
  1918. }
  1919. // Directions locks
  1920. if (!swiper.allowSlideNext && swiper.swipeDirection === 'next' && data.currentTranslate < data.startTranslate) {
  1921. data.currentTranslate = data.startTranslate;
  1922. }
  1923. if (!swiper.allowSlidePrev && swiper.swipeDirection === 'prev' && data.currentTranslate > data.startTranslate) {
  1924. data.currentTranslate = data.startTranslate;
  1925. }
  1926. // Threshold
  1927. if (params.threshold > 0) {
  1928. if (Math.abs(diff) > params.threshold || data.allowThresholdMove) {
  1929. if (!data.allowThresholdMove) {
  1930. data.allowThresholdMove = true;
  1931. touches.startX = touches.currentX;
  1932. touches.startY = touches.currentY;
  1933. data.currentTranslate = data.startTranslate;
  1934. touches.diff = swiper.isHorizontal() ? touches.currentX - touches.startX : touches.currentY - touches.startY;
  1935. return;
  1936. }
  1937. } else {
  1938. data.currentTranslate = data.startTranslate;
  1939. return;
  1940. }
  1941. }
  1942. if (!params.followFinger || params.cssMode) return;
  1943. // Update active index in free mode
  1944. if (params.freeMode || params.watchSlidesProgress || params.watchSlidesVisibility) {
  1945. swiper.updateActiveIndex();
  1946. swiper.updateSlidesClasses();
  1947. }
  1948. if (params.freeMode) {
  1949. // Velocity
  1950. if (data.velocities.length === 0) {
  1951. data.velocities.push({
  1952. position: touches[swiper.isHorizontal() ? 'startX' : 'startY'],
  1953. time: data.touchStartTime,
  1954. });
  1955. }
  1956. data.velocities.push({
  1957. position: touches[swiper.isHorizontal() ? 'currentX' : 'currentY'],
  1958. time: Utils.now(),
  1959. });
  1960. }
  1961. // Update progress
  1962. swiper.updateProgress(data.currentTranslate);
  1963. // Update translate
  1964. swiper.setTranslate(data.currentTranslate);
  1965. }
  1966. function onTouchEnd (event) {
  1967. const swiper = this;
  1968. const data = swiper.touchEventsData;
  1969. const {
  1970. params, touches, rtlTranslate: rtl, $wrapperEl, slidesGrid, snapGrid,
  1971. } = swiper;
  1972. let e = event;
  1973. if (e.originalEvent) e = e.originalEvent;
  1974. if (data.allowTouchCallbacks) {
  1975. swiper.emit('touchEnd', e);
  1976. }
  1977. data.allowTouchCallbacks = false;
  1978. if (!data.isTouched) {
  1979. if (data.isMoved && params.grabCursor) {
  1980. swiper.setGrabCursor(false);
  1981. }
  1982. data.isMoved = false;
  1983. data.startMoving = false;
  1984. return;
  1985. }
  1986. // Return Grab Cursor
  1987. if (params.grabCursor && data.isMoved && data.isTouched && (swiper.allowSlideNext === true || swiper.allowSlidePrev === true)) {
  1988. swiper.setGrabCursor(false);
  1989. }
  1990. // Time diff
  1991. const touchEndTime = Utils.now();
  1992. const timeDiff = touchEndTime - data.touchStartTime;
  1993. // Tap, doubleTap, Click
  1994. if (swiper.allowClick) {
  1995. swiper.updateClickedSlide(e);
  1996. swiper.emit('tap click', e);
  1997. if (timeDiff < 300 && (touchEndTime - data.lastClickTime) < 300) {
  1998. swiper.emit('doubleTap doubleClick', e);
  1999. }
  2000. }
  2001. data.lastClickTime = Utils.now();
  2002. Utils.nextTick(() => {
  2003. if (!swiper.destroyed) swiper.allowClick = true;
  2004. });
  2005. if (!data.isTouched || !data.isMoved || !swiper.swipeDirection || touches.diff === 0 || data.currentTranslate === data.startTranslate) {
  2006. data.isTouched = false;
  2007. data.isMoved = false;
  2008. data.startMoving = false;
  2009. return;
  2010. }
  2011. data.isTouched = false;
  2012. data.isMoved = false;
  2013. data.startMoving = false;
  2014. let currentPos;
  2015. if (params.followFinger) {
  2016. currentPos = rtl ? swiper.translate : -swiper.translate;
  2017. } else {
  2018. currentPos = -data.currentTranslate;
  2019. }
  2020. if (params.cssMode) {
  2021. return;
  2022. }
  2023. if (params.freeMode) {
  2024. if (currentPos < -swiper.minTranslate()) {
  2025. swiper.slideTo(swiper.activeIndex);
  2026. return;
  2027. }
  2028. if (currentPos > -swiper.maxTranslate()) {
  2029. if (swiper.slides.length < snapGrid.length) {
  2030. swiper.slideTo(snapGrid.length - 1);
  2031. } else {
  2032. swiper.slideTo(swiper.slides.length - 1);
  2033. }
  2034. return;
  2035. }
  2036. if (params.freeModeMomentum) {
  2037. if (data.velocities.length > 1) {
  2038. const lastMoveEvent = data.velocities.pop();
  2039. const velocityEvent = data.velocities.pop();
  2040. const distance = lastMoveEvent.position - velocityEvent.position;
  2041. const time = lastMoveEvent.time - velocityEvent.time;
  2042. swiper.velocity = distance / time;
  2043. swiper.velocity /= 2;
  2044. if (Math.abs(swiper.velocity) < params.freeModeMinimumVelocity) {
  2045. swiper.velocity = 0;
  2046. }
  2047. // this implies that the user stopped moving a finger then released.
  2048. // There would be no events with distance zero, so the last event is stale.
  2049. if (time > 150 || (Utils.now() - lastMoveEvent.time) > 300) {
  2050. swiper.velocity = 0;
  2051. }
  2052. } else {
  2053. swiper.velocity = 0;
  2054. }
  2055. swiper.velocity *= params.freeModeMomentumVelocityRatio;
  2056. data.velocities.length = 0;
  2057. let momentumDuration = 1000 * params.freeModeMomentumRatio;
  2058. const momentumDistance = swiper.velocity * momentumDuration;
  2059. let newPosition = swiper.translate + momentumDistance;
  2060. if (rtl) newPosition = -newPosition;
  2061. let doBounce = false;
  2062. let afterBouncePosition;
  2063. const bounceAmount = Math.abs(swiper.velocity) * 20 * params.freeModeMomentumBounceRatio;
  2064. let needsLoopFix;
  2065. if (newPosition < swiper.maxTranslate()) {
  2066. if (params.freeModeMomentumBounce) {
  2067. if (newPosition + swiper.maxTranslate() < -bounceAmount) {
  2068. newPosition = swiper.maxTranslate() - bounceAmount;
  2069. }
  2070. afterBouncePosition = swiper.maxTranslate();
  2071. doBounce = true;
  2072. data.allowMomentumBounce = true;
  2073. } else {
  2074. newPosition = swiper.maxTranslate();
  2075. }
  2076. if (params.loop && params.centeredSlides) needsLoopFix = true;
  2077. } else if (newPosition > swiper.minTranslate()) {
  2078. if (params.freeModeMomentumBounce) {
  2079. if (newPosition - swiper.minTranslate() > bounceAmount) {
  2080. newPosition = swiper.minTranslate() + bounceAmount;
  2081. }
  2082. afterBouncePosition = swiper.minTranslate();
  2083. doBounce = true;
  2084. data.allowMomentumBounce = true;
  2085. } else {
  2086. newPosition = swiper.minTranslate();
  2087. }
  2088. if (params.loop && params.centeredSlides) needsLoopFix = true;
  2089. } else if (params.freeModeSticky) {
  2090. let nextSlide;
  2091. for (let j = 0; j < snapGrid.length; j += 1) {
  2092. if (snapGrid[j] > -newPosition) {
  2093. nextSlide = j;
  2094. break;
  2095. }
  2096. }
  2097. if (Math.abs(snapGrid[nextSlide] - newPosition) < Math.abs(snapGrid[nextSlide - 1] - newPosition) || swiper.swipeDirection === 'next') {
  2098. newPosition = snapGrid[nextSlide];
  2099. } else {
  2100. newPosition = snapGrid[nextSlide - 1];
  2101. }
  2102. newPosition = -newPosition;
  2103. }
  2104. if (needsLoopFix) {
  2105. swiper.once('transitionEnd', () => {
  2106. swiper.loopFix();
  2107. });
  2108. }
  2109. // Fix duration
  2110. if (swiper.velocity !== 0) {
  2111. if (rtl) {
  2112. momentumDuration = Math.abs((-newPosition - swiper.translate) / swiper.velocity);
  2113. } else {
  2114. momentumDuration = Math.abs((newPosition - swiper.translate) / swiper.velocity);
  2115. }
  2116. if (params.freeModeSticky) {
  2117. // If freeModeSticky is active and the user ends a swipe with a slow-velocity
  2118. // event, then durations can be 20+ seconds to slide one (or zero!) slides.
  2119. // It's easy to see this when simulating touch with mouse events. To fix this,
  2120. // limit single-slide swipes to the default slide duration. This also has the
  2121. // nice side effect of matching slide speed if the user stopped moving before
  2122. // lifting finger or mouse vs. moving slowly before lifting the finger/mouse.
  2123. // For faster swipes, also apply limits (albeit higher ones).
  2124. const moveDistance = Math.abs((rtl ? -newPosition : newPosition) - swiper.translate);
  2125. const currentSlideSize = swiper.slidesSizesGrid[swiper.activeIndex];
  2126. if (moveDistance < currentSlideSize) {
  2127. momentumDuration = params.speed;
  2128. } else if (moveDistance < 2 * currentSlideSize) {
  2129. momentumDuration = params.speed * 1.5;
  2130. } else {
  2131. momentumDuration = params.speed * 2.5;
  2132. }
  2133. }
  2134. } else if (params.freeModeSticky) {
  2135. swiper.slideToClosest();
  2136. return;
  2137. }
  2138. if (params.freeModeMomentumBounce && doBounce) {
  2139. swiper.updateProgress(afterBouncePosition);
  2140. swiper.setTransition(momentumDuration);
  2141. swiper.setTranslate(newPosition);
  2142. swiper.transitionStart(true, swiper.swipeDirection);
  2143. swiper.animating = true;
  2144. $wrapperEl.transitionEnd(() => {
  2145. if (!swiper || swiper.destroyed || !data.allowMomentumBounce) return;
  2146. swiper.emit('momentumBounce');
  2147. swiper.setTransition(params.speed);
  2148. swiper.setTranslate(afterBouncePosition);
  2149. $wrapperEl.transitionEnd(() => {
  2150. if (!swiper || swiper.destroyed) return;
  2151. swiper.transitionEnd();
  2152. });
  2153. });
  2154. } else if (swiper.velocity) {
  2155. swiper.updateProgress(newPosition);
  2156. swiper.setTransition(momentumDuration);
  2157. swiper.setTranslate(newPosition);
  2158. swiper.transitionStart(true, swiper.swipeDirection);
  2159. if (!swiper.animating) {
  2160. swiper.animating = true;
  2161. $wrapperEl.transitionEnd(() => {
  2162. if (!swiper || swiper.destroyed) return;
  2163. swiper.transitionEnd();
  2164. });
  2165. }
  2166. } else {
  2167. swiper.updateProgress(newPosition);
  2168. }
  2169. swiper.updateActiveIndex();
  2170. swiper.updateSlidesClasses();
  2171. } else if (params.freeModeSticky) {
  2172. swiper.slideToClosest();
  2173. return;
  2174. }
  2175. if (!params.freeModeMomentum || timeDiff >= params.longSwipesMs) {
  2176. swiper.updateProgress();
  2177. swiper.updateActiveIndex();
  2178. swiper.updateSlidesClasses();
  2179. }
  2180. return;
  2181. }
  2182. // Find current slide
  2183. let stopIndex = 0;
  2184. let groupSize = swiper.slidesSizesGrid[0];
  2185. for (let i = 0; i < slidesGrid.length; i += (i < params.slidesPerGroupSkip ? 1 : params.slidesPerGroup)) {
  2186. const increment = (i < params.slidesPerGroupSkip - 1 ? 1 : params.slidesPerGroup);
  2187. if (typeof slidesGrid[i + increment] !== 'undefined') {
  2188. if (currentPos >= slidesGrid[i] && currentPos < slidesGrid[i + increment]) {
  2189. stopIndex = i;
  2190. groupSize = slidesGrid[i + increment] - slidesGrid[i];
  2191. }
  2192. } else if (currentPos >= slidesGrid[i]) {
  2193. stopIndex = i;
  2194. groupSize = slidesGrid[slidesGrid.length - 1] - slidesGrid[slidesGrid.length - 2];
  2195. }
  2196. }
  2197. // Find current slide size
  2198. const ratio = (currentPos - slidesGrid[stopIndex]) / groupSize;
  2199. const increment = (stopIndex < params.slidesPerGroupSkip - 1 ? 1 : params.slidesPerGroup);
  2200. if (timeDiff > params.longSwipesMs) {
  2201. // Long touches
  2202. if (!params.longSwipes) {
  2203. swiper.slideTo(swiper.activeIndex);
  2204. return;
  2205. }
  2206. if (swiper.swipeDirection === 'next') {
  2207. if (ratio >= params.longSwipesRatio) swiper.slideTo(stopIndex + increment);
  2208. else swiper.slideTo(stopIndex);
  2209. }
  2210. if (swiper.swipeDirection === 'prev') {
  2211. if (ratio > (1 - params.longSwipesRatio)) swiper.slideTo(stopIndex + increment);
  2212. else swiper.slideTo(stopIndex);
  2213. }
  2214. } else {
  2215. // Short swipes
  2216. if (!params.shortSwipes) {
  2217. swiper.slideTo(swiper.activeIndex);
  2218. return;
  2219. }
  2220. const isNavButtonTarget = swiper.navigation && (e.target === swiper.navigation.nextEl || e.target === swiper.navigation.prevEl);
  2221. if (!isNavButtonTarget) {
  2222. if (swiper.swipeDirection === 'next') {
  2223. swiper.slideTo(stopIndex + increment);
  2224. }
  2225. if (swiper.swipeDirection === 'prev') {
  2226. swiper.slideTo(stopIndex);
  2227. }
  2228. } else if (e.target === swiper.navigation.nextEl) {
  2229. swiper.slideTo(stopIndex + increment);
  2230. } else {
  2231. swiper.slideTo(stopIndex);
  2232. }
  2233. }
  2234. }
  2235. function onResize () {
  2236. const swiper = this;
  2237. const { params, el } = swiper;
  2238. if (el && el.offsetWidth === 0) return;
  2239. // Breakpoints
  2240. if (params.breakpoints) {
  2241. swiper.setBreakpoint();
  2242. }
  2243. // Save locks
  2244. const { allowSlideNext, allowSlidePrev, snapGrid } = swiper;
  2245. // Disable locks on resize
  2246. swiper.allowSlideNext = true;
  2247. swiper.allowSlidePrev = true;
  2248. swiper.updateSize();
  2249. swiper.updateSlides();
  2250. swiper.updateSlidesClasses();
  2251. if ((params.slidesPerView === 'auto' || params.slidesPerView > 1) && swiper.isEnd && !swiper.params.centeredSlides) {
  2252. swiper.slideTo(swiper.slides.length - 1, 0, false, true);
  2253. } else {
  2254. swiper.slideTo(swiper.activeIndex, 0, false, true);
  2255. }
  2256. if (swiper.autoplay && swiper.autoplay.running && swiper.autoplay.paused) {
  2257. swiper.autoplay.run();
  2258. }
  2259. // Return locks after resize
  2260. swiper.allowSlidePrev = allowSlidePrev;
  2261. swiper.allowSlideNext = allowSlideNext;
  2262. if (swiper.params.watchOverflow && snapGrid !== swiper.snapGrid) {
  2263. swiper.checkOverflow();
  2264. }
  2265. }
  2266. function onClick (e) {
  2267. const swiper = this;
  2268. if (!swiper.allowClick) {
  2269. if (swiper.params.preventClicks) e.preventDefault();
  2270. if (swiper.params.preventClicksPropagation && swiper.animating) {
  2271. e.stopPropagation();
  2272. e.stopImmediatePropagation();
  2273. }
  2274. }
  2275. }
  2276. function onScroll () {
  2277. const swiper = this;
  2278. const { wrapperEl } = swiper;
  2279. swiper.previousTranslate = swiper.translate;
  2280. swiper.translate = swiper.isHorizontal() ? -wrapperEl.scrollLeft : -wrapperEl.scrollTop;
  2281. // eslint-disable-next-line
  2282. if (swiper.translate === -0) swiper.translate = 0;
  2283. swiper.updateActiveIndex();
  2284. swiper.updateSlidesClasses();
  2285. let newProgress;
  2286. const translatesDiff = swiper.maxTranslate() - swiper.minTranslate();
  2287. if (translatesDiff === 0) {
  2288. newProgress = 0;
  2289. } else {
  2290. newProgress = (swiper.translate - swiper.minTranslate()) / (translatesDiff);
  2291. }
  2292. if (newProgress !== swiper.progress) {
  2293. swiper.updateProgress(swiper.translate);
  2294. }
  2295. swiper.emit('setTranslate', swiper.translate, false);
  2296. }
  2297. let dummyEventAttached = false;
  2298. function dummyEventListener() {}
  2299. function attachEvents() {
  2300. const swiper = this;
  2301. const {
  2302. params, touchEvents, el, wrapperEl,
  2303. } = swiper;
  2304. swiper.onTouchStart = onTouchStart.bind(swiper);
  2305. swiper.onTouchMove = onTouchMove.bind(swiper);
  2306. swiper.onTouchEnd = onTouchEnd.bind(swiper);
  2307. if (params.cssMode) {
  2308. swiper.onScroll = onScroll.bind(swiper);
  2309. }
  2310. swiper.onClick = onClick.bind(swiper);
  2311. const capture = !!params.nested;
  2312. // Touch Events
  2313. if (!Support.touch && Support.pointerEvents) {
  2314. el.addEventListener(touchEvents.start, swiper.onTouchStart, false);
  2315. document$1.addEventListener(touchEvents.move, swiper.onTouchMove, capture);
  2316. document$1.addEventListener(touchEvents.end, swiper.onTouchEnd, false);
  2317. } else {
  2318. if (Support.touch) {
  2319. const passiveListener = touchEvents.start === 'touchstart' && Support.passiveListener && params.passiveListeners ? { passive: true, capture: false } : false;
  2320. el.addEventListener(touchEvents.start, swiper.onTouchStart, passiveListener);
  2321. el.addEventListener(touchEvents.move, swiper.onTouchMove, Support.passiveListener ? { passive: false, capture } : capture);
  2322. el.addEventListener(touchEvents.end, swiper.onTouchEnd, passiveListener);
  2323. if (touchEvents.cancel) {
  2324. el.addEventListener(touchEvents.cancel, swiper.onTouchEnd, passiveListener);
  2325. }
  2326. if (!dummyEventAttached) {
  2327. document$1.addEventListener('touchstart', dummyEventListener);
  2328. dummyEventAttached = true;
  2329. }
  2330. }
  2331. if ((params.simulateTouch && !Device.ios && !Device.android) || (params.simulateTouch && !Support.touch && Device.ios)) {
  2332. el.addEventListener('mousedown', swiper.onTouchStart, false);
  2333. document$1.addEventListener('mousemove', swiper.onTouchMove, capture);
  2334. document$1.addEventListener('mouseup', swiper.onTouchEnd, false);
  2335. }
  2336. }
  2337. // Prevent Links Clicks
  2338. if (params.preventClicks || params.preventClicksPropagation) {
  2339. el.addEventListener('click', swiper.onClick, true);
  2340. }
  2341. if (params.cssMode) {
  2342. wrapperEl.addEventListener('scroll', swiper.onScroll);
  2343. }
  2344. // Resize handler
  2345. if (params.updateOnWindowResize) {
  2346. swiper.on((Device.ios || Device.android ? 'resize orientationchange observerUpdate' : 'resize observerUpdate'), onResize, true);
  2347. } else {
  2348. swiper.on('observerUpdate', onResize, true);
  2349. }
  2350. }
  2351. function detachEvents() {
  2352. const swiper = this;
  2353. const {
  2354. params, touchEvents, el, wrapperEl,
  2355. } = swiper;
  2356. const capture = !!params.nested;
  2357. // Touch Events
  2358. if (!Support.touch && Support.pointerEvents) {
  2359. el.removeEventListener(touchEvents.start, swiper.onTouchStart, false);
  2360. document$1.removeEventListener(touchEvents.move, swiper.onTouchMove, capture);
  2361. document$1.removeEventListener(touchEvents.end, swiper.onTouchEnd, false);
  2362. } else {
  2363. if (Support.touch) {
  2364. const passiveListener = touchEvents.start === 'onTouchStart' && Support.passiveListener && params.passiveListeners ? { passive: true, capture: false } : false;
  2365. el.removeEventListener(touchEvents.start, swiper.onTouchStart, passiveListener);
  2366. el.removeEventListener(touchEvents.move, swiper.onTouchMove, capture);
  2367. el.removeEventListener(touchEvents.end, swiper.onTouchEnd, passiveListener);
  2368. if (touchEvents.cancel) {
  2369. el.removeEventListener(touchEvents.cancel, swiper.onTouchEnd, passiveListener);
  2370. }
  2371. }
  2372. if ((params.simulateTouch && !Device.ios && !Device.android) || (params.simulateTouch && !Support.touch && Device.ios)) {
  2373. el.removeEventListener('mousedown', swiper.onTouchStart, false);
  2374. document$1.removeEventListener('mousemove', swiper.onTouchMove, capture);
  2375. document$1.removeEventListener('mouseup', swiper.onTouchEnd, false);
  2376. }
  2377. }
  2378. // Prevent Links Clicks
  2379. if (params.preventClicks || params.preventClicksPropagation) {
  2380. el.removeEventListener('click', swiper.onClick, true);
  2381. }
  2382. if (params.cssMode) {
  2383. wrapperEl.removeEventListener('scroll', swiper.onScroll);
  2384. }
  2385. // Resize handler
  2386. swiper.off((Device.ios || Device.android ? 'resize orientationchange observerUpdate' : 'resize observerUpdate'), onResize);
  2387. }
  2388. var events = {
  2389. attachEvents,
  2390. detachEvents,
  2391. };
  2392. function setBreakpoint () {
  2393. const swiper = this;
  2394. const {
  2395. activeIndex, initialized, loopedSlides = 0, params, $el,
  2396. } = swiper;
  2397. const breakpoints = params.breakpoints;
  2398. if (!breakpoints || (breakpoints && Object.keys(breakpoints).length === 0)) return;
  2399. // Get breakpoint for window width and update parameters
  2400. const breakpoint = swiper.getBreakpoint(breakpoints);
  2401. if (breakpoint && swiper.currentBreakpoint !== breakpoint) {
  2402. const breakpointOnlyParams = breakpoint in breakpoints ? breakpoints[breakpoint] : undefined;
  2403. if (breakpointOnlyParams) {
  2404. ['slidesPerView', 'spaceBetween', 'slidesPerGroup', 'slidesPerGroupSkip', 'slidesPerColumn'].forEach((param) => {
  2405. const paramValue = breakpointOnlyParams[param];
  2406. if (typeof paramValue === 'undefined') return;
  2407. if (param === 'slidesPerView' && (paramValue === 'AUTO' || paramValue === 'auto')) {
  2408. breakpointOnlyParams[param] = 'auto';
  2409. } else if (param === 'slidesPerView') {
  2410. breakpointOnlyParams[param] = parseFloat(paramValue);
  2411. } else {
  2412. breakpointOnlyParams[param] = parseInt(paramValue, 10);
  2413. }
  2414. });
  2415. }
  2416. const breakpointParams = breakpointOnlyParams || swiper.originalParams;
  2417. const wasMultiRow = params.slidesPerColumn > 1;
  2418. const isMultiRow = breakpointParams.slidesPerColumn > 1;
  2419. if (wasMultiRow && !isMultiRow) {
  2420. $el.removeClass(`${params.containerModifierClass}multirow ${params.containerModifierClass}multirow-column`);
  2421. } else if (!wasMultiRow && isMultiRow) {
  2422. $el.addClass(`${params.containerModifierClass}multirow`);
  2423. if (breakpointParams.slidesPerColumnFill === 'column') {
  2424. $el.addClass(`${params.containerModifierClass}multirow-column`);
  2425. }
  2426. }
  2427. const directionChanged = breakpointParams.direction && breakpointParams.direction !== params.direction;
  2428. const needsReLoop = params.loop && (breakpointParams.slidesPerView !== params.slidesPerView || directionChanged);
  2429. if (directionChanged && initialized) {
  2430. swiper.changeDirection();
  2431. }
  2432. Utils.extend(swiper.params, breakpointParams);
  2433. Utils.extend(swiper, {
  2434. allowTouchMove: swiper.params.allowTouchMove,
  2435. allowSlideNext: swiper.params.allowSlideNext,
  2436. allowSlidePrev: swiper.params.allowSlidePrev,
  2437. });
  2438. swiper.currentBreakpoint = breakpoint;
  2439. if (needsReLoop && initialized) {
  2440. swiper.loopDestroy();
  2441. swiper.loopCreate();
  2442. swiper.updateSlides();
  2443. swiper.slideTo((activeIndex - loopedSlides) + swiper.loopedSlides, 0, false);
  2444. }
  2445. swiper.emit('breakpoint', breakpointParams);
  2446. }
  2447. }
  2448. function getBreakpoint (breakpoints) {
  2449. // Get breakpoint for window width
  2450. if (!breakpoints) return undefined;
  2451. let breakpoint = false;
  2452. const points = Object.keys(breakpoints).map((point) => {
  2453. if (typeof point === 'string' && point.indexOf('@') === 0) {
  2454. const minRatio = parseFloat(point.substr(1));
  2455. const value = window.innerHeight * minRatio;
  2456. return { value, point };
  2457. }
  2458. return { value: point, point };
  2459. });
  2460. points.sort((a, b) => parseInt(a.value, 10) - parseInt(b.value, 10));
  2461. for (let i = 0; i < points.length; i += 1) {
  2462. const { point, value } = points[i];
  2463. if (value <= window.innerWidth) {
  2464. breakpoint = point;
  2465. }
  2466. }
  2467. return breakpoint || 'max';
  2468. }
  2469. var breakpoints = { setBreakpoint, getBreakpoint };
  2470. function addClasses () {
  2471. const swiper = this;
  2472. const {
  2473. classNames, params, rtl, $el,
  2474. } = swiper;
  2475. const suffixes = [];
  2476. suffixes.push('initialized');
  2477. suffixes.push(params.direction);
  2478. if (params.freeMode) {
  2479. suffixes.push('free-mode');
  2480. }
  2481. if (params.autoHeight) {
  2482. suffixes.push('autoheight');
  2483. }
  2484. if (rtl) {
  2485. suffixes.push('rtl');
  2486. }
  2487. if (params.slidesPerColumn > 1) {
  2488. suffixes.push('multirow');
  2489. if (params.slidesPerColumnFill === 'column') {
  2490. suffixes.push('multirow-column');
  2491. }
  2492. }
  2493. if (Device.android) {
  2494. suffixes.push('android');
  2495. }
  2496. if (Device.ios) {
  2497. suffixes.push('ios');
  2498. }
  2499. if (params.cssMode) {
  2500. suffixes.push('css-mode');
  2501. }
  2502. suffixes.forEach((suffix) => {
  2503. classNames.push(params.containerModifierClass + suffix);
  2504. });
  2505. $el.addClass(classNames.join(' '));
  2506. }
  2507. function removeClasses () {
  2508. const swiper = this;
  2509. const { $el, classNames } = swiper;
  2510. $el.removeClass(classNames.join(' '));
  2511. }
  2512. var classes = { addClasses, removeClasses };
  2513. function loadImage (imageEl, src, srcset, sizes, checkForComplete, callback) {
  2514. let image;
  2515. function onReady() {
  2516. if (callback) callback();
  2517. }
  2518. if (!imageEl.complete || !checkForComplete) {
  2519. if (src) {
  2520. image = new window.Image();
  2521. image.onload = onReady;
  2522. image.onerror = onReady;
  2523. if (sizes) {
  2524. image.sizes = sizes;
  2525. }
  2526. if (srcset) {
  2527. image.srcset = srcset;
  2528. }
  2529. if (src) {
  2530. image.src = src;
  2531. }
  2532. } else {
  2533. onReady();
  2534. }
  2535. } else {
  2536. // image already loaded...
  2537. onReady();
  2538. }
  2539. }
  2540. function preloadImages () {
  2541. const swiper = this;
  2542. swiper.imagesToLoad = swiper.$el.find('img');
  2543. function onReady() {
  2544. if (typeof swiper === 'undefined' || swiper === null || !swiper || swiper.destroyed) return;
  2545. if (swiper.imagesLoaded !== undefined) swiper.imagesLoaded += 1;
  2546. if (swiper.imagesLoaded === swiper.imagesToLoad.length) {
  2547. if (swiper.params.updateOnImagesReady) swiper.update();
  2548. swiper.emit('imagesReady');
  2549. }
  2550. }
  2551. for (let i = 0; i < swiper.imagesToLoad.length; i += 1) {
  2552. const imageEl = swiper.imagesToLoad[i];
  2553. swiper.loadImage(
  2554. imageEl,
  2555. imageEl.currentSrc || imageEl.getAttribute('src'),
  2556. imageEl.srcset || imageEl.getAttribute('srcset'),
  2557. imageEl.sizes || imageEl.getAttribute('sizes'),
  2558. true,
  2559. onReady
  2560. );
  2561. }
  2562. }
  2563. var images = {
  2564. loadImage,
  2565. preloadImages,
  2566. };
  2567. function checkOverflow() {
  2568. const swiper = this;
  2569. const params = swiper.params;
  2570. const wasLocked = swiper.isLocked;
  2571. const lastSlidePosition = swiper.slides.length > 0 && (params.slidesOffsetBefore + (params.spaceBetween * (swiper.slides.length - 1)) + ((swiper.slides[0]).offsetWidth) * swiper.slides.length);
  2572. if (params.slidesOffsetBefore && params.slidesOffsetAfter && lastSlidePosition) {
  2573. swiper.isLocked = lastSlidePosition <= swiper.size;
  2574. } else {
  2575. swiper.isLocked = swiper.snapGrid.length === 1;
  2576. }
  2577. swiper.allowSlideNext = !swiper.isLocked;
  2578. swiper.allowSlidePrev = !swiper.isLocked;
  2579. // events
  2580. if (wasLocked !== swiper.isLocked) swiper.emit(swiper.isLocked ? 'lock' : 'unlock');
  2581. if (wasLocked && wasLocked !== swiper.isLocked) {
  2582. swiper.isEnd = false;
  2583. swiper.navigation.update();
  2584. }
  2585. }
  2586. var checkOverflow$1 = { checkOverflow };
  2587. var defaults = {
  2588. init: true,
  2589. direction: 'horizontal',
  2590. touchEventsTarget: 'container',
  2591. initialSlide: 0,
  2592. speed: 300,
  2593. cssMode: false,
  2594. updateOnWindowResize: true,
  2595. //
  2596. preventInteractionOnTransition: false,
  2597. // To support iOS's swipe-to-go-back gesture (when being used in-app, with UIWebView).
  2598. edgeSwipeDetection: false,
  2599. edgeSwipeThreshold: 20,
  2600. // Free mode
  2601. freeMode: false,
  2602. freeModeMomentum: true,
  2603. freeModeMomentumRatio: 1,
  2604. freeModeMomentumBounce: true,
  2605. freeModeMomentumBounceRatio: 1,
  2606. freeModeMomentumVelocityRatio: 1,
  2607. freeModeSticky: false,
  2608. freeModeMinimumVelocity: 0.02,
  2609. // Autoheight
  2610. autoHeight: false,
  2611. // Set wrapper width
  2612. setWrapperSize: false,
  2613. // Virtual Translate
  2614. virtualTranslate: false,
  2615. // Effects
  2616. effect: 'slide', // 'slide' or 'fade' or 'cube' or 'coverflow' or 'flip'
  2617. // Breakpoints
  2618. breakpoints: undefined,
  2619. // Slides grid
  2620. spaceBetween: 0,
  2621. slidesPerView: 1,
  2622. slidesPerColumn: 1,
  2623. slidesPerColumnFill: 'column',
  2624. slidesPerGroup: 1,
  2625. slidesPerGroupSkip: 0,
  2626. centeredSlides: false,
  2627. centeredSlidesBounds: false,
  2628. slidesOffsetBefore: 0, // in px
  2629. slidesOffsetAfter: 0, // in px
  2630. normalizeSlideIndex: true,
  2631. centerInsufficientSlides: false,
  2632. // Disable swiper and hide navigation when container not overflow
  2633. watchOverflow: false,
  2634. // Round length
  2635. roundLengths: false,
  2636. // Touches
  2637. touchRatio: 1,
  2638. touchAngle: 45,
  2639. simulateTouch: true,
  2640. shortSwipes: true,
  2641. longSwipes: true,
  2642. longSwipesRatio: 0.5,
  2643. longSwipesMs: 300,
  2644. followFinger: true,
  2645. allowTouchMove: true,
  2646. threshold: 0,
  2647. touchMoveStopPropagation: false,
  2648. touchStartPreventDefault: true,
  2649. touchStartForcePreventDefault: false,
  2650. touchReleaseOnEdges: false,
  2651. // Unique Navigation Elements
  2652. uniqueNavElements: true,
  2653. // Resistance
  2654. resistance: true,
  2655. resistanceRatio: 0.85,
  2656. // Progress
  2657. watchSlidesProgress: false,
  2658. watchSlidesVisibility: false,
  2659. // Cursor
  2660. grabCursor: false,
  2661. // Clicks
  2662. preventClicks: true,
  2663. preventClicksPropagation: true,
  2664. slideToClickedSlide: false,
  2665. // Images
  2666. preloadImages: true,
  2667. updateOnImagesReady: true,
  2668. // loop
  2669. loop: false,
  2670. loopAdditionalSlides: 0,
  2671. loopedSlides: null,
  2672. loopFillGroupWithBlank: false,
  2673. // Swiping/no swiping
  2674. allowSlidePrev: true,
  2675. allowSlideNext: true,
  2676. swipeHandler: null, // '.swipe-handler',
  2677. noSwiping: true,
  2678. noSwipingClass: 'swiper-no-swiping',
  2679. noSwipingSelector: null,
  2680. // Passive Listeners
  2681. passiveListeners: true,
  2682. // NS
  2683. containerModifierClass: 'swiper-container-', // NEW
  2684. slideClass: 'swiper-slide',
  2685. slideBlankClass: 'swiper-slide-invisible-blank',
  2686. slideActiveClass: 'swiper-slide-active',
  2687. slideDuplicateActiveClass: 'swiper-slide-duplicate-active',
  2688. slideVisibleClass: 'swiper-slide-visible',
  2689. slideDuplicateClass: 'swiper-slide-duplicate',
  2690. slideNextClass: 'swiper-slide-next',
  2691. slideDuplicateNextClass: 'swiper-slide-duplicate-next',
  2692. slidePrevClass: 'swiper-slide-prev',
  2693. slideDuplicatePrevClass: 'swiper-slide-duplicate-prev',
  2694. wrapperClass: 'swiper-wrapper',
  2695. // Callbacks
  2696. runCallbacksOnInit: true,
  2697. };
  2698. /* eslint no-param-reassign: "off" */
  2699. const prototypes = {
  2700. update,
  2701. translate,
  2702. transition,
  2703. slide,
  2704. loop,
  2705. grabCursor,
  2706. manipulation,
  2707. events,
  2708. breakpoints,
  2709. checkOverflow: checkOverflow$1,
  2710. classes,
  2711. images,
  2712. };
  2713. const extendedDefaults = {};
  2714. class Swiper extends SwiperClass {
  2715. constructor(...args) {
  2716. let el;
  2717. let params;
  2718. if (args.length === 1 && args[0].constructor && args[0].constructor === Object) {
  2719. params = args[0];
  2720. } else {
  2721. [el, params] = args;
  2722. }
  2723. if (!params) params = {};
  2724. params = Utils.extend({}, params);
  2725. if (el && !params.el) params.el = el;
  2726. super(params);
  2727. Object.keys(prototypes).forEach((prototypeGroup) => {
  2728. Object.keys(prototypes[prototypeGroup]).forEach((protoMethod) => {
  2729. if (!Swiper.prototype[protoMethod]) {
  2730. Swiper.prototype[protoMethod] = prototypes[prototypeGroup][protoMethod];
  2731. }
  2732. });
  2733. });
  2734. // Swiper Instance
  2735. const swiper = this;
  2736. if (typeof swiper.modules === 'undefined') {
  2737. swiper.modules = {};
  2738. }
  2739. Object.keys(swiper.modules).forEach((moduleName) => {
  2740. const module = swiper.modules[moduleName];
  2741. if (module.params) {
  2742. const moduleParamName = Object.keys(module.params)[0];
  2743. const moduleParams = module.params[moduleParamName];
  2744. if (typeof moduleParams !== 'object' || moduleParams === null) return;
  2745. if (!(moduleParamName in params && 'enabled' in moduleParams)) return;
  2746. if (params[moduleParamName] === true) {
  2747. params[moduleParamName] = { enabled: true };
  2748. }
  2749. if (
  2750. typeof params[moduleParamName] === 'object'
  2751. && !('enabled' in params[moduleParamName])
  2752. ) {
  2753. params[moduleParamName].enabled = true;
  2754. }
  2755. if (!params[moduleParamName]) params[moduleParamName] = { enabled: false };
  2756. }
  2757. });
  2758. // Extend defaults with modules params
  2759. const swiperParams = Utils.extend({}, defaults);
  2760. swiper.useModulesParams(swiperParams);
  2761. // Extend defaults with passed params
  2762. swiper.params = Utils.extend({}, swiperParams, extendedDefaults, params);
  2763. swiper.originalParams = Utils.extend({}, swiper.params);
  2764. swiper.passedParams = Utils.extend({}, params);
  2765. // Save Dom lib
  2766. swiper.$ = $;
  2767. // Find el
  2768. const $el = $(swiper.params.el);
  2769. el = $el[0];
  2770. if (!el) {
  2771. return undefined;
  2772. }
  2773. if ($el.length > 1) {
  2774. const swipers = [];
  2775. $el.each((index, containerEl) => {
  2776. const newParams = Utils.extend({}, params, { el: containerEl });
  2777. swipers.push(new Swiper(newParams));
  2778. });
  2779. return swipers;
  2780. }
  2781. el.swiper = swiper;
  2782. $el.data('swiper', swiper);
  2783. // Find Wrapper
  2784. let $wrapperEl;
  2785. if (el && el.shadowRoot && el.shadowRoot.querySelector) {
  2786. $wrapperEl = $(el.shadowRoot.querySelector(`.${swiper.params.wrapperClass}`));
  2787. // Children needs to return slot items
  2788. $wrapperEl.children = (options) => $el.children(options);
  2789. } else {
  2790. $wrapperEl = $el.children(`.${swiper.params.wrapperClass}`);
  2791. }
  2792. // Extend Swiper
  2793. Utils.extend(swiper, {
  2794. $el,
  2795. el,
  2796. $wrapperEl,
  2797. wrapperEl: $wrapperEl[0],
  2798. // Classes
  2799. classNames: [],
  2800. // Slides
  2801. slides: $(),
  2802. slidesGrid: [],
  2803. snapGrid: [],
  2804. slidesSizesGrid: [],
  2805. // isDirection
  2806. isHorizontal() {
  2807. return swiper.params.direction === 'horizontal';
  2808. },
  2809. isVertical() {
  2810. return swiper.params.direction === 'vertical';
  2811. },
  2812. // RTL
  2813. rtl: (el.dir.toLowerCase() === 'rtl' || $el.css('direction') === 'rtl'),
  2814. rtlTranslate: swiper.params.direction === 'horizontal' && (el.dir.toLowerCase() === 'rtl' || $el.css('direction') === 'rtl'),
  2815. wrongRTL: $wrapperEl.css('display') === '-webkit-box',
  2816. // Indexes
  2817. activeIndex: 0,
  2818. realIndex: 0,
  2819. //
  2820. isBeginning: true,
  2821. isEnd: false,
  2822. // Props
  2823. translate: 0,
  2824. previousTranslate: 0,
  2825. progress: 0,
  2826. velocity: 0,
  2827. animating: false,
  2828. // Locks
  2829. allowSlideNext: swiper.params.allowSlideNext,
  2830. allowSlidePrev: swiper.params.allowSlidePrev,
  2831. // Touch Events
  2832. touchEvents: (function touchEvents() {
  2833. const touch = ['touchstart', 'touchmove', 'touchend', 'touchcancel'];
  2834. let desktop = ['mousedown', 'mousemove', 'mouseup'];
  2835. if (Support.pointerEvents) {
  2836. desktop = ['pointerdown', 'pointermove', 'pointerup'];
  2837. }
  2838. swiper.touchEventsTouch = {
  2839. start: touch[0],
  2840. move: touch[1],
  2841. end: touch[2],
  2842. cancel: touch[3],
  2843. };
  2844. swiper.touchEventsDesktop = {
  2845. start: desktop[0],
  2846. move: desktop[1],
  2847. end: desktop[2],
  2848. };
  2849. return Support.touch || !swiper.params.simulateTouch ? swiper.touchEventsTouch : swiper.touchEventsDesktop;
  2850. }()),
  2851. touchEventsData: {
  2852. isTouched: undefined,
  2853. isMoved: undefined,
  2854. allowTouchCallbacks: undefined,
  2855. touchStartTime: undefined,
  2856. isScrolling: undefined,
  2857. currentTranslate: undefined,
  2858. startTranslate: undefined,
  2859. allowThresholdMove: undefined,
  2860. // Form elements to match
  2861. formElements: 'input, select, option, textarea, button, video, label',
  2862. // Last click time
  2863. lastClickTime: Utils.now(),
  2864. clickTimeout: undefined,
  2865. // Velocities
  2866. velocities: [],
  2867. allowMomentumBounce: undefined,
  2868. isTouchEvent: undefined,
  2869. startMoving: undefined,
  2870. },
  2871. // Clicks
  2872. allowClick: true,
  2873. // Touches
  2874. allowTouchMove: swiper.params.allowTouchMove,
  2875. touches: {
  2876. startX: 0,
  2877. startY: 0,
  2878. currentX: 0,
  2879. currentY: 0,
  2880. diff: 0,
  2881. },
  2882. // Images
  2883. imagesToLoad: [],
  2884. imagesLoaded: 0,
  2885. });
  2886. // Install Modules
  2887. swiper.useModules();
  2888. // Init
  2889. if (swiper.params.init) {
  2890. swiper.init();
  2891. }
  2892. // Return app instance
  2893. return swiper;
  2894. }
  2895. slidesPerViewDynamic() {
  2896. const swiper = this;
  2897. const {
  2898. params, slides, slidesGrid, size: swiperSize, activeIndex,
  2899. } = swiper;
  2900. let spv = 1;
  2901. if (params.centeredSlides) {
  2902. let slideSize = slides[activeIndex].swiperSlideSize;
  2903. let breakLoop;
  2904. for (let i = activeIndex + 1; i < slides.length; i += 1) {
  2905. if (slides[i] && !breakLoop) {
  2906. slideSize += slides[i].swiperSlideSize;
  2907. spv += 1;
  2908. if (slideSize > swiperSize) breakLoop = true;
  2909. }
  2910. }
  2911. for (let i = activeIndex - 1; i >= 0; i -= 1) {
  2912. if (slides[i] && !breakLoop) {
  2913. slideSize += slides[i].swiperSlideSize;
  2914. spv += 1;
  2915. if (slideSize > swiperSize) breakLoop = true;
  2916. }
  2917. }
  2918. } else {
  2919. for (let i = activeIndex + 1; i < slides.length; i += 1) {
  2920. if (slidesGrid[i] - slidesGrid[activeIndex] < swiperSize) {
  2921. spv += 1;
  2922. }
  2923. }
  2924. }
  2925. return spv;
  2926. }
  2927. update() {
  2928. const swiper = this;
  2929. if (!swiper || swiper.destroyed) return;
  2930. const { snapGrid, params } = swiper;
  2931. // Breakpoints
  2932. if (params.breakpoints) {
  2933. swiper.setBreakpoint();
  2934. }
  2935. swiper.updateSize();
  2936. swiper.updateSlides();
  2937. swiper.updateProgress();
  2938. swiper.updateSlidesClasses();
  2939. function setTranslate() {
  2940. const translateValue = swiper.rtlTranslate ? swiper.translate * -1 : swiper.translate;
  2941. const newTranslate = Math.min(Math.max(translateValue, swiper.maxTranslate()), swiper.minTranslate());
  2942. swiper.setTranslate(newTranslate);
  2943. swiper.updateActiveIndex();
  2944. swiper.updateSlidesClasses();
  2945. }
  2946. let translated;
  2947. if (swiper.params.freeMode) {
  2948. setTranslate();
  2949. if (swiper.params.autoHeight) {
  2950. swiper.updateAutoHeight();
  2951. }
  2952. } else {
  2953. if ((swiper.params.slidesPerView === 'auto' || swiper.params.slidesPerView > 1) && swiper.isEnd && !swiper.params.centeredSlides) {
  2954. translated = swiper.slideTo(swiper.slides.length - 1, 0, false, true);
  2955. } else {
  2956. translated = swiper.slideTo(swiper.activeIndex, 0, false, true);
  2957. }
  2958. if (!translated) {
  2959. setTranslate();
  2960. }
  2961. }
  2962. if (params.watchOverflow && snapGrid !== swiper.snapGrid) {
  2963. swiper.checkOverflow();
  2964. }
  2965. swiper.emit('update');
  2966. }
  2967. changeDirection(newDirection, needUpdate = true) {
  2968. const swiper = this;
  2969. const currentDirection = swiper.params.direction;
  2970. if (!newDirection) {
  2971. // eslint-disable-next-line
  2972. newDirection = currentDirection === 'horizontal' ? 'vertical' : 'horizontal';
  2973. }
  2974. if ((newDirection === currentDirection) || (newDirection !== 'horizontal' && newDirection !== 'vertical')) {
  2975. return swiper;
  2976. }
  2977. swiper.$el
  2978. .removeClass(`${swiper.params.containerModifierClass}${currentDirection}`)
  2979. .addClass(`${swiper.params.containerModifierClass}${newDirection}`);
  2980. swiper.params.direction = newDirection;
  2981. swiper.slides.each((slideIndex, slideEl) => {
  2982. if (newDirection === 'vertical') {
  2983. slideEl.style.width = '';
  2984. } else {
  2985. slideEl.style.height = '';
  2986. }
  2987. });
  2988. swiper.emit('changeDirection');
  2989. if (needUpdate) swiper.update();
  2990. return swiper;
  2991. }
  2992. init() {
  2993. const swiper = this;
  2994. if (swiper.initialized) return;
  2995. swiper.emit('beforeInit');
  2996. // Set breakpoint
  2997. if (swiper.params.breakpoints) {
  2998. swiper.setBreakpoint();
  2999. }
  3000. // Add Classes
  3001. swiper.addClasses();
  3002. // Create loop
  3003. if (swiper.params.loop) {
  3004. swiper.loopCreate();
  3005. }
  3006. // Update size
  3007. swiper.updateSize();
  3008. // Update slides
  3009. swiper.updateSlides();
  3010. if (swiper.params.watchOverflow) {
  3011. swiper.checkOverflow();
  3012. }
  3013. // Set Grab Cursor
  3014. if (swiper.params.grabCursor) {
  3015. swiper.setGrabCursor();
  3016. }
  3017. if (swiper.params.preloadImages) {
  3018. swiper.preloadImages();
  3019. }
  3020. // Slide To Initial Slide
  3021. if (swiper.params.loop) {
  3022. swiper.slideTo(swiper.params.initialSlide + swiper.loopedSlides, 0, swiper.params.runCallbacksOnInit);
  3023. } else {
  3024. swiper.slideTo(swiper.params.initialSlide, 0, swiper.params.runCallbacksOnInit);
  3025. }
  3026. // Attach events
  3027. swiper.attachEvents();
  3028. // Init Flag
  3029. swiper.initialized = true;
  3030. // Emit
  3031. swiper.emit('init');
  3032. }
  3033. destroy(deleteInstance = true, cleanStyles = true) {
  3034. const swiper = this;
  3035. const {
  3036. params, $el, $wrapperEl, slides,
  3037. } = swiper;
  3038. if (typeof swiper.params === 'undefined' || swiper.destroyed) {
  3039. return null;
  3040. }
  3041. swiper.emit('beforeDestroy');
  3042. // Init Flag
  3043. swiper.initialized = false;
  3044. // Detach events
  3045. swiper.detachEvents();
  3046. // Destroy loop
  3047. if (params.loop) {
  3048. swiper.loopDestroy();
  3049. }
  3050. // Cleanup styles
  3051. if (cleanStyles) {
  3052. swiper.removeClasses();
  3053. $el.removeAttr('style');
  3054. $wrapperEl.removeAttr('style');
  3055. if (slides && slides.length) {
  3056. slides
  3057. .removeClass([
  3058. params.slideVisibleClass,
  3059. params.slideActiveClass,
  3060. params.slideNextClass,
  3061. params.slidePrevClass,
  3062. ].join(' '))
  3063. .removeAttr('style')
  3064. .removeAttr('data-swiper-slide-index');
  3065. }
  3066. }
  3067. swiper.emit('destroy');
  3068. // Detach emitter events
  3069. Object.keys(swiper.eventsListeners).forEach((eventName) => {
  3070. swiper.off(eventName);
  3071. });
  3072. if (deleteInstance !== false) {
  3073. swiper.$el[0].swiper = null;
  3074. swiper.$el.data('swiper', null);
  3075. Utils.deleteProps(swiper);
  3076. }
  3077. swiper.destroyed = true;
  3078. return null;
  3079. }
  3080. static extendDefaults(newDefaults) {
  3081. Utils.extend(extendedDefaults, newDefaults);
  3082. }
  3083. static get extendedDefaults() {
  3084. return extendedDefaults;
  3085. }
  3086. static get defaults() {
  3087. return defaults;
  3088. }
  3089. static get Class() {
  3090. return SwiperClass;
  3091. }
  3092. static get $() {
  3093. return $;
  3094. }
  3095. }
  3096. var Device$1 = {
  3097. name: 'device',
  3098. proto: {
  3099. device: Device,
  3100. },
  3101. static: {
  3102. device: Device,
  3103. },
  3104. };
  3105. var Support$1 = {
  3106. name: 'support',
  3107. proto: {
  3108. support: Support,
  3109. },
  3110. static: {
  3111. support: Support,
  3112. },
  3113. };
  3114. const Browser = (function Browser() {
  3115. function isSafari() {
  3116. const ua = window.navigator.userAgent.toLowerCase();
  3117. return (ua.indexOf('safari') >= 0 && ua.indexOf('chrome') < 0 && ua.indexOf('android') < 0);
  3118. }
  3119. return {
  3120. isEdge: !!window.navigator.userAgent.match(/Edge/g),
  3121. isSafari: isSafari(),
  3122. isUiWebView: /(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(window.navigator.userAgent),
  3123. };
  3124. }());
  3125. var Browser$1 = {
  3126. name: 'browser',
  3127. proto: {
  3128. browser: Browser,
  3129. },
  3130. static: {
  3131. browser: Browser,
  3132. },
  3133. };
  3134. var Resize = {
  3135. name: 'resize',
  3136. create() {
  3137. const swiper = this;
  3138. Utils.extend(swiper, {
  3139. resize: {
  3140. resizeHandler() {
  3141. if (!swiper || swiper.destroyed || !swiper.initialized) return;
  3142. swiper.emit('beforeResize');
  3143. swiper.emit('resize');
  3144. },
  3145. orientationChangeHandler() {
  3146. if (!swiper || swiper.destroyed || !swiper.initialized) return;
  3147. swiper.emit('orientationchange');
  3148. },
  3149. },
  3150. });
  3151. },
  3152. on: {
  3153. init() {
  3154. const swiper = this;
  3155. // Emit resize
  3156. window.addEventListener('resize', swiper.resize.resizeHandler);
  3157. // Emit orientationchange
  3158. window.addEventListener('orientationchange', swiper.resize.orientationChangeHandler);
  3159. },
  3160. destroy() {
  3161. const swiper = this;
  3162. window.removeEventListener('resize', swiper.resize.resizeHandler);
  3163. window.removeEventListener('orientationchange', swiper.resize.orientationChangeHandler);
  3164. },
  3165. },
  3166. };
  3167. const Observer = {
  3168. func: window.MutationObserver || window.WebkitMutationObserver,
  3169. attach(target, options = {}) {
  3170. const swiper = this;
  3171. const ObserverFunc = Observer.func;
  3172. const observer = new ObserverFunc((mutations) => {
  3173. // The observerUpdate event should only be triggered
  3174. // once despite the number of mutations. Additional
  3175. // triggers are redundant and are very costly
  3176. if (mutations.length === 1) {
  3177. swiper.emit('observerUpdate', mutations[0]);
  3178. return;
  3179. }
  3180. const observerUpdate = function observerUpdate() {
  3181. swiper.emit('observerUpdate', mutations[0]);
  3182. };
  3183. if (window.requestAnimationFrame) {
  3184. window.requestAnimationFrame(observerUpdate);
  3185. } else {
  3186. window.setTimeout(observerUpdate, 0);
  3187. }
  3188. });
  3189. observer.observe(target, {
  3190. attributes: typeof options.attributes === 'undefined' ? true : options.attributes,
  3191. childList: typeof options.childList === 'undefined' ? true : options.childList,
  3192. characterData: typeof options.characterData === 'undefined' ? true : options.characterData,
  3193. });
  3194. swiper.observer.observers.push(observer);
  3195. },
  3196. init() {
  3197. const swiper = this;
  3198. if (!Support.observer || !swiper.params.observer) return;
  3199. if (swiper.params.observeParents) {
  3200. const containerParents = swiper.$el.parents();
  3201. for (let i = 0; i < containerParents.length; i += 1) {
  3202. swiper.observer.attach(containerParents[i]);
  3203. }
  3204. }
  3205. // Observe container
  3206. swiper.observer.attach(swiper.$el[0], { childList: swiper.params.observeSlideChildren });
  3207. // Observe wrapper
  3208. swiper.observer.attach(swiper.$wrapperEl[0], { attributes: false });
  3209. },
  3210. destroy() {
  3211. const swiper = this;
  3212. swiper.observer.observers.forEach((observer) => {
  3213. observer.disconnect();
  3214. });
  3215. swiper.observer.observers = [];
  3216. },
  3217. };
  3218. var Observer$1 = {
  3219. name: 'observer',
  3220. params: {
  3221. observer: false,
  3222. observeParents: false,
  3223. observeSlideChildren: false,
  3224. },
  3225. create() {
  3226. const swiper = this;
  3227. Utils.extend(swiper, {
  3228. observer: {
  3229. init: Observer.init.bind(swiper),
  3230. attach: Observer.attach.bind(swiper),
  3231. destroy: Observer.destroy.bind(swiper),
  3232. observers: [],
  3233. },
  3234. });
  3235. },
  3236. on: {
  3237. init() {
  3238. const swiper = this;
  3239. swiper.observer.init();
  3240. },
  3241. destroy() {
  3242. const swiper = this;
  3243. swiper.observer.destroy();
  3244. },
  3245. },
  3246. };
  3247. const Virtual = {
  3248. update(force) {
  3249. const swiper = this;
  3250. const { slidesPerView, slidesPerGroup, centeredSlides } = swiper.params;
  3251. const { addSlidesBefore, addSlidesAfter } = swiper.params.virtual;
  3252. const {
  3253. from: previousFrom,
  3254. to: previousTo,
  3255. slides,
  3256. slidesGrid: previousSlidesGrid,
  3257. renderSlide,
  3258. offset: previousOffset,
  3259. } = swiper.virtual;
  3260. swiper.updateActiveIndex();
  3261. const activeIndex = swiper.activeIndex || 0;
  3262. let offsetProp;
  3263. if (swiper.rtlTranslate) offsetProp = 'right';
  3264. else offsetProp = swiper.isHorizontal() ? 'left' : 'top';
  3265. let slidesAfter;
  3266. let slidesBefore;
  3267. if (centeredSlides) {
  3268. slidesAfter = Math.floor(slidesPerView / 2) + slidesPerGroup + addSlidesBefore;
  3269. slidesBefore = Math.floor(slidesPerView / 2) + slidesPerGroup + addSlidesAfter;
  3270. } else {
  3271. slidesAfter = slidesPerView + (slidesPerGroup - 1) + addSlidesBefore;
  3272. slidesBefore = slidesPerGroup + addSlidesAfter;
  3273. }
  3274. const from = Math.max((activeIndex || 0) - slidesBefore, 0);
  3275. const to = Math.min((activeIndex || 0) + slidesAfter, slides.length - 1);
  3276. const offset = (swiper.slidesGrid[from] || 0) - (swiper.slidesGrid[0] || 0);
  3277. Utils.extend(swiper.virtual, {
  3278. from,
  3279. to,
  3280. offset,
  3281. slidesGrid: swiper.slidesGrid,
  3282. });
  3283. function onRendered() {
  3284. swiper.updateSlides();
  3285. swiper.updateProgress();
  3286. swiper.updateSlidesClasses();
  3287. if (swiper.lazy && swiper.params.lazy.enabled) {
  3288. swiper.lazy.load();
  3289. }
  3290. }
  3291. if (previousFrom === from && previousTo === to && !force) {
  3292. if (swiper.slidesGrid !== previousSlidesGrid && offset !== previousOffset) {
  3293. swiper.slides.css(offsetProp, `${offset}px`);
  3294. }
  3295. swiper.updateProgress();
  3296. return;
  3297. }
  3298. if (swiper.params.virtual.renderExternal) {
  3299. swiper.params.virtual.renderExternal.call(swiper, {
  3300. offset,
  3301. from,
  3302. to,
  3303. slides: (function getSlides() {
  3304. const slidesToRender = [];
  3305. for (let i = from; i <= to; i += 1) {
  3306. slidesToRender.push(slides[i]);
  3307. }
  3308. return slidesToRender;
  3309. }()),
  3310. });
  3311. onRendered();
  3312. return;
  3313. }
  3314. const prependIndexes = [];
  3315. const appendIndexes = [];
  3316. if (force) {
  3317. swiper.$wrapperEl.find(`.${swiper.params.slideClass}`).remove();
  3318. } else {
  3319. for (let i = previousFrom; i <= previousTo; i += 1) {
  3320. if (i < from || i > to) {
  3321. swiper.$wrapperEl.find(`.${swiper.params.slideClass}[data-swiper-slide-index="${i}"]`).remove();
  3322. }
  3323. }
  3324. }
  3325. for (let i = 0; i < slides.length; i += 1) {
  3326. if (i >= from && i <= to) {
  3327. if (typeof previousTo === 'undefined' || force) {
  3328. appendIndexes.push(i);
  3329. } else {
  3330. if (i > previousTo) appendIndexes.push(i);
  3331. if (i < previousFrom) prependIndexes.push(i);
  3332. }
  3333. }
  3334. }
  3335. appendIndexes.forEach((index) => {
  3336. swiper.$wrapperEl.append(renderSlide(slides[index], index));
  3337. });
  3338. prependIndexes.sort((a, b) => b - a).forEach((index) => {
  3339. swiper.$wrapperEl.prepend(renderSlide(slides[index], index));
  3340. });
  3341. swiper.$wrapperEl.children('.swiper-slide').css(offsetProp, `${offset}px`);
  3342. onRendered();
  3343. },
  3344. renderSlide(slide, index) {
  3345. const swiper = this;
  3346. const params = swiper.params.virtual;
  3347. if (params.cache && swiper.virtual.cache[index]) {
  3348. return swiper.virtual.cache[index];
  3349. }
  3350. const $slideEl = params.renderSlide
  3351. ? $(params.renderSlide.call(swiper, slide, index))
  3352. : $(`<div class="${swiper.params.slideClass}" data-swiper-slide-index="${index}">${slide}</div>`);
  3353. if (!$slideEl.attr('data-swiper-slide-index')) $slideEl.attr('data-swiper-slide-index', index);
  3354. if (params.cache) swiper.virtual.cache[index] = $slideEl;
  3355. return $slideEl;
  3356. },
  3357. appendSlide(slides) {
  3358. const swiper = this;
  3359. if (typeof slides === 'object' && 'length' in slides) {
  3360. for (let i = 0; i < slides.length; i += 1) {
  3361. if (slides[i]) swiper.virtual.slides.push(slides[i]);
  3362. }
  3363. } else {
  3364. swiper.virtual.slides.push(slides);
  3365. }
  3366. swiper.virtual.update(true);
  3367. },
  3368. prependSlide(slides) {
  3369. const swiper = this;
  3370. const activeIndex = swiper.activeIndex;
  3371. let newActiveIndex = activeIndex + 1;
  3372. let numberOfNewSlides = 1;
  3373. if (Array.isArray(slides)) {
  3374. for (let i = 0; i < slides.length; i += 1) {
  3375. if (slides[i]) swiper.virtual.slides.unshift(slides[i]);
  3376. }
  3377. newActiveIndex = activeIndex + slides.length;
  3378. numberOfNewSlides = slides.length;
  3379. } else {
  3380. swiper.virtual.slides.unshift(slides);
  3381. }
  3382. if (swiper.params.virtual.cache) {
  3383. const cache = swiper.virtual.cache;
  3384. const newCache = {};
  3385. Object.keys(cache).forEach((cachedIndex) => {
  3386. const $cachedEl = cache[cachedIndex];
  3387. const cachedElIndex = $cachedEl.attr('data-swiper-slide-index');
  3388. if (cachedElIndex) {
  3389. $cachedEl.attr('data-swiper-slide-index', parseInt(cachedElIndex, 10) + 1);
  3390. }
  3391. newCache[parseInt(cachedIndex, 10) + numberOfNewSlides] = $cachedEl;
  3392. });
  3393. swiper.virtual.cache = newCache;
  3394. }
  3395. swiper.virtual.update(true);
  3396. swiper.slideTo(newActiveIndex, 0);
  3397. },
  3398. removeSlide(slidesIndexes) {
  3399. const swiper = this;
  3400. if (typeof slidesIndexes === 'undefined' || slidesIndexes === null) return;
  3401. let activeIndex = swiper.activeIndex;
  3402. if (Array.isArray(slidesIndexes)) {
  3403. for (let i = slidesIndexes.length - 1; i >= 0; i -= 1) {
  3404. swiper.virtual.slides.splice(slidesIndexes[i], 1);
  3405. if (swiper.params.virtual.cache) {
  3406. delete swiper.virtual.cache[slidesIndexes[i]];
  3407. }
  3408. if (slidesIndexes[i] < activeIndex) activeIndex -= 1;
  3409. activeIndex = Math.max(activeIndex, 0);
  3410. }
  3411. } else {
  3412. swiper.virtual.slides.splice(slidesIndexes, 1);
  3413. if (swiper.params.virtual.cache) {
  3414. delete swiper.virtual.cache[slidesIndexes];
  3415. }
  3416. if (slidesIndexes < activeIndex) activeIndex -= 1;
  3417. activeIndex = Math.max(activeIndex, 0);
  3418. }
  3419. swiper.virtual.update(true);
  3420. swiper.slideTo(activeIndex, 0);
  3421. },
  3422. removeAllSlides() {
  3423. const swiper = this;
  3424. swiper.virtual.slides = [];
  3425. if (swiper.params.virtual.cache) {
  3426. swiper.virtual.cache = {};
  3427. }
  3428. swiper.virtual.update(true);
  3429. swiper.slideTo(0, 0);
  3430. },
  3431. };
  3432. var virtual = {
  3433. name: 'virtual',
  3434. params: {
  3435. virtual: {
  3436. enabled: false,
  3437. slides: [],
  3438. cache: true,
  3439. renderSlide: null,
  3440. renderExternal: null,
  3441. addSlidesBefore: 0,
  3442. addSlidesAfter: 0,
  3443. },
  3444. },
  3445. create() {
  3446. const swiper = this;
  3447. Utils.extend(swiper, {
  3448. virtual: {
  3449. update: Virtual.update.bind(swiper),
  3450. appendSlide: Virtual.appendSlide.bind(swiper),
  3451. prependSlide: Virtual.prependSlide.bind(swiper),
  3452. removeSlide: Virtual.removeSlide.bind(swiper),
  3453. removeAllSlides: Virtual.removeAllSlides.bind(swiper),
  3454. renderSlide: Virtual.renderSlide.bind(swiper),
  3455. slides: swiper.params.virtual.slides,
  3456. cache: {},
  3457. },
  3458. });
  3459. },
  3460. on: {
  3461. beforeInit() {
  3462. const swiper = this;
  3463. if (!swiper.params.virtual.enabled) return;
  3464. swiper.classNames.push(`${swiper.params.containerModifierClass}virtual`);
  3465. const overwriteParams = {
  3466. watchSlidesProgress: true,
  3467. };
  3468. Utils.extend(swiper.params, overwriteParams);
  3469. Utils.extend(swiper.originalParams, overwriteParams);
  3470. if (!swiper.params.initialSlide) {
  3471. swiper.virtual.update();
  3472. }
  3473. },
  3474. setTranslate() {
  3475. const swiper = this;
  3476. if (!swiper.params.virtual.enabled) return;
  3477. swiper.virtual.update();
  3478. },
  3479. },
  3480. };
  3481. const Keyboard = {
  3482. handle(event) {
  3483. const swiper = this;
  3484. const { rtlTranslate: rtl } = swiper;
  3485. let e = event;
  3486. if (e.originalEvent) e = e.originalEvent; // jquery fix
  3487. const kc = e.keyCode || e.charCode;
  3488. // Directions locks
  3489. if (!swiper.allowSlideNext && ((swiper.isHorizontal() && kc === 39) || (swiper.isVertical() && kc === 40) || kc === 34)) {
  3490. return false;
  3491. }
  3492. if (!swiper.allowSlidePrev && ((swiper.isHorizontal() && kc === 37) || (swiper.isVertical() && kc === 38) || kc === 33)) {
  3493. return false;
  3494. }
  3495. if (e.shiftKey || e.altKey || e.ctrlKey || e.metaKey) {
  3496. return undefined;
  3497. }
  3498. if (document$1.activeElement && document$1.activeElement.nodeName && (document$1.activeElement.nodeName.toLowerCase() === 'input' || document$1.activeElement.nodeName.toLowerCase() === 'textarea')) {
  3499. return undefined;
  3500. }
  3501. if (swiper.params.keyboard.onlyInViewport && (kc === 33 || kc === 34 || kc === 37 || kc === 39 || kc === 38 || kc === 40)) {
  3502. let inView = false;
  3503. // Check that swiper should be inside of visible area of window
  3504. if (swiper.$el.parents(`.${swiper.params.slideClass}`).length > 0 && swiper.$el.parents(`.${swiper.params.slideActiveClass}`).length === 0) {
  3505. return undefined;
  3506. }
  3507. const windowWidth = window.innerWidth;
  3508. const windowHeight = window.innerHeight;
  3509. const swiperOffset = swiper.$el.offset();
  3510. if (rtl) swiperOffset.left -= swiper.$el[0].scrollLeft;
  3511. const swiperCoord = [
  3512. [swiperOffset.left, swiperOffset.top],
  3513. [swiperOffset.left + swiper.width, swiperOffset.top],
  3514. [swiperOffset.left, swiperOffset.top + swiper.height],
  3515. [swiperOffset.left + swiper.width, swiperOffset.top + swiper.height],
  3516. ];
  3517. for (let i = 0; i < swiperCoord.length; i += 1) {
  3518. const point = swiperCoord[i];
  3519. if (
  3520. point[0] >= 0 && point[0] <= windowWidth
  3521. && point[1] >= 0 && point[1] <= windowHeight
  3522. ) {
  3523. inView = true;
  3524. }
  3525. }
  3526. if (!inView) return undefined;
  3527. }
  3528. if (swiper.isHorizontal()) {
  3529. if (kc === 33 || kc === 34 || kc === 37 || kc === 39) {
  3530. if (e.preventDefault) e.preventDefault();
  3531. else e.returnValue = false;
  3532. }
  3533. if (((kc === 34 || kc === 39) && !rtl) || ((kc === 33 || kc === 37) && rtl)) swiper.slideNext();
  3534. if (((kc === 33 || kc === 37) && !rtl) || ((kc === 34 || kc === 39) && rtl)) swiper.slidePrev();
  3535. } else {
  3536. if (kc === 33 || kc === 34 || kc === 38 || kc === 40) {
  3537. if (e.preventDefault) e.preventDefault();
  3538. else e.returnValue = false;
  3539. }
  3540. if (kc === 34 || kc === 40) swiper.slideNext();
  3541. if (kc === 33 || kc === 38) swiper.slidePrev();
  3542. }
  3543. swiper.emit('keyPress', kc);
  3544. return undefined;
  3545. },
  3546. enable() {
  3547. const swiper = this;
  3548. if (swiper.keyboard.enabled) return;
  3549. $(document$1).on('keydown', swiper.keyboard.handle);
  3550. swiper.keyboard.enabled = true;
  3551. },
  3552. disable() {
  3553. const swiper = this;
  3554. if (!swiper.keyboard.enabled) return;
  3555. $(document$1).off('keydown', swiper.keyboard.handle);
  3556. swiper.keyboard.enabled = false;
  3557. },
  3558. };
  3559. var keyboard = {
  3560. name: 'keyboard',
  3561. params: {
  3562. keyboard: {
  3563. enabled: false,
  3564. onlyInViewport: true,
  3565. },
  3566. },
  3567. create() {
  3568. const swiper = this;
  3569. Utils.extend(swiper, {
  3570. keyboard: {
  3571. enabled: false,
  3572. enable: Keyboard.enable.bind(swiper),
  3573. disable: Keyboard.disable.bind(swiper),
  3574. handle: Keyboard.handle.bind(swiper),
  3575. },
  3576. });
  3577. },
  3578. on: {
  3579. init() {
  3580. const swiper = this;
  3581. if (swiper.params.keyboard.enabled) {
  3582. swiper.keyboard.enable();
  3583. }
  3584. },
  3585. destroy() {
  3586. const swiper = this;
  3587. if (swiper.keyboard.enabled) {
  3588. swiper.keyboard.disable();
  3589. }
  3590. },
  3591. },
  3592. };
  3593. function isEventSupported() {
  3594. const eventName = 'onwheel';
  3595. let isSupported = eventName in document$1;
  3596. if (!isSupported) {
  3597. const element = document$1.createElement('div');
  3598. element.setAttribute(eventName, 'return;');
  3599. isSupported = typeof element[eventName] === 'function';
  3600. }
  3601. if (!isSupported
  3602. && document$1.implementation
  3603. && document$1.implementation.hasFeature
  3604. // always returns true in newer browsers as per the standard.
  3605. // @see http://dom.spec.whatwg.org/#dom-domimplementation-hasfeature
  3606. && document$1.implementation.hasFeature('', '') !== true
  3607. ) {
  3608. // This is the only way to test support for the `wheel` event in IE9+.
  3609. isSupported = document$1.implementation.hasFeature('Events.wheel', '3.0');
  3610. }
  3611. return isSupported;
  3612. }
  3613. const Mousewheel = {
  3614. lastScrollTime: Utils.now(),
  3615. lastEventBeforeSnap: undefined,
  3616. recentWheelEvents: [],
  3617. event() {
  3618. if (window.navigator.userAgent.indexOf('firefox') > -1) return 'DOMMouseScroll';
  3619. return isEventSupported() ? 'wheel' : 'mousewheel';
  3620. },
  3621. normalize(e) {
  3622. // Reasonable defaults
  3623. const PIXEL_STEP = 10;
  3624. const LINE_HEIGHT = 40;
  3625. const PAGE_HEIGHT = 800;
  3626. let sX = 0;
  3627. let sY = 0; // spinX, spinY
  3628. let pX = 0;
  3629. let pY = 0; // pixelX, pixelY
  3630. // Legacy
  3631. if ('detail' in e) {
  3632. sY = e.detail;
  3633. }
  3634. if ('wheelDelta' in e) {
  3635. sY = -e.wheelDelta / 120;
  3636. }
  3637. if ('wheelDeltaY' in e) {
  3638. sY = -e.wheelDeltaY / 120;
  3639. }
  3640. if ('wheelDeltaX' in e) {
  3641. sX = -e.wheelDeltaX / 120;
  3642. }
  3643. // side scrolling on FF with DOMMouseScroll
  3644. if ('axis' in e && e.axis === e.HORIZONTAL_AXIS) {
  3645. sX = sY;
  3646. sY = 0;
  3647. }
  3648. pX = sX * PIXEL_STEP;
  3649. pY = sY * PIXEL_STEP;
  3650. if ('deltaY' in e) {
  3651. pY = e.deltaY;
  3652. }
  3653. if ('deltaX' in e) {
  3654. pX = e.deltaX;
  3655. }
  3656. if (e.shiftKey && !pX) { // if user scrolls with shift he wants horizontal scroll
  3657. pX = pY;
  3658. pY = 0;
  3659. }
  3660. if ((pX || pY) && e.deltaMode) {
  3661. if (e.deltaMode === 1) { // delta in LINE units
  3662. pX *= LINE_HEIGHT;
  3663. pY *= LINE_HEIGHT;
  3664. } else { // delta in PAGE units
  3665. pX *= PAGE_HEIGHT;
  3666. pY *= PAGE_HEIGHT;
  3667. }
  3668. }
  3669. // Fall-back if spin cannot be determined
  3670. if (pX && !sX) {
  3671. sX = (pX < 1) ? -1 : 1;
  3672. }
  3673. if (pY && !sY) {
  3674. sY = (pY < 1) ? -1 : 1;
  3675. }
  3676. return {
  3677. spinX: sX,
  3678. spinY: sY,
  3679. pixelX: pX,
  3680. pixelY: pY,
  3681. };
  3682. },
  3683. handleMouseEnter() {
  3684. const swiper = this;
  3685. swiper.mouseEntered = true;
  3686. },
  3687. handleMouseLeave() {
  3688. const swiper = this;
  3689. swiper.mouseEntered = false;
  3690. },
  3691. handle(event) {
  3692. let e = event;
  3693. const swiper = this;
  3694. const params = swiper.params.mousewheel;
  3695. if (swiper.params.cssMode) {
  3696. e.preventDefault();
  3697. }
  3698. let target = swiper.$el;
  3699. if (swiper.params.mousewheel.eventsTarged !== 'container') {
  3700. target = $(swiper.params.mousewheel.eventsTarged);
  3701. }
  3702. if (!swiper.mouseEntered && !target[0].contains(e.target) && !params.releaseOnEdges) return true;
  3703. if (e.originalEvent) e = e.originalEvent; // jquery fix
  3704. let delta = 0;
  3705. const rtlFactor = swiper.rtlTranslate ? -1 : 1;
  3706. const data = Mousewheel.normalize(e);
  3707. if (params.forceToAxis) {
  3708. if (swiper.isHorizontal()) {
  3709. if (Math.abs(data.pixelX) > Math.abs(data.pixelY)) delta = data.pixelX * rtlFactor;
  3710. else return true;
  3711. } else if (Math.abs(data.pixelY) > Math.abs(data.pixelX)) delta = data.pixelY;
  3712. else return true;
  3713. } else {
  3714. delta = Math.abs(data.pixelX) > Math.abs(data.pixelY) ? -data.pixelX * rtlFactor : -data.pixelY;
  3715. }
  3716. if (delta === 0) return true;
  3717. if (params.invert) delta = -delta;
  3718. if (!swiper.params.freeMode) {
  3719. // Register the new event in a variable which stores the relevant data
  3720. const newEvent = {
  3721. time: Utils.now(),
  3722. delta: Math.abs(delta),
  3723. direction: Math.sign(delta),
  3724. raw: event,
  3725. };
  3726. // Keep the most recent events
  3727. const recentWheelEvents = swiper.mousewheel.recentWheelEvents;
  3728. if (recentWheelEvents.length >= 2) {
  3729. recentWheelEvents.shift(); // only store the last N events
  3730. }
  3731. const prevEvent = recentWheelEvents.length ? recentWheelEvents[recentWheelEvents.length - 1] : undefined;
  3732. recentWheelEvents.push(newEvent);
  3733. // If there is at least one previous recorded event:
  3734. // If direction has changed or
  3735. // if the scroll is quicker than the previous one:
  3736. // Animate the slider.
  3737. // Else (this is the first time the wheel is moved):
  3738. // Animate the slider.
  3739. if (prevEvent) {
  3740. if (newEvent.direction !== prevEvent.direction || newEvent.delta > prevEvent.delta) {
  3741. swiper.mousewheel.animateSlider(newEvent);
  3742. }
  3743. } else {
  3744. swiper.mousewheel.animateSlider(newEvent);
  3745. }
  3746. // If it's time to release the scroll:
  3747. // Return now so you don't hit the preventDefault.
  3748. if (swiper.mousewheel.releaseScroll(newEvent)) {
  3749. return true;
  3750. }
  3751. } else {
  3752. // Freemode or scrollContainer:
  3753. // If we recently snapped after a momentum scroll, then ignore wheel events
  3754. // to give time for the deceleration to finish. Stop ignoring after 500 msecs
  3755. // or if it's a new scroll (larger delta or inverse sign as last event before
  3756. // an end-of-momentum snap).
  3757. const newEvent = { time: Utils.now(), delta: Math.abs(delta), direction: Math.sign(delta) };
  3758. const { lastEventBeforeSnap } = swiper.mousewheel;
  3759. const ignoreWheelEvents = lastEventBeforeSnap
  3760. && newEvent.time < lastEventBeforeSnap.time + 500
  3761. && newEvent.delta <= lastEventBeforeSnap.delta
  3762. && newEvent.direction === lastEventBeforeSnap.direction;
  3763. if (!ignoreWheelEvents) {
  3764. swiper.mousewheel.lastEventBeforeSnap = undefined;
  3765. if (swiper.params.loop) {
  3766. swiper.loopFix();
  3767. }
  3768. let position = swiper.getTranslate() + (delta * params.sensitivity);
  3769. const wasBeginning = swiper.isBeginning;
  3770. const wasEnd = swiper.isEnd;
  3771. if (position >= swiper.minTranslate()) position = swiper.minTranslate();
  3772. if (position <= swiper.maxTranslate()) position = swiper.maxTranslate();
  3773. swiper.setTransition(0);
  3774. swiper.setTranslate(position);
  3775. swiper.updateProgress();
  3776. swiper.updateActiveIndex();
  3777. swiper.updateSlidesClasses();
  3778. if ((!wasBeginning && swiper.isBeginning) || (!wasEnd && swiper.isEnd)) {
  3779. swiper.updateSlidesClasses();
  3780. }
  3781. if (swiper.params.freeModeSticky) {
  3782. // When wheel scrolling starts with sticky (aka snap) enabled, then detect
  3783. // the end of a momentum scroll by storing recent (N=15?) wheel events.
  3784. // 1. do all N events have decreasing or same (absolute value) delta?
  3785. // 2. did all N events arrive in the last M (M=500?) msecs?
  3786. // 3. does the earliest event have an (absolute value) delta that's
  3787. // at least P (P=1?) larger than the most recent event's delta?
  3788. // 4. does the latest event have a delta that's smaller than Q (Q=6?) pixels?
  3789. // If 1-4 are "yes" then we're near the end of a momuntum scroll deceleration.
  3790. // Snap immediately and ignore remaining wheel events in this scroll.
  3791. // See comment above for "remaining wheel events in this scroll" determination.
  3792. // If 1-4 aren't satisfied, then wait to snap until 500ms after the last event.
  3793. clearTimeout(swiper.mousewheel.timeout);
  3794. swiper.mousewheel.timeout = undefined;
  3795. const recentWheelEvents = swiper.mousewheel.recentWheelEvents;
  3796. if (recentWheelEvents.length >= 15) {
  3797. recentWheelEvents.shift(); // only store the last N events
  3798. }
  3799. const prevEvent = recentWheelEvents.length ? recentWheelEvents[recentWheelEvents.length - 1] : undefined;
  3800. const firstEvent = recentWheelEvents[0];
  3801. recentWheelEvents.push(newEvent);
  3802. if (prevEvent && (newEvent.delta > prevEvent.delta || newEvent.direction !== prevEvent.direction)) {
  3803. // Increasing or reverse-sign delta means the user started scrolling again. Clear the wheel event log.
  3804. recentWheelEvents.splice(0);
  3805. } else if (recentWheelEvents.length >= 15
  3806. && newEvent.time - firstEvent.time < 500
  3807. && firstEvent.delta - newEvent.delta >= 1
  3808. && newEvent.delta <= 6
  3809. ) {
  3810. // We're at the end of the deceleration of a momentum scroll, so there's no need
  3811. // to wait for more events. Snap ASAP on the next tick.
  3812. // Also, because there's some remaining momentum we'll bias the snap in the
  3813. // direction of the ongoing scroll because it's better UX for the scroll to snap
  3814. // in the same direction as the scroll instead of reversing to snap. Therefore,
  3815. // if it's already scrolled more than 20% in the current direction, keep going.
  3816. const snapToThreshold = delta > 0 ? 0.8 : 0.2;
  3817. swiper.mousewheel.lastEventBeforeSnap = newEvent;
  3818. recentWheelEvents.splice(0);
  3819. swiper.mousewheel.timeout = Utils.nextTick(() => {
  3820. swiper.slideToClosest(swiper.params.speed, true, undefined, snapToThreshold);
  3821. }, 0); // no delay; move on next tick
  3822. }
  3823. if (!swiper.mousewheel.timeout) {
  3824. // if we get here, then we haven't detected the end of a momentum scroll, so
  3825. // we'll consider a scroll "complete" when there haven't been any wheel events
  3826. // for 500ms.
  3827. swiper.mousewheel.timeout = Utils.nextTick(() => {
  3828. const snapToThreshold = 0.5;
  3829. swiper.mousewheel.lastEventBeforeSnap = newEvent;
  3830. recentWheelEvents.splice(0);
  3831. swiper.slideToClosest(swiper.params.speed, true, undefined, snapToThreshold);
  3832. }, 500);
  3833. }
  3834. }
  3835. // Emit event
  3836. if (!ignoreWheelEvents) swiper.emit('scroll', e);
  3837. // Stop autoplay
  3838. if (swiper.params.autoplay && swiper.params.autoplayDisableOnInteraction) swiper.autoplay.stop();
  3839. // Return page scroll on edge positions
  3840. if (position === swiper.minTranslate() || position === swiper.maxTranslate()) return true;
  3841. }
  3842. }
  3843. if (e.preventDefault) e.preventDefault();
  3844. else e.returnValue = false;
  3845. return false;
  3846. },
  3847. animateSlider(newEvent) {
  3848. const swiper = this;
  3849. // If the movement is NOT big enough and
  3850. // if the last time the user scrolled was too close to the current one (avoid continuously triggering the slider):
  3851. // Don't go any further (avoid insignificant scroll movement).
  3852. if (newEvent.delta >= 6 && Utils.now() - swiper.mousewheel.lastScrollTime < 60) {
  3853. // Return false as a default
  3854. return true;
  3855. }
  3856. // If user is scrolling towards the end:
  3857. // If the slider hasn't hit the latest slide or
  3858. // if the slider is a loop and
  3859. // if the slider isn't moving right now:
  3860. // Go to next slide and
  3861. // emit a scroll event.
  3862. // Else (the user is scrolling towards the beginning) and
  3863. // if the slider hasn't hit the first slide or
  3864. // if the slider is a loop and
  3865. // if the slider isn't moving right now:
  3866. // Go to prev slide and
  3867. // emit a scroll event.
  3868. if (newEvent.direction < 0) {
  3869. if ((!swiper.isEnd || swiper.params.loop) && !swiper.animating) {
  3870. swiper.slideNext();
  3871. swiper.emit('scroll', newEvent.raw);
  3872. }
  3873. } else if ((!swiper.isBeginning || swiper.params.loop) && !swiper.animating) {
  3874. swiper.slidePrev();
  3875. swiper.emit('scroll', newEvent.raw);
  3876. }
  3877. // If you got here is because an animation has been triggered so store the current time
  3878. swiper.mousewheel.lastScrollTime = (new window.Date()).getTime();
  3879. // Return false as a default
  3880. return false;
  3881. },
  3882. releaseScroll(newEvent) {
  3883. const swiper = this;
  3884. const params = swiper.params.mousewheel;
  3885. if (newEvent.direction < 0) {
  3886. if (swiper.isEnd && !swiper.params.loop && params.releaseOnEdges) {
  3887. // Return true to animate scroll on edges
  3888. return true;
  3889. }
  3890. } else if (swiper.isBeginning && !swiper.params.loop && params.releaseOnEdges) {
  3891. // Return true to animate scroll on edges
  3892. return true;
  3893. }
  3894. return false;
  3895. },
  3896. enable() {
  3897. const swiper = this;
  3898. const event = Mousewheel.event();
  3899. if (swiper.params.cssMode) {
  3900. swiper.wrapperEl.removeEventListener(event, swiper.mousewheel.handle);
  3901. return true;
  3902. }
  3903. if (!event) return false;
  3904. if (swiper.mousewheel.enabled) return false;
  3905. let target = swiper.$el;
  3906. if (swiper.params.mousewheel.eventsTarged !== 'container') {
  3907. target = $(swiper.params.mousewheel.eventsTarged);
  3908. }
  3909. target.on('mouseenter', swiper.mousewheel.handleMouseEnter);
  3910. target.on('mouseleave', swiper.mousewheel.handleMouseLeave);
  3911. target.on(event, swiper.mousewheel.handle);
  3912. swiper.mousewheel.enabled = true;
  3913. return true;
  3914. },
  3915. disable() {
  3916. const swiper = this;
  3917. const event = Mousewheel.event();
  3918. if (swiper.params.cssMode) {
  3919. swiper.wrapperEl.addEventListener(event, swiper.mousewheel.handle);
  3920. return true;
  3921. }
  3922. if (!event) return false;
  3923. if (!swiper.mousewheel.enabled) return false;
  3924. let target = swiper.$el;
  3925. if (swiper.params.mousewheel.eventsTarged !== 'container') {
  3926. target = $(swiper.params.mousewheel.eventsTarged);
  3927. }
  3928. target.off(event, swiper.mousewheel.handle);
  3929. swiper.mousewheel.enabled = false;
  3930. return true;
  3931. },
  3932. };
  3933. var mousewheel = {
  3934. name: 'mousewheel',
  3935. params: {
  3936. mousewheel: {
  3937. enabled: false,
  3938. releaseOnEdges: false,
  3939. invert: false,
  3940. forceToAxis: false,
  3941. sensitivity: 1,
  3942. eventsTarged: 'container',
  3943. },
  3944. },
  3945. create() {
  3946. const swiper = this;
  3947. Utils.extend(swiper, {
  3948. mousewheel: {
  3949. enabled: false,
  3950. enable: Mousewheel.enable.bind(swiper),
  3951. disable: Mousewheel.disable.bind(swiper),
  3952. handle: Mousewheel.handle.bind(swiper),
  3953. handleMouseEnter: Mousewheel.handleMouseEnter.bind(swiper),
  3954. handleMouseLeave: Mousewheel.handleMouseLeave.bind(swiper),
  3955. animateSlider: Mousewheel.animateSlider.bind(swiper),
  3956. releaseScroll: Mousewheel.releaseScroll.bind(swiper),
  3957. lastScrollTime: Utils.now(),
  3958. lastEventBeforeSnap: undefined,
  3959. recentWheelEvents: [],
  3960. },
  3961. });
  3962. },
  3963. on: {
  3964. init() {
  3965. const swiper = this;
  3966. if (!swiper.params.mousewheel.enabled && swiper.params.cssMode) {
  3967. swiper.mousewheel.disable();
  3968. }
  3969. if (swiper.params.mousewheel.enabled) swiper.mousewheel.enable();
  3970. },
  3971. destroy() {
  3972. const swiper = this;
  3973. if (swiper.params.cssMode) {
  3974. swiper.mousewheel.enable();
  3975. }
  3976. if (swiper.mousewheel.enabled) swiper.mousewheel.disable();
  3977. },
  3978. },
  3979. };
  3980. const Navigation = {
  3981. update() {
  3982. // Update Navigation Buttons
  3983. const swiper = this;
  3984. const params = swiper.params.navigation;
  3985. if (swiper.params.loop) return;
  3986. const { $nextEl, $prevEl } = swiper.navigation;
  3987. if ($prevEl && $prevEl.length > 0) {
  3988. if (swiper.isBeginning) {
  3989. $prevEl.addClass(params.disabledClass);
  3990. } else {
  3991. $prevEl.removeClass(params.disabledClass);
  3992. }
  3993. $prevEl[swiper.params.watchOverflow && swiper.isLocked ? 'addClass' : 'removeClass'](params.lockClass);
  3994. }
  3995. if ($nextEl && $nextEl.length > 0) {
  3996. if (swiper.isEnd) {
  3997. $nextEl.addClass(params.disabledClass);
  3998. } else {
  3999. $nextEl.removeClass(params.disabledClass);
  4000. }
  4001. $nextEl[swiper.params.watchOverflow && swiper.isLocked ? 'addClass' : 'removeClass'](params.lockClass);
  4002. }
  4003. },
  4004. onPrevClick(e) {
  4005. const swiper = this;
  4006. e.preventDefault();
  4007. if (swiper.isBeginning && !swiper.params.loop) return;
  4008. swiper.slidePrev();
  4009. },
  4010. onNextClick(e) {
  4011. const swiper = this;
  4012. e.preventDefault();
  4013. if (swiper.isEnd && !swiper.params.loop) return;
  4014. swiper.slideNext();
  4015. },
  4016. init() {
  4017. const swiper = this;
  4018. const params = swiper.params.navigation;
  4019. if (!(params.nextEl || params.prevEl)) return;
  4020. let $nextEl;
  4021. let $prevEl;
  4022. if (params.nextEl) {
  4023. $nextEl = $(params.nextEl);
  4024. if (
  4025. swiper.params.uniqueNavElements
  4026. && typeof params.nextEl === 'string'
  4027. && $nextEl.length > 1
  4028. && swiper.$el.find(params.nextEl).length === 1
  4029. ) {
  4030. $nextEl = swiper.$el.find(params.nextEl);
  4031. }
  4032. }
  4033. if (params.prevEl) {
  4034. $prevEl = $(params.prevEl);
  4035. if (
  4036. swiper.params.uniqueNavElements
  4037. && typeof params.prevEl === 'string'
  4038. && $prevEl.length > 1
  4039. && swiper.$el.find(params.prevEl).length === 1
  4040. ) {
  4041. $prevEl = swiper.$el.find(params.prevEl);
  4042. }
  4043. }
  4044. if ($nextEl && $nextEl.length > 0) {
  4045. $nextEl.on('click', swiper.navigation.onNextClick);
  4046. }
  4047. if ($prevEl && $prevEl.length > 0) {
  4048. $prevEl.on('click', swiper.navigation.onPrevClick);
  4049. }
  4050. Utils.extend(swiper.navigation, {
  4051. $nextEl,
  4052. nextEl: $nextEl && $nextEl[0],
  4053. $prevEl,
  4054. prevEl: $prevEl && $prevEl[0],
  4055. });
  4056. },
  4057. destroy() {
  4058. const swiper = this;
  4059. const { $nextEl, $prevEl } = swiper.navigation;
  4060. if ($nextEl && $nextEl.length) {
  4061. $nextEl.off('click', swiper.navigation.onNextClick);
  4062. $nextEl.removeClass(swiper.params.navigation.disabledClass);
  4063. }
  4064. if ($prevEl && $prevEl.length) {
  4065. $prevEl.off('click', swiper.navigation.onPrevClick);
  4066. $prevEl.removeClass(swiper.params.navigation.disabledClass);
  4067. }
  4068. },
  4069. };
  4070. var navigation = {
  4071. name: 'navigation',
  4072. params: {
  4073. navigation: {
  4074. nextEl: null,
  4075. prevEl: null,
  4076. hideOnClick: false,
  4077. disabledClass: 'swiper-button-disabled',
  4078. hiddenClass: 'swiper-button-hidden',
  4079. lockClass: 'swiper-button-lock',
  4080. },
  4081. },
  4082. create() {
  4083. const swiper = this;
  4084. Utils.extend(swiper, {
  4085. navigation: {
  4086. init: Navigation.init.bind(swiper),
  4087. update: Navigation.update.bind(swiper),
  4088. destroy: Navigation.destroy.bind(swiper),
  4089. onNextClick: Navigation.onNextClick.bind(swiper),
  4090. onPrevClick: Navigation.onPrevClick.bind(swiper),
  4091. },
  4092. });
  4093. },
  4094. on: {
  4095. init() {
  4096. const swiper = this;
  4097. swiper.navigation.init();
  4098. swiper.navigation.update();
  4099. },
  4100. toEdge() {
  4101. const swiper = this;
  4102. swiper.navigation.update();
  4103. },
  4104. fromEdge() {
  4105. const swiper = this;
  4106. swiper.navigation.update();
  4107. },
  4108. destroy() {
  4109. const swiper = this;
  4110. swiper.navigation.destroy();
  4111. },
  4112. click(e) {
  4113. const swiper = this;
  4114. const { $nextEl, $prevEl } = swiper.navigation;
  4115. if (
  4116. swiper.params.navigation.hideOnClick
  4117. && !$(e.target).is($prevEl)
  4118. && !$(e.target).is($nextEl)
  4119. ) {
  4120. let isHidden;
  4121. if ($nextEl) {
  4122. isHidden = $nextEl.hasClass(swiper.params.navigation.hiddenClass);
  4123. } else if ($prevEl) {
  4124. isHidden = $prevEl.hasClass(swiper.params.navigation.hiddenClass);
  4125. }
  4126. if (isHidden === true) {
  4127. swiper.emit('navigationShow', swiper);
  4128. } else {
  4129. swiper.emit('navigationHide', swiper);
  4130. }
  4131. if ($nextEl) {
  4132. $nextEl.toggleClass(swiper.params.navigation.hiddenClass);
  4133. }
  4134. if ($prevEl) {
  4135. $prevEl.toggleClass(swiper.params.navigation.hiddenClass);
  4136. }
  4137. }
  4138. },
  4139. },
  4140. };
  4141. const Pagination = {
  4142. update() {
  4143. // Render || Update Pagination bullets/items
  4144. const swiper = this;
  4145. const rtl = swiper.rtl;
  4146. const params = swiper.params.pagination;
  4147. if (!params.el || !swiper.pagination.el || !swiper.pagination.$el || swiper.pagination.$el.length === 0) return;
  4148. const slidesLength = swiper.virtual && swiper.params.virtual.enabled ? swiper.virtual.slides.length : swiper.slides.length;
  4149. const $el = swiper.pagination.$el;
  4150. // Current/Total
  4151. let current;
  4152. const total = swiper.params.loop ? Math.ceil((slidesLength - (swiper.loopedSlides * 2)) / swiper.params.slidesPerGroup) : swiper.snapGrid.length;
  4153. if (swiper.params.loop) {
  4154. current = Math.ceil((swiper.activeIndex - swiper.loopedSlides) / swiper.params.slidesPerGroup);
  4155. if (current > slidesLength - 1 - (swiper.loopedSlides * 2)) {
  4156. current -= (slidesLength - (swiper.loopedSlides * 2));
  4157. }
  4158. if (current > total - 1) current -= total;
  4159. if (current < 0 && swiper.params.paginationType !== 'bullets') current = total + current;
  4160. } else if (typeof swiper.snapIndex !== 'undefined') {
  4161. current = swiper.snapIndex;
  4162. } else {
  4163. current = swiper.activeIndex || 0;
  4164. }
  4165. // Types
  4166. if (params.type === 'bullets' && swiper.pagination.bullets && swiper.pagination.bullets.length > 0) {
  4167. const bullets = swiper.pagination.bullets;
  4168. let firstIndex;
  4169. let lastIndex;
  4170. let midIndex;
  4171. if (params.dynamicBullets) {
  4172. swiper.pagination.bulletSize = bullets.eq(0)[swiper.isHorizontal() ? 'outerWidth' : 'outerHeight'](true);
  4173. $el.css(swiper.isHorizontal() ? 'width' : 'height', `${swiper.pagination.bulletSize * (params.dynamicMainBullets + 4)}px`);
  4174. if (params.dynamicMainBullets > 1 && swiper.previousIndex !== undefined) {
  4175. swiper.pagination.dynamicBulletIndex += (current - swiper.previousIndex);
  4176. if (swiper.pagination.dynamicBulletIndex > (params.dynamicMainBullets - 1)) {
  4177. swiper.pagination.dynamicBulletIndex = params.dynamicMainBullets - 1;
  4178. } else if (swiper.pagination.dynamicBulletIndex < 0) {
  4179. swiper.pagination.dynamicBulletIndex = 0;
  4180. }
  4181. }
  4182. firstIndex = current - swiper.pagination.dynamicBulletIndex;
  4183. lastIndex = firstIndex + (Math.min(bullets.length, params.dynamicMainBullets) - 1);
  4184. midIndex = (lastIndex + firstIndex) / 2;
  4185. }
  4186. bullets.removeClass(`${params.bulletActiveClass} ${params.bulletActiveClass}-next ${params.bulletActiveClass}-next-next ${params.bulletActiveClass}-prev ${params.bulletActiveClass}-prev-prev ${params.bulletActiveClass}-main`);
  4187. if ($el.length > 1) {
  4188. bullets.each((index, bullet) => {
  4189. const $bullet = $(bullet);
  4190. const bulletIndex = $bullet.index();
  4191. if (bulletIndex === current) {
  4192. $bullet.addClass(params.bulletActiveClass);
  4193. }
  4194. if (params.dynamicBullets) {
  4195. if (bulletIndex >= firstIndex && bulletIndex <= lastIndex) {
  4196. $bullet.addClass(`${params.bulletActiveClass}-main`);
  4197. }
  4198. if (bulletIndex === firstIndex) {
  4199. $bullet
  4200. .prev()
  4201. .addClass(`${params.bulletActiveClass}-prev`)
  4202. .prev()
  4203. .addClass(`${params.bulletActiveClass}-prev-prev`);
  4204. }
  4205. if (bulletIndex === lastIndex) {
  4206. $bullet
  4207. .next()
  4208. .addClass(`${params.bulletActiveClass}-next`)
  4209. .next()
  4210. .addClass(`${params.bulletActiveClass}-next-next`);
  4211. }
  4212. }
  4213. });
  4214. } else {
  4215. const $bullet = bullets.eq(current);
  4216. const bulletIndex = $bullet.index();
  4217. $bullet.addClass(params.bulletActiveClass);
  4218. if (params.dynamicBullets) {
  4219. const $firstDisplayedBullet = bullets.eq(firstIndex);
  4220. const $lastDisplayedBullet = bullets.eq(lastIndex);
  4221. for (let i = firstIndex; i <= lastIndex; i += 1) {
  4222. bullets.eq(i).addClass(`${params.bulletActiveClass}-main`);
  4223. }
  4224. if (swiper.params.loop) {
  4225. if (bulletIndex >= bullets.length - params.dynamicMainBullets) {
  4226. for (let i = params.dynamicMainBullets; i >= 0; i -= 1) {
  4227. bullets.eq(bullets.length - i).addClass(`${params.bulletActiveClass}-main`);
  4228. }
  4229. bullets.eq(bullets.length - params.dynamicMainBullets - 1).addClass(`${params.bulletActiveClass}-prev`);
  4230. } else {
  4231. $firstDisplayedBullet
  4232. .prev()
  4233. .addClass(`${params.bulletActiveClass}-prev`)
  4234. .prev()
  4235. .addClass(`${params.bulletActiveClass}-prev-prev`);
  4236. $lastDisplayedBullet
  4237. .next()
  4238. .addClass(`${params.bulletActiveClass}-next`)
  4239. .next()
  4240. .addClass(`${params.bulletActiveClass}-next-next`);
  4241. }
  4242. } else {
  4243. $firstDisplayedBullet
  4244. .prev()
  4245. .addClass(`${params.bulletActiveClass}-prev`)
  4246. .prev()
  4247. .addClass(`${params.bulletActiveClass}-prev-prev`);
  4248. $lastDisplayedBullet
  4249. .next()
  4250. .addClass(`${params.bulletActiveClass}-next`)
  4251. .next()
  4252. .addClass(`${params.bulletActiveClass}-next-next`);
  4253. }
  4254. }
  4255. }
  4256. if (params.dynamicBullets) {
  4257. const dynamicBulletsLength = Math.min(bullets.length, params.dynamicMainBullets + 4);
  4258. const bulletsOffset = (((swiper.pagination.bulletSize * dynamicBulletsLength) - (swiper.pagination.bulletSize)) / 2) - (midIndex * swiper.pagination.bulletSize);
  4259. const offsetProp = rtl ? 'right' : 'left';
  4260. bullets.css(swiper.isHorizontal() ? offsetProp : 'top', `${bulletsOffset}px`);
  4261. }
  4262. }
  4263. if (params.type === 'fraction') {
  4264. $el.find(`.${params.currentClass}`).text(params.formatFractionCurrent(current + 1));
  4265. $el.find(`.${params.totalClass}`).text(params.formatFractionTotal(total));
  4266. }
  4267. if (params.type === 'progressbar') {
  4268. let progressbarDirection;
  4269. if (params.progressbarOpposite) {
  4270. progressbarDirection = swiper.isHorizontal() ? 'vertical' : 'horizontal';
  4271. } else {
  4272. progressbarDirection = swiper.isHorizontal() ? 'horizontal' : 'vertical';
  4273. }
  4274. const scale = (current + 1) / total;
  4275. let scaleX = 1;
  4276. let scaleY = 1;
  4277. if (progressbarDirection === 'horizontal') {
  4278. scaleX = scale;
  4279. } else {
  4280. scaleY = scale;
  4281. }
  4282. $el.find(`.${params.progressbarFillClass}`).transform(`translate3d(0,0,0) scaleX(${scaleX}) scaleY(${scaleY})`).transition(swiper.params.speed);
  4283. }
  4284. if (params.type === 'custom' && params.renderCustom) {
  4285. $el.html(params.renderCustom(swiper, current + 1, total));
  4286. swiper.emit('paginationRender', swiper, $el[0]);
  4287. } else {
  4288. swiper.emit('paginationUpdate', swiper, $el[0]);
  4289. }
  4290. $el[swiper.params.watchOverflow && swiper.isLocked ? 'addClass' : 'removeClass'](params.lockClass);
  4291. },
  4292. render() {
  4293. // Render Container
  4294. const swiper = this;
  4295. const params = swiper.params.pagination;
  4296. if (!params.el || !swiper.pagination.el || !swiper.pagination.$el || swiper.pagination.$el.length === 0) return;
  4297. const slidesLength = swiper.virtual && swiper.params.virtual.enabled ? swiper.virtual.slides.length : swiper.slides.length;
  4298. const $el = swiper.pagination.$el;
  4299. let paginationHTML = '';
  4300. if (params.type === 'bullets') {
  4301. const numberOfBullets = swiper.params.loop ? Math.ceil((slidesLength - (swiper.loopedSlides * 2)) / swiper.params.slidesPerGroup) : swiper.snapGrid.length;
  4302. for (let i = 0; i < numberOfBullets; i += 1) {
  4303. if (params.renderBullet) {
  4304. paginationHTML += params.renderBullet.call(swiper, i, params.bulletClass);
  4305. } else {
  4306. paginationHTML += `<${params.bulletElement} class="${params.bulletClass}"></${params.bulletElement}>`;
  4307. }
  4308. }
  4309. $el.html(paginationHTML);
  4310. swiper.pagination.bullets = $el.find(`.${params.bulletClass}`);
  4311. }
  4312. if (params.type === 'fraction') {
  4313. if (params.renderFraction) {
  4314. paginationHTML = params.renderFraction.call(swiper, params.currentClass, params.totalClass);
  4315. } else {
  4316. paginationHTML = `<span class="${params.currentClass}"></span>`
  4317. + ' / '
  4318. + `<span class="${params.totalClass}"></span>`;
  4319. }
  4320. $el.html(paginationHTML);
  4321. }
  4322. if (params.type === 'progressbar') {
  4323. if (params.renderProgressbar) {
  4324. paginationHTML = params.renderProgressbar.call(swiper, params.progressbarFillClass);
  4325. } else {
  4326. paginationHTML = `<span class="${params.progressbarFillClass}"></span>`;
  4327. }
  4328. $el.html(paginationHTML);
  4329. }
  4330. if (params.type !== 'custom') {
  4331. swiper.emit('paginationRender', swiper.pagination.$el[0]);
  4332. }
  4333. },
  4334. init() {
  4335. const swiper = this;
  4336. const params = swiper.params.pagination;
  4337. if (!params.el) return;
  4338. let $el = $(params.el);
  4339. if ($el.length === 0) return;
  4340. if (
  4341. swiper.params.uniqueNavElements
  4342. && typeof params.el === 'string'
  4343. && $el.length > 1
  4344. && swiper.$el.find(params.el).length === 1
  4345. ) {
  4346. $el = swiper.$el.find(params.el);
  4347. }
  4348. if (params.type === 'bullets' && params.clickable) {
  4349. $el.addClass(params.clickableClass);
  4350. }
  4351. $el.addClass(params.modifierClass + params.type);
  4352. if (params.type === 'bullets' && params.dynamicBullets) {
  4353. $el.addClass(`${params.modifierClass}${params.type}-dynamic`);
  4354. swiper.pagination.dynamicBulletIndex = 0;
  4355. if (params.dynamicMainBullets < 1) {
  4356. params.dynamicMainBullets = 1;
  4357. }
  4358. }
  4359. if (params.type === 'progressbar' && params.progressbarOpposite) {
  4360. $el.addClass(params.progressbarOppositeClass);
  4361. }
  4362. if (params.clickable) {
  4363. $el.on('click', `.${params.bulletClass}`, function onClick(e) {
  4364. e.preventDefault();
  4365. let index = $(this).index() * swiper.params.slidesPerGroup;
  4366. if (swiper.params.loop) index += swiper.loopedSlides;
  4367. swiper.slideTo(index);
  4368. });
  4369. }
  4370. Utils.extend(swiper.pagination, {
  4371. $el,
  4372. el: $el[0],
  4373. });
  4374. },
  4375. destroy() {
  4376. const swiper = this;
  4377. const params = swiper.params.pagination;
  4378. if (!params.el || !swiper.pagination.el || !swiper.pagination.$el || swiper.pagination.$el.length === 0) return;
  4379. const $el = swiper.pagination.$el;
  4380. $el.removeClass(params.hiddenClass);
  4381. $el.removeClass(params.modifierClass + params.type);
  4382. if (swiper.pagination.bullets) swiper.pagination.bullets.removeClass(params.bulletActiveClass);
  4383. if (params.clickable) {
  4384. $el.off('click', `.${params.bulletClass}`);
  4385. }
  4386. },
  4387. };
  4388. var pagination = {
  4389. name: 'pagination',
  4390. params: {
  4391. pagination: {
  4392. el: null,
  4393. bulletElement: 'span',
  4394. clickable: false,
  4395. hideOnClick: false,
  4396. renderBullet: null,
  4397. renderProgressbar: null,
  4398. renderFraction: null,
  4399. renderCustom: null,
  4400. progressbarOpposite: false,
  4401. type: 'bullets', // 'bullets' or 'progressbar' or 'fraction' or 'custom'
  4402. dynamicBullets: false,
  4403. dynamicMainBullets: 1,
  4404. formatFractionCurrent: (number) => number,
  4405. formatFractionTotal: (number) => number,
  4406. bulletClass: 'swiper-pagination-bullet',
  4407. bulletActiveClass: 'swiper-pagination-bullet-active',
  4408. modifierClass: 'swiper-pagination-', // NEW
  4409. currentClass: 'swiper-pagination-current',
  4410. totalClass: 'swiper-pagination-total',
  4411. hiddenClass: 'swiper-pagination-hidden',
  4412. progressbarFillClass: 'swiper-pagination-progressbar-fill',
  4413. progressbarOppositeClass: 'swiper-pagination-progressbar-opposite',
  4414. clickableClass: 'swiper-pagination-clickable', // NEW
  4415. lockClass: 'swiper-pagination-lock',
  4416. },
  4417. },
  4418. create() {
  4419. const swiper = this;
  4420. Utils.extend(swiper, {
  4421. pagination: {
  4422. init: Pagination.init.bind(swiper),
  4423. render: Pagination.render.bind(swiper),
  4424. update: Pagination.update.bind(swiper),
  4425. destroy: Pagination.destroy.bind(swiper),
  4426. dynamicBulletIndex: 0,
  4427. },
  4428. });
  4429. },
  4430. on: {
  4431. init() {
  4432. const swiper = this;
  4433. swiper.pagination.init();
  4434. swiper.pagination.render();
  4435. swiper.pagination.update();
  4436. },
  4437. activeIndexChange() {
  4438. const swiper = this;
  4439. if (swiper.params.loop) {
  4440. swiper.pagination.update();
  4441. } else if (typeof swiper.snapIndex === 'undefined') {
  4442. swiper.pagination.update();
  4443. }
  4444. },
  4445. snapIndexChange() {
  4446. const swiper = this;
  4447. if (!swiper.params.loop) {
  4448. swiper.pagination.update();
  4449. }
  4450. },
  4451. slidesLengthChange() {
  4452. const swiper = this;
  4453. if (swiper.params.loop) {
  4454. swiper.pagination.render();
  4455. swiper.pagination.update();
  4456. }
  4457. },
  4458. snapGridLengthChange() {
  4459. const swiper = this;
  4460. if (!swiper.params.loop) {
  4461. swiper.pagination.render();
  4462. swiper.pagination.update();
  4463. }
  4464. },
  4465. destroy() {
  4466. const swiper = this;
  4467. swiper.pagination.destroy();
  4468. },
  4469. click(e) {
  4470. const swiper = this;
  4471. if (
  4472. swiper.params.pagination.el
  4473. && swiper.params.pagination.hideOnClick
  4474. && swiper.pagination.$el.length > 0
  4475. && !$(e.target).hasClass(swiper.params.pagination.bulletClass)
  4476. ) {
  4477. const isHidden = swiper.pagination.$el.hasClass(swiper.params.pagination.hiddenClass);
  4478. if (isHidden === true) {
  4479. swiper.emit('paginationShow', swiper);
  4480. } else {
  4481. swiper.emit('paginationHide', swiper);
  4482. }
  4483. swiper.pagination.$el.toggleClass(swiper.params.pagination.hiddenClass);
  4484. }
  4485. },
  4486. },
  4487. };
  4488. const Scrollbar = {
  4489. setTranslate() {
  4490. const swiper = this;
  4491. if (!swiper.params.scrollbar.el || !swiper.scrollbar.el) return;
  4492. const { scrollbar, rtlTranslate: rtl, progress } = swiper;
  4493. const {
  4494. dragSize, trackSize, $dragEl, $el,
  4495. } = scrollbar;
  4496. const params = swiper.params.scrollbar;
  4497. let newSize = dragSize;
  4498. let newPos = (trackSize - dragSize) * progress;
  4499. if (rtl) {
  4500. newPos = -newPos;
  4501. if (newPos > 0) {
  4502. newSize = dragSize - newPos;
  4503. newPos = 0;
  4504. } else if (-newPos + dragSize > trackSize) {
  4505. newSize = trackSize + newPos;
  4506. }
  4507. } else if (newPos < 0) {
  4508. newSize = dragSize + newPos;
  4509. newPos = 0;
  4510. } else if (newPos + dragSize > trackSize) {
  4511. newSize = trackSize - newPos;
  4512. }
  4513. if (swiper.isHorizontal()) {
  4514. $dragEl.transform(`translate3d(${newPos}px, 0, 0)`);
  4515. $dragEl[0].style.width = `${newSize}px`;
  4516. } else {
  4517. $dragEl.transform(`translate3d(0px, ${newPos}px, 0)`);
  4518. $dragEl[0].style.height = `${newSize}px`;
  4519. }
  4520. if (params.hide) {
  4521. clearTimeout(swiper.scrollbar.timeout);
  4522. $el[0].style.opacity = 1;
  4523. swiper.scrollbar.timeout = setTimeout(() => {
  4524. $el[0].style.opacity = 0;
  4525. $el.transition(400);
  4526. }, 1000);
  4527. }
  4528. },
  4529. setTransition(duration) {
  4530. const swiper = this;
  4531. if (!swiper.params.scrollbar.el || !swiper.scrollbar.el) return;
  4532. swiper.scrollbar.$dragEl.transition(duration);
  4533. },
  4534. updateSize() {
  4535. const swiper = this;
  4536. if (!swiper.params.scrollbar.el || !swiper.scrollbar.el) return;
  4537. const { scrollbar } = swiper;
  4538. const { $dragEl, $el } = scrollbar;
  4539. $dragEl[0].style.width = '';
  4540. $dragEl[0].style.height = '';
  4541. const trackSize = swiper.isHorizontal() ? $el[0].offsetWidth : $el[0].offsetHeight;
  4542. const divider = swiper.size / swiper.virtualSize;
  4543. const moveDivider = divider * (trackSize / swiper.size);
  4544. let dragSize;
  4545. if (swiper.params.scrollbar.dragSize === 'auto') {
  4546. dragSize = trackSize * divider;
  4547. } else {
  4548. dragSize = parseInt(swiper.params.scrollbar.dragSize, 10);
  4549. }
  4550. if (swiper.isHorizontal()) {
  4551. $dragEl[0].style.width = `${dragSize}px`;
  4552. } else {
  4553. $dragEl[0].style.height = `${dragSize}px`;
  4554. }
  4555. if (divider >= 1) {
  4556. $el[0].style.display = 'none';
  4557. } else {
  4558. $el[0].style.display = '';
  4559. }
  4560. if (swiper.params.scrollbar.hide) {
  4561. $el[0].style.opacity = 0;
  4562. }
  4563. Utils.extend(scrollbar, {
  4564. trackSize,
  4565. divider,
  4566. moveDivider,
  4567. dragSize,
  4568. });
  4569. scrollbar.$el[swiper.params.watchOverflow && swiper.isLocked ? 'addClass' : 'removeClass'](swiper.params.scrollbar.lockClass);
  4570. },
  4571. getPointerPosition(e) {
  4572. const swiper = this;
  4573. if (swiper.isHorizontal()) {
  4574. return ((e.type === 'touchstart' || e.type === 'touchmove') ? e.targetTouches[0].clientX : e.clientX);
  4575. }
  4576. return ((e.type === 'touchstart' || e.type === 'touchmove') ? e.targetTouches[0].clientY : e.clientY);
  4577. },
  4578. setDragPosition(e) {
  4579. const swiper = this;
  4580. const { scrollbar, rtlTranslate: rtl } = swiper;
  4581. const {
  4582. $el,
  4583. dragSize,
  4584. trackSize,
  4585. dragStartPos,
  4586. } = scrollbar;
  4587. let positionRatio;
  4588. positionRatio = ((scrollbar.getPointerPosition(e)) - $el.offset()[swiper.isHorizontal() ? 'left' : 'top']
  4589. - (dragStartPos !== null ? dragStartPos : dragSize / 2)) / (trackSize - dragSize);
  4590. positionRatio = Math.max(Math.min(positionRatio, 1), 0);
  4591. if (rtl) {
  4592. positionRatio = 1 - positionRatio;
  4593. }
  4594. const position = swiper.minTranslate() + ((swiper.maxTranslate() - swiper.minTranslate()) * positionRatio);
  4595. swiper.updateProgress(position);
  4596. swiper.setTranslate(position);
  4597. swiper.updateActiveIndex();
  4598. swiper.updateSlidesClasses();
  4599. },
  4600. onDragStart(e) {
  4601. const swiper = this;
  4602. const params = swiper.params.scrollbar;
  4603. const { scrollbar, $wrapperEl } = swiper;
  4604. const { $el, $dragEl } = scrollbar;
  4605. swiper.scrollbar.isTouched = true;
  4606. swiper.scrollbar.dragStartPos = (e.target === $dragEl[0] || e.target === $dragEl)
  4607. ? scrollbar.getPointerPosition(e) - e.target.getBoundingClientRect()[swiper.isHorizontal() ? 'left' : 'top'] : null;
  4608. e.preventDefault();
  4609. e.stopPropagation();
  4610. $wrapperEl.transition(100);
  4611. $dragEl.transition(100);
  4612. scrollbar.setDragPosition(e);
  4613. clearTimeout(swiper.scrollbar.dragTimeout);
  4614. $el.transition(0);
  4615. if (params.hide) {
  4616. $el.css('opacity', 1);
  4617. }
  4618. if (swiper.params.cssMode) {
  4619. swiper.$wrapperEl.css('scroll-snap-type', 'none');
  4620. }
  4621. swiper.emit('scrollbarDragStart', e);
  4622. },
  4623. onDragMove(e) {
  4624. const swiper = this;
  4625. const { scrollbar, $wrapperEl } = swiper;
  4626. const { $el, $dragEl } = scrollbar;
  4627. if (!swiper.scrollbar.isTouched) return;
  4628. if (e.preventDefault) e.preventDefault();
  4629. else e.returnValue = false;
  4630. scrollbar.setDragPosition(e);
  4631. $wrapperEl.transition(0);
  4632. $el.transition(0);
  4633. $dragEl.transition(0);
  4634. swiper.emit('scrollbarDragMove', e);
  4635. },
  4636. onDragEnd(e) {
  4637. const swiper = this;
  4638. const params = swiper.params.scrollbar;
  4639. const { scrollbar, $wrapperEl } = swiper;
  4640. const { $el } = scrollbar;
  4641. if (!swiper.scrollbar.isTouched) return;
  4642. swiper.scrollbar.isTouched = false;
  4643. if (swiper.params.cssMode) {
  4644. swiper.$wrapperEl.css('scroll-snap-type', '');
  4645. $wrapperEl.transition('');
  4646. }
  4647. if (params.hide) {
  4648. clearTimeout(swiper.scrollbar.dragTimeout);
  4649. swiper.scrollbar.dragTimeout = Utils.nextTick(() => {
  4650. $el.css('opacity', 0);
  4651. $el.transition(400);
  4652. }, 1000);
  4653. }
  4654. swiper.emit('scrollbarDragEnd', e);
  4655. if (params.snapOnRelease) {
  4656. swiper.slideToClosest();
  4657. }
  4658. },
  4659. enableDraggable() {
  4660. const swiper = this;
  4661. if (!swiper.params.scrollbar.el) return;
  4662. const {
  4663. scrollbar, touchEventsTouch, touchEventsDesktop, params,
  4664. } = swiper;
  4665. const $el = scrollbar.$el;
  4666. const target = $el[0];
  4667. const activeListener = Support.passiveListener && params.passiveListeners ? { passive: false, capture: false } : false;
  4668. const passiveListener = Support.passiveListener && params.passiveListeners ? { passive: true, capture: false } : false;
  4669. if (!Support.touch) {
  4670. target.addEventListener(touchEventsDesktop.start, swiper.scrollbar.onDragStart, activeListener);
  4671. document$1.addEventListener(touchEventsDesktop.move, swiper.scrollbar.onDragMove, activeListener);
  4672. document$1.addEventListener(touchEventsDesktop.end, swiper.scrollbar.onDragEnd, passiveListener);
  4673. } else {
  4674. target.addEventListener(touchEventsTouch.start, swiper.scrollbar.onDragStart, activeListener);
  4675. target.addEventListener(touchEventsTouch.move, swiper.scrollbar.onDragMove, activeListener);
  4676. target.addEventListener(touchEventsTouch.end, swiper.scrollbar.onDragEnd, passiveListener);
  4677. }
  4678. },
  4679. disableDraggable() {
  4680. const swiper = this;
  4681. if (!swiper.params.scrollbar.el) return;
  4682. const {
  4683. scrollbar, touchEventsTouch, touchEventsDesktop, params,
  4684. } = swiper;
  4685. const $el = scrollbar.$el;
  4686. const target = $el[0];
  4687. const activeListener = Support.passiveListener && params.passiveListeners ? { passive: false, capture: false } : false;
  4688. const passiveListener = Support.passiveListener && params.passiveListeners ? { passive: true, capture: false } : false;
  4689. if (!Support.touch) {
  4690. target.removeEventListener(touchEventsDesktop.start, swiper.scrollbar.onDragStart, activeListener);
  4691. document$1.removeEventListener(touchEventsDesktop.move, swiper.scrollbar.onDragMove, activeListener);
  4692. document$1.removeEventListener(touchEventsDesktop.end, swiper.scrollbar.onDragEnd, passiveListener);
  4693. } else {
  4694. target.removeEventListener(touchEventsTouch.start, swiper.scrollbar.onDragStart, activeListener);
  4695. target.removeEventListener(touchEventsTouch.move, swiper.scrollbar.onDragMove, activeListener);
  4696. target.removeEventListener(touchEventsTouch.end, swiper.scrollbar.onDragEnd, passiveListener);
  4697. }
  4698. },
  4699. init() {
  4700. const swiper = this;
  4701. if (!swiper.params.scrollbar.el) return;
  4702. const { scrollbar, $el: $swiperEl } = swiper;
  4703. const params = swiper.params.scrollbar;
  4704. let $el = $(params.el);
  4705. if (swiper.params.uniqueNavElements && typeof params.el === 'string' && $el.length > 1 && $swiperEl.find(params.el).length === 1) {
  4706. $el = $swiperEl.find(params.el);
  4707. }
  4708. let $dragEl = $el.find(`.${swiper.params.scrollbar.dragClass}`);
  4709. if ($dragEl.length === 0) {
  4710. $dragEl = $(`<div class="${swiper.params.scrollbar.dragClass}"></div>`);
  4711. $el.append($dragEl);
  4712. }
  4713. Utils.extend(scrollbar, {
  4714. $el,
  4715. el: $el[0],
  4716. $dragEl,
  4717. dragEl: $dragEl[0],
  4718. });
  4719. if (params.draggable) {
  4720. scrollbar.enableDraggable();
  4721. }
  4722. },
  4723. destroy() {
  4724. const swiper = this;
  4725. swiper.scrollbar.disableDraggable();
  4726. },
  4727. };
  4728. var scrollbar = {
  4729. name: 'scrollbar',
  4730. params: {
  4731. scrollbar: {
  4732. el: null,
  4733. dragSize: 'auto',
  4734. hide: false,
  4735. draggable: false,
  4736. snapOnRelease: true,
  4737. lockClass: 'swiper-scrollbar-lock',
  4738. dragClass: 'swiper-scrollbar-drag',
  4739. },
  4740. },
  4741. create() {
  4742. const swiper = this;
  4743. Utils.extend(swiper, {
  4744. scrollbar: {
  4745. init: Scrollbar.init.bind(swiper),
  4746. destroy: Scrollbar.destroy.bind(swiper),
  4747. updateSize: Scrollbar.updateSize.bind(swiper),
  4748. setTranslate: Scrollbar.setTranslate.bind(swiper),
  4749. setTransition: Scrollbar.setTransition.bind(swiper),
  4750. enableDraggable: Scrollbar.enableDraggable.bind(swiper),
  4751. disableDraggable: Scrollbar.disableDraggable.bind(swiper),
  4752. setDragPosition: Scrollbar.setDragPosition.bind(swiper),
  4753. getPointerPosition: Scrollbar.getPointerPosition.bind(swiper),
  4754. onDragStart: Scrollbar.onDragStart.bind(swiper),
  4755. onDragMove: Scrollbar.onDragMove.bind(swiper),
  4756. onDragEnd: Scrollbar.onDragEnd.bind(swiper),
  4757. isTouched: false,
  4758. timeout: null,
  4759. dragTimeout: null,
  4760. },
  4761. });
  4762. },
  4763. on: {
  4764. init() {
  4765. const swiper = this;
  4766. swiper.scrollbar.init();
  4767. swiper.scrollbar.updateSize();
  4768. swiper.scrollbar.setTranslate();
  4769. },
  4770. update() {
  4771. const swiper = this;
  4772. swiper.scrollbar.updateSize();
  4773. },
  4774. resize() {
  4775. const swiper = this;
  4776. swiper.scrollbar.updateSize();
  4777. },
  4778. observerUpdate() {
  4779. const swiper = this;
  4780. swiper.scrollbar.updateSize();
  4781. },
  4782. setTranslate() {
  4783. const swiper = this;
  4784. swiper.scrollbar.setTranslate();
  4785. },
  4786. setTransition(duration) {
  4787. const swiper = this;
  4788. swiper.scrollbar.setTransition(duration);
  4789. },
  4790. destroy() {
  4791. const swiper = this;
  4792. swiper.scrollbar.destroy();
  4793. },
  4794. },
  4795. };
  4796. const Parallax = {
  4797. setTransform(el, progress) {
  4798. const swiper = this;
  4799. const { rtl } = swiper;
  4800. const $el = $(el);
  4801. const rtlFactor = rtl ? -1 : 1;
  4802. const p = $el.attr('data-swiper-parallax') || '0';
  4803. let x = $el.attr('data-swiper-parallax-x');
  4804. let y = $el.attr('data-swiper-parallax-y');
  4805. const scale = $el.attr('data-swiper-parallax-scale');
  4806. const opacity = $el.attr('data-swiper-parallax-opacity');
  4807. if (x || y) {
  4808. x = x || '0';
  4809. y = y || '0';
  4810. } else if (swiper.isHorizontal()) {
  4811. x = p;
  4812. y = '0';
  4813. } else {
  4814. y = p;
  4815. x = '0';
  4816. }
  4817. if ((x).indexOf('%') >= 0) {
  4818. x = `${parseInt(x, 10) * progress * rtlFactor}%`;
  4819. } else {
  4820. x = `${x * progress * rtlFactor}px`;
  4821. }
  4822. if ((y).indexOf('%') >= 0) {
  4823. y = `${parseInt(y, 10) * progress}%`;
  4824. } else {
  4825. y = `${y * progress}px`;
  4826. }
  4827. if (typeof opacity !== 'undefined' && opacity !== null) {
  4828. const currentOpacity = opacity - ((opacity - 1) * (1 - Math.abs(progress)));
  4829. $el[0].style.opacity = currentOpacity;
  4830. }
  4831. if (typeof scale === 'undefined' || scale === null) {
  4832. $el.transform(`translate3d(${x}, ${y}, 0px)`);
  4833. } else {
  4834. const currentScale = scale - ((scale - 1) * (1 - Math.abs(progress)));
  4835. $el.transform(`translate3d(${x}, ${y}, 0px) scale(${currentScale})`);
  4836. }
  4837. },
  4838. setTranslate() {
  4839. const swiper = this;
  4840. const {
  4841. $el, slides, progress, snapGrid,
  4842. } = swiper;
  4843. $el.children('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y], [data-swiper-parallax-opacity], [data-swiper-parallax-scale]')
  4844. .each((index, el) => {
  4845. swiper.parallax.setTransform(el, progress);
  4846. });
  4847. slides.each((slideIndex, slideEl) => {
  4848. let slideProgress = slideEl.progress;
  4849. if (swiper.params.slidesPerGroup > 1 && swiper.params.slidesPerView !== 'auto') {
  4850. slideProgress += Math.ceil(slideIndex / 2) - (progress * (snapGrid.length - 1));
  4851. }
  4852. slideProgress = Math.min(Math.max(slideProgress, -1), 1);
  4853. $(slideEl).find('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y], [data-swiper-parallax-opacity], [data-swiper-parallax-scale]')
  4854. .each((index, el) => {
  4855. swiper.parallax.setTransform(el, slideProgress);
  4856. });
  4857. });
  4858. },
  4859. setTransition(duration = this.params.speed) {
  4860. const swiper = this;
  4861. const { $el } = swiper;
  4862. $el.find('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y], [data-swiper-parallax-opacity], [data-swiper-parallax-scale]')
  4863. .each((index, parallaxEl) => {
  4864. const $parallaxEl = $(parallaxEl);
  4865. let parallaxDuration = parseInt($parallaxEl.attr('data-swiper-parallax-duration'), 10) || duration;
  4866. if (duration === 0) parallaxDuration = 0;
  4867. $parallaxEl.transition(parallaxDuration);
  4868. });
  4869. },
  4870. };
  4871. var parallax = {
  4872. name: 'parallax',
  4873. params: {
  4874. parallax: {
  4875. enabled: false,
  4876. },
  4877. },
  4878. create() {
  4879. const swiper = this;
  4880. Utils.extend(swiper, {
  4881. parallax: {
  4882. setTransform: Parallax.setTransform.bind(swiper),
  4883. setTranslate: Parallax.setTranslate.bind(swiper),
  4884. setTransition: Parallax.setTransition.bind(swiper),
  4885. },
  4886. });
  4887. },
  4888. on: {
  4889. beforeInit() {
  4890. const swiper = this;
  4891. if (!swiper.params.parallax.enabled) return;
  4892. swiper.params.watchSlidesProgress = true;
  4893. swiper.originalParams.watchSlidesProgress = true;
  4894. },
  4895. init() {
  4896. const swiper = this;
  4897. if (!swiper.params.parallax.enabled) return;
  4898. swiper.parallax.setTranslate();
  4899. },
  4900. setTranslate() {
  4901. const swiper = this;
  4902. if (!swiper.params.parallax.enabled) return;
  4903. swiper.parallax.setTranslate();
  4904. },
  4905. setTransition(duration) {
  4906. const swiper = this;
  4907. if (!swiper.params.parallax.enabled) return;
  4908. swiper.parallax.setTransition(duration);
  4909. },
  4910. },
  4911. };
  4912. const Zoom = {
  4913. // Calc Scale From Multi-touches
  4914. getDistanceBetweenTouches(e) {
  4915. if (e.targetTouches.length < 2) return 1;
  4916. const x1 = e.targetTouches[0].pageX;
  4917. const y1 = e.targetTouches[0].pageY;
  4918. const x2 = e.targetTouches[1].pageX;
  4919. const y2 = e.targetTouches[1].pageY;
  4920. const distance = Math.sqrt(((x2 - x1) ** 2) + ((y2 - y1) ** 2));
  4921. return distance;
  4922. },
  4923. // Events
  4924. onGestureStart(e) {
  4925. const swiper = this;
  4926. const params = swiper.params.zoom;
  4927. const zoom = swiper.zoom;
  4928. const { gesture } = zoom;
  4929. zoom.fakeGestureTouched = false;
  4930. zoom.fakeGestureMoved = false;
  4931. if (!Support.gestures) {
  4932. if (e.type !== 'touchstart' || (e.type === 'touchstart' && e.targetTouches.length < 2)) {
  4933. return;
  4934. }
  4935. zoom.fakeGestureTouched = true;
  4936. gesture.scaleStart = Zoom.getDistanceBetweenTouches(e);
  4937. }
  4938. if (!gesture.$slideEl || !gesture.$slideEl.length) {
  4939. gesture.$slideEl = $(e.target).closest(`.${swiper.params.slideClass}`);
  4940. if (gesture.$slideEl.length === 0) gesture.$slideEl = swiper.slides.eq(swiper.activeIndex);
  4941. gesture.$imageEl = gesture.$slideEl.find('img, svg, canvas, picture, .swiper-zoom-target');
  4942. gesture.$imageWrapEl = gesture.$imageEl.parent(`.${params.containerClass}`);
  4943. gesture.maxRatio = gesture.$imageWrapEl.attr('data-swiper-zoom') || params.maxRatio;
  4944. if (gesture.$imageWrapEl.length === 0) {
  4945. gesture.$imageEl = undefined;
  4946. return;
  4947. }
  4948. }
  4949. gesture.$imageEl.transition(0);
  4950. swiper.zoom.isScaling = true;
  4951. },
  4952. onGestureChange(e) {
  4953. const swiper = this;
  4954. const params = swiper.params.zoom;
  4955. const zoom = swiper.zoom;
  4956. const { gesture } = zoom;
  4957. if (!Support.gestures) {
  4958. if (e.type !== 'touchmove' || (e.type === 'touchmove' && e.targetTouches.length < 2)) {
  4959. return;
  4960. }
  4961. zoom.fakeGestureMoved = true;
  4962. gesture.scaleMove = Zoom.getDistanceBetweenTouches(e);
  4963. }
  4964. if (!gesture.$imageEl || gesture.$imageEl.length === 0) return;
  4965. if (Support.gestures) {
  4966. zoom.scale = e.scale * zoom.currentScale;
  4967. } else {
  4968. zoom.scale = (gesture.scaleMove / gesture.scaleStart) * zoom.currentScale;
  4969. }
  4970. if (zoom.scale > gesture.maxRatio) {
  4971. zoom.scale = (gesture.maxRatio - 1) + (((zoom.scale - gesture.maxRatio) + 1) ** 0.5);
  4972. }
  4973. if (zoom.scale < params.minRatio) {
  4974. zoom.scale = (params.minRatio + 1) - (((params.minRatio - zoom.scale) + 1) ** 0.5);
  4975. }
  4976. gesture.$imageEl.transform(`translate3d(0,0,0) scale(${zoom.scale})`);
  4977. },
  4978. onGestureEnd(e) {
  4979. const swiper = this;
  4980. const params = swiper.params.zoom;
  4981. const zoom = swiper.zoom;
  4982. const { gesture } = zoom;
  4983. if (!Support.gestures) {
  4984. if (!zoom.fakeGestureTouched || !zoom.fakeGestureMoved) {
  4985. return;
  4986. }
  4987. if (e.type !== 'touchend' || (e.type === 'touchend' && e.changedTouches.length < 2 && !Device.android)) {
  4988. return;
  4989. }
  4990. zoom.fakeGestureTouched = false;
  4991. zoom.fakeGestureMoved = false;
  4992. }
  4993. if (!gesture.$imageEl || gesture.$imageEl.length === 0) return;
  4994. zoom.scale = Math.max(Math.min(zoom.scale, gesture.maxRatio), params.minRatio);
  4995. gesture.$imageEl.transition(swiper.params.speed).transform(`translate3d(0,0,0) scale(${zoom.scale})`);
  4996. zoom.currentScale = zoom.scale;
  4997. zoom.isScaling = false;
  4998. if (zoom.scale === 1) gesture.$slideEl = undefined;
  4999. },
  5000. onTouchStart(e) {
  5001. const swiper = this;
  5002. const zoom = swiper.zoom;
  5003. const { gesture, image } = zoom;
  5004. if (!gesture.$imageEl || gesture.$imageEl.length === 0) return;
  5005. if (image.isTouched) return;
  5006. if (Device.android) e.preventDefault();
  5007. image.isTouched = true;
  5008. image.touchesStart.x = e.type === 'touchstart' ? e.targetTouches[0].pageX : e.pageX;
  5009. image.touchesStart.y = e.type === 'touchstart' ? e.targetTouches[0].pageY : e.pageY;
  5010. },
  5011. onTouchMove(e) {
  5012. const swiper = this;
  5013. const zoom = swiper.zoom;
  5014. const { gesture, image, velocity } = zoom;
  5015. if (!gesture.$imageEl || gesture.$imageEl.length === 0) return;
  5016. swiper.allowClick = false;
  5017. if (!image.isTouched || !gesture.$slideEl) return;
  5018. if (!image.isMoved) {
  5019. image.width = gesture.$imageEl[0].offsetWidth;
  5020. image.height = gesture.$imageEl[0].offsetHeight;
  5021. image.startX = Utils.getTranslate(gesture.$imageWrapEl[0], 'x') || 0;
  5022. image.startY = Utils.getTranslate(gesture.$imageWrapEl[0], 'y') || 0;
  5023. gesture.slideWidth = gesture.$slideEl[0].offsetWidth;
  5024. gesture.slideHeight = gesture.$slideEl[0].offsetHeight;
  5025. gesture.$imageWrapEl.transition(0);
  5026. if (swiper.rtl) {
  5027. image.startX = -image.startX;
  5028. image.startY = -image.startY;
  5029. }
  5030. }
  5031. // Define if we need image drag
  5032. const scaledWidth = image.width * zoom.scale;
  5033. const scaledHeight = image.height * zoom.scale;
  5034. if (scaledWidth < gesture.slideWidth && scaledHeight < gesture.slideHeight) return;
  5035. image.minX = Math.min(((gesture.slideWidth / 2) - (scaledWidth / 2)), 0);
  5036. image.maxX = -image.minX;
  5037. image.minY = Math.min(((gesture.slideHeight / 2) - (scaledHeight / 2)), 0);
  5038. image.maxY = -image.minY;
  5039. image.touchesCurrent.x = e.type === 'touchmove' ? e.targetTouches[0].pageX : e.pageX;
  5040. image.touchesCurrent.y = e.type === 'touchmove' ? e.targetTouches[0].pageY : e.pageY;
  5041. if (!image.isMoved && !zoom.isScaling) {
  5042. if (
  5043. swiper.isHorizontal()
  5044. && (
  5045. (Math.floor(image.minX) === Math.floor(image.startX) && image.touchesCurrent.x < image.touchesStart.x)
  5046. || (Math.floor(image.maxX) === Math.floor(image.startX) && image.touchesCurrent.x > image.touchesStart.x)
  5047. )
  5048. ) {
  5049. image.isTouched = false;
  5050. return;
  5051. } if (
  5052. !swiper.isHorizontal()
  5053. && (
  5054. (Math.floor(image.minY) === Math.floor(image.startY) && image.touchesCurrent.y < image.touchesStart.y)
  5055. || (Math.floor(image.maxY) === Math.floor(image.startY) && image.touchesCurrent.y > image.touchesStart.y)
  5056. )
  5057. ) {
  5058. image.isTouched = false;
  5059. return;
  5060. }
  5061. }
  5062. e.preventDefault();
  5063. e.stopPropagation();
  5064. image.isMoved = true;
  5065. image.currentX = (image.touchesCurrent.x - image.touchesStart.x) + image.startX;
  5066. image.currentY = (image.touchesCurrent.y - image.touchesStart.y) + image.startY;
  5067. if (image.currentX < image.minX) {
  5068. image.currentX = (image.minX + 1) - (((image.minX - image.currentX) + 1) ** 0.8);
  5069. }
  5070. if (image.currentX > image.maxX) {
  5071. image.currentX = (image.maxX - 1) + (((image.currentX - image.maxX) + 1) ** 0.8);
  5072. }
  5073. if (image.currentY < image.minY) {
  5074. image.currentY = (image.minY + 1) - (((image.minY - image.currentY) + 1) ** 0.8);
  5075. }
  5076. if (image.currentY > image.maxY) {
  5077. image.currentY = (image.maxY - 1) + (((image.currentY - image.maxY) + 1) ** 0.8);
  5078. }
  5079. // Velocity
  5080. if (!velocity.prevPositionX) velocity.prevPositionX = image.touchesCurrent.x;
  5081. if (!velocity.prevPositionY) velocity.prevPositionY = image.touchesCurrent.y;
  5082. if (!velocity.prevTime) velocity.prevTime = Date.now();
  5083. velocity.x = (image.touchesCurrent.x - velocity.prevPositionX) / (Date.now() - velocity.prevTime) / 2;
  5084. velocity.y = (image.touchesCurrent.y - velocity.prevPositionY) / (Date.now() - velocity.prevTime) / 2;
  5085. if (Math.abs(image.touchesCurrent.x - velocity.prevPositionX) < 2) velocity.x = 0;
  5086. if (Math.abs(image.touchesCurrent.y - velocity.prevPositionY) < 2) velocity.y = 0;
  5087. velocity.prevPositionX = image.touchesCurrent.x;
  5088. velocity.prevPositionY = image.touchesCurrent.y;
  5089. velocity.prevTime = Date.now();
  5090. gesture.$imageWrapEl.transform(`translate3d(${image.currentX}px, ${image.currentY}px,0)`);
  5091. },
  5092. onTouchEnd() {
  5093. const swiper = this;
  5094. const zoom = swiper.zoom;
  5095. const { gesture, image, velocity } = zoom;
  5096. if (!gesture.$imageEl || gesture.$imageEl.length === 0) return;
  5097. if (!image.isTouched || !image.isMoved) {
  5098. image.isTouched = false;
  5099. image.isMoved = false;
  5100. return;
  5101. }
  5102. image.isTouched = false;
  5103. image.isMoved = false;
  5104. let momentumDurationX = 300;
  5105. let momentumDurationY = 300;
  5106. const momentumDistanceX = velocity.x * momentumDurationX;
  5107. const newPositionX = image.currentX + momentumDistanceX;
  5108. const momentumDistanceY = velocity.y * momentumDurationY;
  5109. const newPositionY = image.currentY + momentumDistanceY;
  5110. // Fix duration
  5111. if (velocity.x !== 0) momentumDurationX = Math.abs((newPositionX - image.currentX) / velocity.x);
  5112. if (velocity.y !== 0) momentumDurationY = Math.abs((newPositionY - image.currentY) / velocity.y);
  5113. const momentumDuration = Math.max(momentumDurationX, momentumDurationY);
  5114. image.currentX = newPositionX;
  5115. image.currentY = newPositionY;
  5116. // Define if we need image drag
  5117. const scaledWidth = image.width * zoom.scale;
  5118. const scaledHeight = image.height * zoom.scale;
  5119. image.minX = Math.min(((gesture.slideWidth / 2) - (scaledWidth / 2)), 0);
  5120. image.maxX = -image.minX;
  5121. image.minY = Math.min(((gesture.slideHeight / 2) - (scaledHeight / 2)), 0);
  5122. image.maxY = -image.minY;
  5123. image.currentX = Math.max(Math.min(image.currentX, image.maxX), image.minX);
  5124. image.currentY = Math.max(Math.min(image.currentY, image.maxY), image.minY);
  5125. gesture.$imageWrapEl.transition(momentumDuration).transform(`translate3d(${image.currentX}px, ${image.currentY}px,0)`);
  5126. },
  5127. onTransitionEnd() {
  5128. const swiper = this;
  5129. const zoom = swiper.zoom;
  5130. const { gesture } = zoom;
  5131. if (gesture.$slideEl && swiper.previousIndex !== swiper.activeIndex) {
  5132. gesture.$imageEl.transform('translate3d(0,0,0) scale(1)');
  5133. gesture.$imageWrapEl.transform('translate3d(0,0,0)');
  5134. zoom.scale = 1;
  5135. zoom.currentScale = 1;
  5136. gesture.$slideEl = undefined;
  5137. gesture.$imageEl = undefined;
  5138. gesture.$imageWrapEl = undefined;
  5139. }
  5140. },
  5141. // Toggle Zoom
  5142. toggle(e) {
  5143. const swiper = this;
  5144. const zoom = swiper.zoom;
  5145. if (zoom.scale && zoom.scale !== 1) {
  5146. // Zoom Out
  5147. zoom.out();
  5148. } else {
  5149. // Zoom In
  5150. zoom.in(e);
  5151. }
  5152. },
  5153. in(e) {
  5154. const swiper = this;
  5155. const zoom = swiper.zoom;
  5156. const params = swiper.params.zoom;
  5157. const { gesture, image } = zoom;
  5158. if (!gesture.$slideEl) {
  5159. gesture.$slideEl = swiper.slides.eq(swiper.activeIndex);
  5160. gesture.$imageEl = gesture.$slideEl.find('img, svg, canvas, picture, .swiper-zoom-target');
  5161. gesture.$imageWrapEl = gesture.$imageEl.parent(`.${params.containerClass}`);
  5162. }
  5163. if (!gesture.$imageEl || gesture.$imageEl.length === 0) return;
  5164. gesture.$slideEl.addClass(`${params.zoomedSlideClass}`);
  5165. let touchX;
  5166. let touchY;
  5167. let offsetX;
  5168. let offsetY;
  5169. let diffX;
  5170. let diffY;
  5171. let translateX;
  5172. let translateY;
  5173. let imageWidth;
  5174. let imageHeight;
  5175. let scaledWidth;
  5176. let scaledHeight;
  5177. let translateMinX;
  5178. let translateMinY;
  5179. let translateMaxX;
  5180. let translateMaxY;
  5181. let slideWidth;
  5182. let slideHeight;
  5183. if (typeof image.touchesStart.x === 'undefined' && e) {
  5184. touchX = e.type === 'touchend' ? e.changedTouches[0].pageX : e.pageX;
  5185. touchY = e.type === 'touchend' ? e.changedTouches[0].pageY : e.pageY;
  5186. } else {
  5187. touchX = image.touchesStart.x;
  5188. touchY = image.touchesStart.y;
  5189. }
  5190. zoom.scale = gesture.$imageWrapEl.attr('data-swiper-zoom') || params.maxRatio;
  5191. zoom.currentScale = gesture.$imageWrapEl.attr('data-swiper-zoom') || params.maxRatio;
  5192. if (e) {
  5193. slideWidth = gesture.$slideEl[0].offsetWidth;
  5194. slideHeight = gesture.$slideEl[0].offsetHeight;
  5195. offsetX = gesture.$slideEl.offset().left;
  5196. offsetY = gesture.$slideEl.offset().top;
  5197. diffX = (offsetX + (slideWidth / 2)) - touchX;
  5198. diffY = (offsetY + (slideHeight / 2)) - touchY;
  5199. imageWidth = gesture.$imageEl[0].offsetWidth;
  5200. imageHeight = gesture.$imageEl[0].offsetHeight;
  5201. scaledWidth = imageWidth * zoom.scale;
  5202. scaledHeight = imageHeight * zoom.scale;
  5203. translateMinX = Math.min(((slideWidth / 2) - (scaledWidth / 2)), 0);
  5204. translateMinY = Math.min(((slideHeight / 2) - (scaledHeight / 2)), 0);
  5205. translateMaxX = -translateMinX;
  5206. translateMaxY = -translateMinY;
  5207. translateX = diffX * zoom.scale;
  5208. translateY = diffY * zoom.scale;
  5209. if (translateX < translateMinX) {
  5210. translateX = translateMinX;
  5211. }
  5212. if (translateX > translateMaxX) {
  5213. translateX = translateMaxX;
  5214. }
  5215. if (translateY < translateMinY) {
  5216. translateY = translateMinY;
  5217. }
  5218. if (translateY > translateMaxY) {
  5219. translateY = translateMaxY;
  5220. }
  5221. } else {
  5222. translateX = 0;
  5223. translateY = 0;
  5224. }
  5225. gesture.$imageWrapEl.transition(300).transform(`translate3d(${translateX}px, ${translateY}px,0)`);
  5226. gesture.$imageEl.transition(300).transform(`translate3d(0,0,0) scale(${zoom.scale})`);
  5227. },
  5228. out() {
  5229. const swiper = this;
  5230. const zoom = swiper.zoom;
  5231. const params = swiper.params.zoom;
  5232. const { gesture } = zoom;
  5233. if (!gesture.$slideEl) {
  5234. gesture.$slideEl = swiper.slides.eq(swiper.activeIndex);
  5235. gesture.$imageEl = gesture.$slideEl.find('img, svg, canvas, picture, .swiper-zoom-target');
  5236. gesture.$imageWrapEl = gesture.$imageEl.parent(`.${params.containerClass}`);
  5237. }
  5238. if (!gesture.$imageEl || gesture.$imageEl.length === 0) return;
  5239. zoom.scale = 1;
  5240. zoom.currentScale = 1;
  5241. gesture.$imageWrapEl.transition(300).transform('translate3d(0,0,0)');
  5242. gesture.$imageEl.transition(300).transform('translate3d(0,0,0) scale(1)');
  5243. gesture.$slideEl.removeClass(`${params.zoomedSlideClass}`);
  5244. gesture.$slideEl = undefined;
  5245. },
  5246. // Attach/Detach Events
  5247. enable() {
  5248. const swiper = this;
  5249. const zoom = swiper.zoom;
  5250. if (zoom.enabled) return;
  5251. zoom.enabled = true;
  5252. const passiveListener = swiper.touchEvents.start === 'touchstart' && Support.passiveListener && swiper.params.passiveListeners ? { passive: true, capture: false } : false;
  5253. const activeListenerWithCapture = Support.passiveListener ? { passive: false, capture: true } : true;
  5254. const slideSelector = `.${swiper.params.slideClass}`;
  5255. // Scale image
  5256. if (Support.gestures) {
  5257. swiper.$wrapperEl.on('gesturestart', slideSelector, zoom.onGestureStart, passiveListener);
  5258. swiper.$wrapperEl.on('gesturechange', slideSelector, zoom.onGestureChange, passiveListener);
  5259. swiper.$wrapperEl.on('gestureend', slideSelector, zoom.onGestureEnd, passiveListener);
  5260. } else if (swiper.touchEvents.start === 'touchstart') {
  5261. swiper.$wrapperEl.on(swiper.touchEvents.start, slideSelector, zoom.onGestureStart, passiveListener);
  5262. swiper.$wrapperEl.on(swiper.touchEvents.move, slideSelector, zoom.onGestureChange, activeListenerWithCapture);
  5263. swiper.$wrapperEl.on(swiper.touchEvents.end, slideSelector, zoom.onGestureEnd, passiveListener);
  5264. if (swiper.touchEvents.cancel) {
  5265. swiper.$wrapperEl.on(swiper.touchEvents.cancel, slideSelector, zoom.onGestureEnd, passiveListener);
  5266. }
  5267. }
  5268. // Move image
  5269. swiper.$wrapperEl.on(swiper.touchEvents.move, `.${swiper.params.zoom.containerClass}`, zoom.onTouchMove, activeListenerWithCapture);
  5270. },
  5271. disable() {
  5272. const swiper = this;
  5273. const zoom = swiper.zoom;
  5274. if (!zoom.enabled) return;
  5275. swiper.zoom.enabled = false;
  5276. const passiveListener = swiper.touchEvents.start === 'touchstart' && Support.passiveListener && swiper.params.passiveListeners ? { passive: true, capture: false } : false;
  5277. const activeListenerWithCapture = Support.passiveListener ? { passive: false, capture: true } : true;
  5278. const slideSelector = `.${swiper.params.slideClass}`;
  5279. // Scale image
  5280. if (Support.gestures) {
  5281. swiper.$wrapperEl.off('gesturestart', slideSelector, zoom.onGestureStart, passiveListener);
  5282. swiper.$wrapperEl.off('gesturechange', slideSelector, zoom.onGestureChange, passiveListener);
  5283. swiper.$wrapperEl.off('gestureend', slideSelector, zoom.onGestureEnd, passiveListener);
  5284. } else if (swiper.touchEvents.start === 'touchstart') {
  5285. swiper.$wrapperEl.off(swiper.touchEvents.start, slideSelector, zoom.onGestureStart, passiveListener);
  5286. swiper.$wrapperEl.off(swiper.touchEvents.move, slideSelector, zoom.onGestureChange, activeListenerWithCapture);
  5287. swiper.$wrapperEl.off(swiper.touchEvents.end, slideSelector, zoom.onGestureEnd, passiveListener);
  5288. if (swiper.touchEvents.cancel) {
  5289. swiper.$wrapperEl.off(swiper.touchEvents.cancel, slideSelector, zoom.onGestureEnd, passiveListener);
  5290. }
  5291. }
  5292. // Move image
  5293. swiper.$wrapperEl.off(swiper.touchEvents.move, `.${swiper.params.zoom.containerClass}`, zoom.onTouchMove, activeListenerWithCapture);
  5294. },
  5295. };
  5296. var zoom = {
  5297. name: 'zoom',
  5298. params: {
  5299. zoom: {
  5300. enabled: false,
  5301. maxRatio: 3,
  5302. minRatio: 1,
  5303. toggle: true,
  5304. containerClass: 'swiper-zoom-container',
  5305. zoomedSlideClass: 'swiper-slide-zoomed',
  5306. },
  5307. },
  5308. create() {
  5309. const swiper = this;
  5310. const zoom = {
  5311. enabled: false,
  5312. scale: 1,
  5313. currentScale: 1,
  5314. isScaling: false,
  5315. gesture: {
  5316. $slideEl: undefined,
  5317. slideWidth: undefined,
  5318. slideHeight: undefined,
  5319. $imageEl: undefined,
  5320. $imageWrapEl: undefined,
  5321. maxRatio: 3,
  5322. },
  5323. image: {
  5324. isTouched: undefined,
  5325. isMoved: undefined,
  5326. currentX: undefined,
  5327. currentY: undefined,
  5328. minX: undefined,
  5329. minY: undefined,
  5330. maxX: undefined,
  5331. maxY: undefined,
  5332. width: undefined,
  5333. height: undefined,
  5334. startX: undefined,
  5335. startY: undefined,
  5336. touchesStart: {},
  5337. touchesCurrent: {},
  5338. },
  5339. velocity: {
  5340. x: undefined,
  5341. y: undefined,
  5342. prevPositionX: undefined,
  5343. prevPositionY: undefined,
  5344. prevTime: undefined,
  5345. },
  5346. };
  5347. ('onGestureStart onGestureChange onGestureEnd onTouchStart onTouchMove onTouchEnd onTransitionEnd toggle enable disable in out').split(' ').forEach((methodName) => {
  5348. zoom[methodName] = Zoom[methodName].bind(swiper);
  5349. });
  5350. Utils.extend(swiper, {
  5351. zoom,
  5352. });
  5353. let scale = 1;
  5354. Object.defineProperty(swiper.zoom, 'scale', {
  5355. get() {
  5356. return scale;
  5357. },
  5358. set(value) {
  5359. if (scale !== value) {
  5360. const imageEl = swiper.zoom.gesture.$imageEl ? swiper.zoom.gesture.$imageEl[0] : undefined;
  5361. const slideEl = swiper.zoom.gesture.$slideEl ? swiper.zoom.gesture.$slideEl[0] : undefined;
  5362. swiper.emit('zoomChange', value, imageEl, slideEl);
  5363. }
  5364. scale = value;
  5365. },
  5366. });
  5367. },
  5368. on: {
  5369. init() {
  5370. const swiper = this;
  5371. if (swiper.params.zoom.enabled) {
  5372. swiper.zoom.enable();
  5373. }
  5374. },
  5375. destroy() {
  5376. const swiper = this;
  5377. swiper.zoom.disable();
  5378. },
  5379. touchStart(e) {
  5380. const swiper = this;
  5381. if (!swiper.zoom.enabled) return;
  5382. swiper.zoom.onTouchStart(e);
  5383. },
  5384. touchEnd(e) {
  5385. const swiper = this;
  5386. if (!swiper.zoom.enabled) return;
  5387. swiper.zoom.onTouchEnd(e);
  5388. },
  5389. doubleTap(e) {
  5390. const swiper = this;
  5391. if (swiper.params.zoom.enabled && swiper.zoom.enabled && swiper.params.zoom.toggle) {
  5392. swiper.zoom.toggle(e);
  5393. }
  5394. },
  5395. transitionEnd() {
  5396. const swiper = this;
  5397. if (swiper.zoom.enabled && swiper.params.zoom.enabled) {
  5398. swiper.zoom.onTransitionEnd();
  5399. }
  5400. },
  5401. slideChange() {
  5402. const swiper = this;
  5403. if (swiper.zoom.enabled && swiper.params.zoom.enabled && swiper.params.cssMode) {
  5404. swiper.zoom.onTransitionEnd();
  5405. }
  5406. },
  5407. },
  5408. };
  5409. const Lazy = {
  5410. loadInSlide(index, loadInDuplicate = true) {
  5411. const swiper = this;
  5412. const params = swiper.params.lazy;
  5413. if (typeof index === 'undefined') return;
  5414. if (swiper.slides.length === 0) return;
  5415. const isVirtual = swiper.virtual && swiper.params.virtual.enabled;
  5416. const $slideEl = isVirtual
  5417. ? swiper.$wrapperEl.children(`.${swiper.params.slideClass}[data-swiper-slide-index="${index}"]`)
  5418. : swiper.slides.eq(index);
  5419. let $images = $slideEl.find(`.${params.elementClass}:not(.${params.loadedClass}):not(.${params.loadingClass})`);
  5420. if ($slideEl.hasClass(params.elementClass) && !$slideEl.hasClass(params.loadedClass) && !$slideEl.hasClass(params.loadingClass)) {
  5421. $images = $images.add($slideEl[0]);
  5422. }
  5423. if ($images.length === 0) return;
  5424. $images.each((imageIndex, imageEl) => {
  5425. const $imageEl = $(imageEl);
  5426. $imageEl.addClass(params.loadingClass);
  5427. const background = $imageEl.attr('data-background');
  5428. const src = $imageEl.attr('data-src');
  5429. const srcset = $imageEl.attr('data-srcset');
  5430. const sizes = $imageEl.attr('data-sizes');
  5431. swiper.loadImage($imageEl[0], (src || background), srcset, sizes, false, () => {
  5432. if (typeof swiper === 'undefined' || swiper === null || !swiper || (swiper && !swiper.params) || swiper.destroyed) return;
  5433. if (background) {
  5434. $imageEl.css('background-image', `url("${background}")`);
  5435. $imageEl.removeAttr('data-background');
  5436. } else {
  5437. if (srcset) {
  5438. $imageEl.attr('srcset', srcset);
  5439. $imageEl.removeAttr('data-srcset');
  5440. }
  5441. if (sizes) {
  5442. $imageEl.attr('sizes', sizes);
  5443. $imageEl.removeAttr('data-sizes');
  5444. }
  5445. if (src) {
  5446. $imageEl.attr('src', src);
  5447. $imageEl.removeAttr('data-src');
  5448. }
  5449. }
  5450. $imageEl.addClass(params.loadedClass).removeClass(params.loadingClass);
  5451. $slideEl.find(`.${params.preloaderClass}`).remove();
  5452. if (swiper.params.loop && loadInDuplicate) {
  5453. const slideOriginalIndex = $slideEl.attr('data-swiper-slide-index');
  5454. if ($slideEl.hasClass(swiper.params.slideDuplicateClass)) {
  5455. const originalSlide = swiper.$wrapperEl.children(`[data-swiper-slide-index="${slideOriginalIndex}"]:not(.${swiper.params.slideDuplicateClass})`);
  5456. swiper.lazy.loadInSlide(originalSlide.index(), false);
  5457. } else {
  5458. const duplicatedSlide = swiper.$wrapperEl.children(`.${swiper.params.slideDuplicateClass}[data-swiper-slide-index="${slideOriginalIndex}"]`);
  5459. swiper.lazy.loadInSlide(duplicatedSlide.index(), false);
  5460. }
  5461. }
  5462. swiper.emit('lazyImageReady', $slideEl[0], $imageEl[0]);
  5463. if (swiper.params.autoHeight) {
  5464. swiper.updateAutoHeight();
  5465. }
  5466. });
  5467. swiper.emit('lazyImageLoad', $slideEl[0], $imageEl[0]);
  5468. });
  5469. },
  5470. load() {
  5471. const swiper = this;
  5472. const {
  5473. $wrapperEl, params: swiperParams, slides, activeIndex,
  5474. } = swiper;
  5475. const isVirtual = swiper.virtual && swiperParams.virtual.enabled;
  5476. const params = swiperParams.lazy;
  5477. let slidesPerView = swiperParams.slidesPerView;
  5478. if (slidesPerView === 'auto') {
  5479. slidesPerView = 0;
  5480. }
  5481. function slideExist(index) {
  5482. if (isVirtual) {
  5483. if ($wrapperEl.children(`.${swiperParams.slideClass}[data-swiper-slide-index="${index}"]`).length) {
  5484. return true;
  5485. }
  5486. } else if (slides[index]) return true;
  5487. return false;
  5488. }
  5489. function slideIndex(slideEl) {
  5490. if (isVirtual) {
  5491. return $(slideEl).attr('data-swiper-slide-index');
  5492. }
  5493. return $(slideEl).index();
  5494. }
  5495. if (!swiper.lazy.initialImageLoaded) swiper.lazy.initialImageLoaded = true;
  5496. if (swiper.params.watchSlidesVisibility) {
  5497. $wrapperEl.children(`.${swiperParams.slideVisibleClass}`).each((elIndex, slideEl) => {
  5498. const index = isVirtual ? $(slideEl).attr('data-swiper-slide-index') : $(slideEl).index();
  5499. swiper.lazy.loadInSlide(index);
  5500. });
  5501. } else if (slidesPerView > 1) {
  5502. for (let i = activeIndex; i < activeIndex + slidesPerView; i += 1) {
  5503. if (slideExist(i)) swiper.lazy.loadInSlide(i);
  5504. }
  5505. } else {
  5506. swiper.lazy.loadInSlide(activeIndex);
  5507. }
  5508. if (params.loadPrevNext) {
  5509. if (slidesPerView > 1 || (params.loadPrevNextAmount && params.loadPrevNextAmount > 1)) {
  5510. const amount = params.loadPrevNextAmount;
  5511. const spv = slidesPerView;
  5512. const maxIndex = Math.min(activeIndex + spv + Math.max(amount, spv), slides.length);
  5513. const minIndex = Math.max(activeIndex - Math.max(spv, amount), 0);
  5514. // Next Slides
  5515. for (let i = activeIndex + slidesPerView; i < maxIndex; i += 1) {
  5516. if (slideExist(i)) swiper.lazy.loadInSlide(i);
  5517. }
  5518. // Prev Slides
  5519. for (let i = minIndex; i < activeIndex; i += 1) {
  5520. if (slideExist(i)) swiper.lazy.loadInSlide(i);
  5521. }
  5522. } else {
  5523. const nextSlide = $wrapperEl.children(`.${swiperParams.slideNextClass}`);
  5524. if (nextSlide.length > 0) swiper.lazy.loadInSlide(slideIndex(nextSlide));
  5525. const prevSlide = $wrapperEl.children(`.${swiperParams.slidePrevClass}`);
  5526. if (prevSlide.length > 0) swiper.lazy.loadInSlide(slideIndex(prevSlide));
  5527. }
  5528. }
  5529. },
  5530. };
  5531. var lazy = {
  5532. name: 'lazy',
  5533. params: {
  5534. lazy: {
  5535. enabled: false,
  5536. loadPrevNext: false,
  5537. loadPrevNextAmount: 1,
  5538. loadOnTransitionStart: false,
  5539. elementClass: 'swiper-lazy',
  5540. loadingClass: 'swiper-lazy-loading',
  5541. loadedClass: 'swiper-lazy-loaded',
  5542. preloaderClass: 'swiper-lazy-preloader',
  5543. },
  5544. },
  5545. create() {
  5546. const swiper = this;
  5547. Utils.extend(swiper, {
  5548. lazy: {
  5549. initialImageLoaded: false,
  5550. load: Lazy.load.bind(swiper),
  5551. loadInSlide: Lazy.loadInSlide.bind(swiper),
  5552. },
  5553. });
  5554. },
  5555. on: {
  5556. beforeInit() {
  5557. const swiper = this;
  5558. if (swiper.params.lazy.enabled && swiper.params.preloadImages) {
  5559. swiper.params.preloadImages = false;
  5560. }
  5561. },
  5562. init() {
  5563. const swiper = this;
  5564. if (swiper.params.lazy.enabled && !swiper.params.loop && swiper.params.initialSlide === 0) {
  5565. swiper.lazy.load();
  5566. }
  5567. },
  5568. scroll() {
  5569. const swiper = this;
  5570. if (swiper.params.freeMode && !swiper.params.freeModeSticky) {
  5571. swiper.lazy.load();
  5572. }
  5573. },
  5574. resize() {
  5575. const swiper = this;
  5576. if (swiper.params.lazy.enabled) {
  5577. swiper.lazy.load();
  5578. }
  5579. },
  5580. scrollbarDragMove() {
  5581. const swiper = this;
  5582. if (swiper.params.lazy.enabled) {
  5583. swiper.lazy.load();
  5584. }
  5585. },
  5586. transitionStart() {
  5587. const swiper = this;
  5588. if (swiper.params.lazy.enabled) {
  5589. if (swiper.params.lazy.loadOnTransitionStart || (!swiper.params.lazy.loadOnTransitionStart && !swiper.lazy.initialImageLoaded)) {
  5590. swiper.lazy.load();
  5591. }
  5592. }
  5593. },
  5594. transitionEnd() {
  5595. const swiper = this;
  5596. if (swiper.params.lazy.enabled && !swiper.params.lazy.loadOnTransitionStart) {
  5597. swiper.lazy.load();
  5598. }
  5599. },
  5600. slideChange() {
  5601. const swiper = this;
  5602. if (swiper.params.lazy.enabled && swiper.params.cssMode) {
  5603. swiper.lazy.load();
  5604. }
  5605. },
  5606. },
  5607. };
  5608. /* eslint no-bitwise: ["error", { "allow": [">>"] }] */
  5609. const Controller = {
  5610. LinearSpline: function LinearSpline(x, y) {
  5611. const binarySearch = (function search() {
  5612. let maxIndex;
  5613. let minIndex;
  5614. let guess;
  5615. return (array, val) => {
  5616. minIndex = -1;
  5617. maxIndex = array.length;
  5618. while (maxIndex - minIndex > 1) {
  5619. guess = maxIndex + minIndex >> 1;
  5620. if (array[guess] <= val) {
  5621. minIndex = guess;
  5622. } else {
  5623. maxIndex = guess;
  5624. }
  5625. }
  5626. return maxIndex;
  5627. };
  5628. }());
  5629. this.x = x;
  5630. this.y = y;
  5631. this.lastIndex = x.length - 1;
  5632. // Given an x value (x2), return the expected y2 value:
  5633. // (x1,y1) is the known point before given value,
  5634. // (x3,y3) is the known point after given value.
  5635. let i1;
  5636. let i3;
  5637. this.interpolate = function interpolate(x2) {
  5638. if (!x2) return 0;
  5639. // Get the indexes of x1 and x3 (the array indexes before and after given x2):
  5640. i3 = binarySearch(this.x, x2);
  5641. i1 = i3 - 1;
  5642. // We have our indexes i1 & i3, so we can calculate already:
  5643. // y2 := ((x2−x1) × (y3−y1)) ÷ (x3−x1) + y1
  5644. return (((x2 - this.x[i1]) * (this.y[i3] - this.y[i1])) / (this.x[i3] - this.x[i1])) + this.y[i1];
  5645. };
  5646. return this;
  5647. },
  5648. // xxx: for now i will just save one spline function to to
  5649. getInterpolateFunction(c) {
  5650. const swiper = this;
  5651. if (!swiper.controller.spline) {
  5652. swiper.controller.spline = swiper.params.loop
  5653. ? new Controller.LinearSpline(swiper.slidesGrid, c.slidesGrid)
  5654. : new Controller.LinearSpline(swiper.snapGrid, c.snapGrid);
  5655. }
  5656. },
  5657. setTranslate(setTranslate, byController) {
  5658. const swiper = this;
  5659. const controlled = swiper.controller.control;
  5660. let multiplier;
  5661. let controlledTranslate;
  5662. function setControlledTranslate(c) {
  5663. // this will create an Interpolate function based on the snapGrids
  5664. // x is the Grid of the scrolled scroller and y will be the controlled scroller
  5665. // it makes sense to create this only once and recall it for the interpolation
  5666. // the function does a lot of value caching for performance
  5667. const translate = swiper.rtlTranslate ? -swiper.translate : swiper.translate;
  5668. if (swiper.params.controller.by === 'slide') {
  5669. swiper.controller.getInterpolateFunction(c);
  5670. // i am not sure why the values have to be multiplicated this way, tried to invert the snapGrid
  5671. // but it did not work out
  5672. controlledTranslate = -swiper.controller.spline.interpolate(-translate);
  5673. }
  5674. if (!controlledTranslate || swiper.params.controller.by === 'container') {
  5675. multiplier = (c.maxTranslate() - c.minTranslate()) / (swiper.maxTranslate() - swiper.minTranslate());
  5676. controlledTranslate = ((translate - swiper.minTranslate()) * multiplier) + c.minTranslate();
  5677. }
  5678. if (swiper.params.controller.inverse) {
  5679. controlledTranslate = c.maxTranslate() - controlledTranslate;
  5680. }
  5681. c.updateProgress(controlledTranslate);
  5682. c.setTranslate(controlledTranslate, swiper);
  5683. c.updateActiveIndex();
  5684. c.updateSlidesClasses();
  5685. }
  5686. if (Array.isArray(controlled)) {
  5687. for (let i = 0; i < controlled.length; i += 1) {
  5688. if (controlled[i] !== byController && controlled[i] instanceof Swiper) {
  5689. setControlledTranslate(controlled[i]);
  5690. }
  5691. }
  5692. } else if (controlled instanceof Swiper && byController !== controlled) {
  5693. setControlledTranslate(controlled);
  5694. }
  5695. },
  5696. setTransition(duration, byController) {
  5697. const swiper = this;
  5698. const controlled = swiper.controller.control;
  5699. let i;
  5700. function setControlledTransition(c) {
  5701. c.setTransition(duration, swiper);
  5702. if (duration !== 0) {
  5703. c.transitionStart();
  5704. if (c.params.autoHeight) {
  5705. Utils.nextTick(() => {
  5706. c.updateAutoHeight();
  5707. });
  5708. }
  5709. c.$wrapperEl.transitionEnd(() => {
  5710. if (!controlled) return;
  5711. if (c.params.loop && swiper.params.controller.by === 'slide') {
  5712. c.loopFix();
  5713. }
  5714. c.transitionEnd();
  5715. });
  5716. }
  5717. }
  5718. if (Array.isArray(controlled)) {
  5719. for (i = 0; i < controlled.length; i += 1) {
  5720. if (controlled[i] !== byController && controlled[i] instanceof Swiper) {
  5721. setControlledTransition(controlled[i]);
  5722. }
  5723. }
  5724. } else if (controlled instanceof Swiper && byController !== controlled) {
  5725. setControlledTransition(controlled);
  5726. }
  5727. },
  5728. };
  5729. var controller = {
  5730. name: 'controller',
  5731. params: {
  5732. controller: {
  5733. control: undefined,
  5734. inverse: false,
  5735. by: 'slide', // or 'container'
  5736. },
  5737. },
  5738. create() {
  5739. const swiper = this;
  5740. Utils.extend(swiper, {
  5741. controller: {
  5742. control: swiper.params.controller.control,
  5743. getInterpolateFunction: Controller.getInterpolateFunction.bind(swiper),
  5744. setTranslate: Controller.setTranslate.bind(swiper),
  5745. setTransition: Controller.setTransition.bind(swiper),
  5746. },
  5747. });
  5748. },
  5749. on: {
  5750. update() {
  5751. const swiper = this;
  5752. if (!swiper.controller.control) return;
  5753. if (swiper.controller.spline) {
  5754. swiper.controller.spline = undefined;
  5755. delete swiper.controller.spline;
  5756. }
  5757. },
  5758. resize() {
  5759. const swiper = this;
  5760. if (!swiper.controller.control) return;
  5761. if (swiper.controller.spline) {
  5762. swiper.controller.spline = undefined;
  5763. delete swiper.controller.spline;
  5764. }
  5765. },
  5766. observerUpdate() {
  5767. const swiper = this;
  5768. if (!swiper.controller.control) return;
  5769. if (swiper.controller.spline) {
  5770. swiper.controller.spline = undefined;
  5771. delete swiper.controller.spline;
  5772. }
  5773. },
  5774. setTranslate(translate, byController) {
  5775. const swiper = this;
  5776. if (!swiper.controller.control) return;
  5777. swiper.controller.setTranslate(translate, byController);
  5778. },
  5779. setTransition(duration, byController) {
  5780. const swiper = this;
  5781. if (!swiper.controller.control) return;
  5782. swiper.controller.setTransition(duration, byController);
  5783. },
  5784. },
  5785. };
  5786. const a11y = {
  5787. makeElFocusable($el) {
  5788. $el.attr('tabIndex', '0');
  5789. return $el;
  5790. },
  5791. addElRole($el, role) {
  5792. $el.attr('role', role);
  5793. return $el;
  5794. },
  5795. addElLabel($el, label) {
  5796. $el.attr('aria-label', label);
  5797. return $el;
  5798. },
  5799. disableEl($el) {
  5800. $el.attr('aria-disabled', true);
  5801. return $el;
  5802. },
  5803. enableEl($el) {
  5804. $el.attr('aria-disabled', false);
  5805. return $el;
  5806. },
  5807. onEnterKey(e) {
  5808. const swiper = this;
  5809. const params = swiper.params.a11y;
  5810. if (e.keyCode !== 13) return;
  5811. const $targetEl = $(e.target);
  5812. if (swiper.navigation && swiper.navigation.$nextEl && $targetEl.is(swiper.navigation.$nextEl)) {
  5813. if (!(swiper.isEnd && !swiper.params.loop)) {
  5814. swiper.slideNext();
  5815. }
  5816. if (swiper.isEnd) {
  5817. swiper.a11y.notify(params.lastSlideMessage);
  5818. } else {
  5819. swiper.a11y.notify(params.nextSlideMessage);
  5820. }
  5821. }
  5822. if (swiper.navigation && swiper.navigation.$prevEl && $targetEl.is(swiper.navigation.$prevEl)) {
  5823. if (!(swiper.isBeginning && !swiper.params.loop)) {
  5824. swiper.slidePrev();
  5825. }
  5826. if (swiper.isBeginning) {
  5827. swiper.a11y.notify(params.firstSlideMessage);
  5828. } else {
  5829. swiper.a11y.notify(params.prevSlideMessage);
  5830. }
  5831. }
  5832. if (swiper.pagination && $targetEl.is(`.${swiper.params.pagination.bulletClass}`)) {
  5833. $targetEl[0].click();
  5834. }
  5835. },
  5836. notify(message) {
  5837. const swiper = this;
  5838. const notification = swiper.a11y.liveRegion;
  5839. if (notification.length === 0) return;
  5840. notification.html('');
  5841. notification.html(message);
  5842. },
  5843. updateNavigation() {
  5844. const swiper = this;
  5845. if (swiper.params.loop || !swiper.navigation) return;
  5846. const { $nextEl, $prevEl } = swiper.navigation;
  5847. if ($prevEl && $prevEl.length > 0) {
  5848. if (swiper.isBeginning) {
  5849. swiper.a11y.disableEl($prevEl);
  5850. } else {
  5851. swiper.a11y.enableEl($prevEl);
  5852. }
  5853. }
  5854. if ($nextEl && $nextEl.length > 0) {
  5855. if (swiper.isEnd) {
  5856. swiper.a11y.disableEl($nextEl);
  5857. } else {
  5858. swiper.a11y.enableEl($nextEl);
  5859. }
  5860. }
  5861. },
  5862. updatePagination() {
  5863. const swiper = this;
  5864. const params = swiper.params.a11y;
  5865. if (swiper.pagination && swiper.params.pagination.clickable && swiper.pagination.bullets && swiper.pagination.bullets.length) {
  5866. swiper.pagination.bullets.each((bulletIndex, bulletEl) => {
  5867. const $bulletEl = $(bulletEl);
  5868. swiper.a11y.makeElFocusable($bulletEl);
  5869. swiper.a11y.addElRole($bulletEl, 'button');
  5870. swiper.a11y.addElLabel($bulletEl, params.paginationBulletMessage.replace(/{{index}}/, $bulletEl.index() + 1));
  5871. });
  5872. }
  5873. },
  5874. init() {
  5875. const swiper = this;
  5876. swiper.$el.append(swiper.a11y.liveRegion);
  5877. // Navigation
  5878. const params = swiper.params.a11y;
  5879. let $nextEl;
  5880. let $prevEl;
  5881. if (swiper.navigation && swiper.navigation.$nextEl) {
  5882. $nextEl = swiper.navigation.$nextEl;
  5883. }
  5884. if (swiper.navigation && swiper.navigation.$prevEl) {
  5885. $prevEl = swiper.navigation.$prevEl;
  5886. }
  5887. if ($nextEl) {
  5888. swiper.a11y.makeElFocusable($nextEl);
  5889. swiper.a11y.addElRole($nextEl, 'button');
  5890. swiper.a11y.addElLabel($nextEl, params.nextSlideMessage);
  5891. $nextEl.on('keydown', swiper.a11y.onEnterKey);
  5892. }
  5893. if ($prevEl) {
  5894. swiper.a11y.makeElFocusable($prevEl);
  5895. swiper.a11y.addElRole($prevEl, 'button');
  5896. swiper.a11y.addElLabel($prevEl, params.prevSlideMessage);
  5897. $prevEl.on('keydown', swiper.a11y.onEnterKey);
  5898. }
  5899. // Pagination
  5900. if (swiper.pagination && swiper.params.pagination.clickable && swiper.pagination.bullets && swiper.pagination.bullets.length) {
  5901. swiper.pagination.$el.on('keydown', `.${swiper.params.pagination.bulletClass}`, swiper.a11y.onEnterKey);
  5902. }
  5903. },
  5904. destroy() {
  5905. const swiper = this;
  5906. if (swiper.a11y.liveRegion && swiper.a11y.liveRegion.length > 0) swiper.a11y.liveRegion.remove();
  5907. let $nextEl;
  5908. let $prevEl;
  5909. if (swiper.navigation && swiper.navigation.$nextEl) {
  5910. $nextEl = swiper.navigation.$nextEl;
  5911. }
  5912. if (swiper.navigation && swiper.navigation.$prevEl) {
  5913. $prevEl = swiper.navigation.$prevEl;
  5914. }
  5915. if ($nextEl) {
  5916. $nextEl.off('keydown', swiper.a11y.onEnterKey);
  5917. }
  5918. if ($prevEl) {
  5919. $prevEl.off('keydown', swiper.a11y.onEnterKey);
  5920. }
  5921. // Pagination
  5922. if (swiper.pagination && swiper.params.pagination.clickable && swiper.pagination.bullets && swiper.pagination.bullets.length) {
  5923. swiper.pagination.$el.off('keydown', `.${swiper.params.pagination.bulletClass}`, swiper.a11y.onEnterKey);
  5924. }
  5925. },
  5926. };
  5927. var a11y$1 = {
  5928. name: 'a11y',
  5929. params: {
  5930. a11y: {
  5931. enabled: true,
  5932. notificationClass: 'swiper-notification',
  5933. prevSlideMessage: 'Previous slide',
  5934. nextSlideMessage: 'Next slide',
  5935. firstSlideMessage: 'This is the first slide',
  5936. lastSlideMessage: 'This is the last slide',
  5937. paginationBulletMessage: 'Go to slide {{index}}',
  5938. },
  5939. },
  5940. create() {
  5941. const swiper = this;
  5942. Utils.extend(swiper, {
  5943. a11y: {
  5944. liveRegion: $(`<span class="${swiper.params.a11y.notificationClass}" aria-live="assertive" aria-atomic="true"></span>`),
  5945. },
  5946. });
  5947. Object.keys(a11y).forEach((methodName) => {
  5948. swiper.a11y[methodName] = a11y[methodName].bind(swiper);
  5949. });
  5950. },
  5951. on: {
  5952. init() {
  5953. const swiper = this;
  5954. if (!swiper.params.a11y.enabled) return;
  5955. swiper.a11y.init();
  5956. swiper.a11y.updateNavigation();
  5957. },
  5958. toEdge() {
  5959. const swiper = this;
  5960. if (!swiper.params.a11y.enabled) return;
  5961. swiper.a11y.updateNavigation();
  5962. },
  5963. fromEdge() {
  5964. const swiper = this;
  5965. if (!swiper.params.a11y.enabled) return;
  5966. swiper.a11y.updateNavigation();
  5967. },
  5968. paginationUpdate() {
  5969. const swiper = this;
  5970. if (!swiper.params.a11y.enabled) return;
  5971. swiper.a11y.updatePagination();
  5972. },
  5973. destroy() {
  5974. const swiper = this;
  5975. if (!swiper.params.a11y.enabled) return;
  5976. swiper.a11y.destroy();
  5977. },
  5978. },
  5979. };
  5980. const History = {
  5981. init() {
  5982. const swiper = this;
  5983. if (!swiper.params.history) return;
  5984. if (!window.history || !window.history.pushState) {
  5985. swiper.params.history.enabled = false;
  5986. swiper.params.hashNavigation.enabled = true;
  5987. return;
  5988. }
  5989. const history = swiper.history;
  5990. history.initialized = true;
  5991. history.paths = History.getPathValues();
  5992. if (!history.paths.key && !history.paths.value) return;
  5993. history.scrollToSlide(0, history.paths.value, swiper.params.runCallbacksOnInit);
  5994. if (!swiper.params.history.replaceState) {
  5995. window.addEventListener('popstate', swiper.history.setHistoryPopState);
  5996. }
  5997. },
  5998. destroy() {
  5999. const swiper = this;
  6000. if (!swiper.params.history.replaceState) {
  6001. window.removeEventListener('popstate', swiper.history.setHistoryPopState);
  6002. }
  6003. },
  6004. setHistoryPopState() {
  6005. const swiper = this;
  6006. swiper.history.paths = History.getPathValues();
  6007. swiper.history.scrollToSlide(swiper.params.speed, swiper.history.paths.value, false);
  6008. },
  6009. getPathValues() {
  6010. const pathArray = window.location.pathname.slice(1).split('/').filter((part) => part !== '');
  6011. const total = pathArray.length;
  6012. const key = pathArray[total - 2];
  6013. const value = pathArray[total - 1];
  6014. return { key, value };
  6015. },
  6016. setHistory(key, index) {
  6017. const swiper = this;
  6018. if (!swiper.history.initialized || !swiper.params.history.enabled) return;
  6019. const slide = swiper.slides.eq(index);
  6020. let value = History.slugify(slide.attr('data-history'));
  6021. if (!window.location.pathname.includes(key)) {
  6022. value = `${key}/${value}`;
  6023. }
  6024. const currentState = window.history.state;
  6025. if (currentState && currentState.value === value) {
  6026. return;
  6027. }
  6028. if (swiper.params.history.replaceState) {
  6029. window.history.replaceState({ value }, null, value);
  6030. } else {
  6031. window.history.pushState({ value }, null, value);
  6032. }
  6033. },
  6034. slugify(text) {
  6035. return text.toString()
  6036. .replace(/\s+/g, '-')
  6037. .replace(/[^\w-]+/g, '')
  6038. .replace(/--+/g, '-')
  6039. .replace(/^-+/, '')
  6040. .replace(/-+$/, '');
  6041. },
  6042. scrollToSlide(speed, value, runCallbacks) {
  6043. const swiper = this;
  6044. if (value) {
  6045. for (let i = 0, length = swiper.slides.length; i < length; i += 1) {
  6046. const slide = swiper.slides.eq(i);
  6047. const slideHistory = History.slugify(slide.attr('data-history'));
  6048. if (slideHistory === value && !slide.hasClass(swiper.params.slideDuplicateClass)) {
  6049. const index = slide.index();
  6050. swiper.slideTo(index, speed, runCallbacks);
  6051. }
  6052. }
  6053. } else {
  6054. swiper.slideTo(0, speed, runCallbacks);
  6055. }
  6056. },
  6057. };
  6058. var history = {
  6059. name: 'history',
  6060. params: {
  6061. history: {
  6062. enabled: false,
  6063. replaceState: false,
  6064. key: 'slides',
  6065. },
  6066. },
  6067. create() {
  6068. const swiper = this;
  6069. Utils.extend(swiper, {
  6070. history: {
  6071. init: History.init.bind(swiper),
  6072. setHistory: History.setHistory.bind(swiper),
  6073. setHistoryPopState: History.setHistoryPopState.bind(swiper),
  6074. scrollToSlide: History.scrollToSlide.bind(swiper),
  6075. destroy: History.destroy.bind(swiper),
  6076. },
  6077. });
  6078. },
  6079. on: {
  6080. init() {
  6081. const swiper = this;
  6082. if (swiper.params.history.enabled) {
  6083. swiper.history.init();
  6084. }
  6085. },
  6086. destroy() {
  6087. const swiper = this;
  6088. if (swiper.params.history.enabled) {
  6089. swiper.history.destroy();
  6090. }
  6091. },
  6092. transitionEnd() {
  6093. const swiper = this;
  6094. if (swiper.history.initialized) {
  6095. swiper.history.setHistory(swiper.params.history.key, swiper.activeIndex);
  6096. }
  6097. },
  6098. slideChange() {
  6099. const swiper = this;
  6100. if (swiper.history.initialized && swiper.params.cssMode) {
  6101. swiper.history.setHistory(swiper.params.history.key, swiper.activeIndex);
  6102. }
  6103. },
  6104. },
  6105. };
  6106. const HashNavigation = {
  6107. onHashCange() {
  6108. const swiper = this;
  6109. const newHash = document$1.location.hash.replace('#', '');
  6110. const activeSlideHash = swiper.slides.eq(swiper.activeIndex).attr('data-hash');
  6111. if (newHash !== activeSlideHash) {
  6112. const newIndex = swiper.$wrapperEl.children(`.${swiper.params.slideClass}[data-hash="${newHash}"]`).index();
  6113. if (typeof newIndex === 'undefined') return;
  6114. swiper.slideTo(newIndex);
  6115. }
  6116. },
  6117. setHash() {
  6118. const swiper = this;
  6119. if (!swiper.hashNavigation.initialized || !swiper.params.hashNavigation.enabled) return;
  6120. if (swiper.params.hashNavigation.replaceState && window.history && window.history.replaceState) {
  6121. window.history.replaceState(null, null, (`#${swiper.slides.eq(swiper.activeIndex).attr('data-hash')}` || ''));
  6122. } else {
  6123. const slide = swiper.slides.eq(swiper.activeIndex);
  6124. const hash = slide.attr('data-hash') || slide.attr('data-history');
  6125. document$1.location.hash = hash || '';
  6126. }
  6127. },
  6128. init() {
  6129. const swiper = this;
  6130. if (!swiper.params.hashNavigation.enabled || (swiper.params.history && swiper.params.history.enabled)) return;
  6131. swiper.hashNavigation.initialized = true;
  6132. const hash = document$1.location.hash.replace('#', '');
  6133. if (hash) {
  6134. const speed = 0;
  6135. for (let i = 0, length = swiper.slides.length; i < length; i += 1) {
  6136. const slide = swiper.slides.eq(i);
  6137. const slideHash = slide.attr('data-hash') || slide.attr('data-history');
  6138. if (slideHash === hash && !slide.hasClass(swiper.params.slideDuplicateClass)) {
  6139. const index = slide.index();
  6140. swiper.slideTo(index, speed, swiper.params.runCallbacksOnInit, true);
  6141. }
  6142. }
  6143. }
  6144. if (swiper.params.hashNavigation.watchState) {
  6145. $(window).on('hashchange', swiper.hashNavigation.onHashCange);
  6146. }
  6147. },
  6148. destroy() {
  6149. const swiper = this;
  6150. if (swiper.params.hashNavigation.watchState) {
  6151. $(window).off('hashchange', swiper.hashNavigation.onHashCange);
  6152. }
  6153. },
  6154. };
  6155. var hashNavigation = {
  6156. name: 'hash-navigation',
  6157. params: {
  6158. hashNavigation: {
  6159. enabled: false,
  6160. replaceState: false,
  6161. watchState: false,
  6162. },
  6163. },
  6164. create() {
  6165. const swiper = this;
  6166. Utils.extend(swiper, {
  6167. hashNavigation: {
  6168. initialized: false,
  6169. init: HashNavigation.init.bind(swiper),
  6170. destroy: HashNavigation.destroy.bind(swiper),
  6171. setHash: HashNavigation.setHash.bind(swiper),
  6172. onHashCange: HashNavigation.onHashCange.bind(swiper),
  6173. },
  6174. });
  6175. },
  6176. on: {
  6177. init() {
  6178. const swiper = this;
  6179. if (swiper.params.hashNavigation.enabled) {
  6180. swiper.hashNavigation.init();
  6181. }
  6182. },
  6183. destroy() {
  6184. const swiper = this;
  6185. if (swiper.params.hashNavigation.enabled) {
  6186. swiper.hashNavigation.destroy();
  6187. }
  6188. },
  6189. transitionEnd() {
  6190. const swiper = this;
  6191. if (swiper.hashNavigation.initialized) {
  6192. swiper.hashNavigation.setHash();
  6193. }
  6194. },
  6195. slideChange() {
  6196. const swiper = this;
  6197. if (swiper.hashNavigation.initialized && swiper.params.cssMode) {
  6198. swiper.hashNavigation.setHash();
  6199. }
  6200. },
  6201. },
  6202. };
  6203. /* eslint no-underscore-dangle: "off" */
  6204. const Autoplay = {
  6205. run() {
  6206. const swiper = this;
  6207. const $activeSlideEl = swiper.slides.eq(swiper.activeIndex);
  6208. let delay = swiper.params.autoplay.delay;
  6209. if ($activeSlideEl.attr('data-swiper-autoplay')) {
  6210. delay = $activeSlideEl.attr('data-swiper-autoplay') || swiper.params.autoplay.delay;
  6211. }
  6212. clearTimeout(swiper.autoplay.timeout);
  6213. swiper.autoplay.timeout = Utils.nextTick(() => {
  6214. if (swiper.params.autoplay.reverseDirection) {
  6215. if (swiper.params.loop) {
  6216. swiper.loopFix();
  6217. swiper.slidePrev(swiper.params.speed, true, true);
  6218. swiper.emit('autoplay');
  6219. } else if (!swiper.isBeginning) {
  6220. swiper.slidePrev(swiper.params.speed, true, true);
  6221. swiper.emit('autoplay');
  6222. } else if (!swiper.params.autoplay.stopOnLastSlide) {
  6223. swiper.slideTo(swiper.slides.length - 1, swiper.params.speed, true, true);
  6224. swiper.emit('autoplay');
  6225. } else {
  6226. swiper.autoplay.stop();
  6227. }
  6228. } else if (swiper.params.loop) {
  6229. swiper.loopFix();
  6230. swiper.slideNext(swiper.params.speed, true, true);
  6231. swiper.emit('autoplay');
  6232. } else if (!swiper.isEnd) {
  6233. swiper.slideNext(swiper.params.speed, true, true);
  6234. swiper.emit('autoplay');
  6235. } else if (!swiper.params.autoplay.stopOnLastSlide) {
  6236. swiper.slideTo(0, swiper.params.speed, true, true);
  6237. swiper.emit('autoplay');
  6238. } else {
  6239. swiper.autoplay.stop();
  6240. }
  6241. if (swiper.params.cssMode && swiper.autoplay.running) swiper.autoplay.run();
  6242. }, delay);
  6243. },
  6244. start() {
  6245. const swiper = this;
  6246. if (typeof swiper.autoplay.timeout !== 'undefined') return false;
  6247. if (swiper.autoplay.running) return false;
  6248. swiper.autoplay.running = true;
  6249. swiper.emit('autoplayStart');
  6250. swiper.autoplay.run();
  6251. return true;
  6252. },
  6253. stop() {
  6254. const swiper = this;
  6255. if (!swiper.autoplay.running) return false;
  6256. if (typeof swiper.autoplay.timeout === 'undefined') return false;
  6257. if (swiper.autoplay.timeout) {
  6258. clearTimeout(swiper.autoplay.timeout);
  6259. swiper.autoplay.timeout = undefined;
  6260. }
  6261. swiper.autoplay.running = false;
  6262. swiper.emit('autoplayStop');
  6263. return true;
  6264. },
  6265. pause(speed) {
  6266. const swiper = this;
  6267. if (!swiper.autoplay.running) return;
  6268. if (swiper.autoplay.paused) return;
  6269. if (swiper.autoplay.timeout) clearTimeout(swiper.autoplay.timeout);
  6270. swiper.autoplay.paused = true;
  6271. if (speed === 0 || !swiper.params.autoplay.waitForTransition) {
  6272. swiper.autoplay.paused = false;
  6273. swiper.autoplay.run();
  6274. } else {
  6275. swiper.$wrapperEl[0].addEventListener('transitionend', swiper.autoplay.onTransitionEnd);
  6276. swiper.$wrapperEl[0].addEventListener('webkitTransitionEnd', swiper.autoplay.onTransitionEnd);
  6277. }
  6278. },
  6279. };
  6280. var autoplay = {
  6281. name: 'autoplay',
  6282. params: {
  6283. autoplay: {
  6284. enabled: false,
  6285. delay: 3000,
  6286. waitForTransition: true,
  6287. disableOnInteraction: true,
  6288. stopOnLastSlide: false,
  6289. reverseDirection: false,
  6290. },
  6291. },
  6292. create() {
  6293. const swiper = this;
  6294. Utils.extend(swiper, {
  6295. autoplay: {
  6296. running: false,
  6297. paused: false,
  6298. run: Autoplay.run.bind(swiper),
  6299. start: Autoplay.start.bind(swiper),
  6300. stop: Autoplay.stop.bind(swiper),
  6301. pause: Autoplay.pause.bind(swiper),
  6302. onVisibilityChange() {
  6303. if (document.visibilityState === 'hidden' && swiper.autoplay.running) {
  6304. swiper.autoplay.pause();
  6305. }
  6306. if (document.visibilityState === 'visible' && swiper.autoplay.paused) {
  6307. swiper.autoplay.run();
  6308. swiper.autoplay.paused = false;
  6309. }
  6310. },
  6311. onTransitionEnd(e) {
  6312. if (!swiper || swiper.destroyed || !swiper.$wrapperEl) return;
  6313. if (e.target !== this) return;
  6314. swiper.$wrapperEl[0].removeEventListener('transitionend', swiper.autoplay.onTransitionEnd);
  6315. swiper.$wrapperEl[0].removeEventListener('webkitTransitionEnd', swiper.autoplay.onTransitionEnd);
  6316. swiper.autoplay.paused = false;
  6317. if (!swiper.autoplay.running) {
  6318. swiper.autoplay.stop();
  6319. } else {
  6320. swiper.autoplay.run();
  6321. }
  6322. },
  6323. },
  6324. });
  6325. },
  6326. on: {
  6327. init() {
  6328. const swiper = this;
  6329. if (swiper.params.autoplay.enabled) {
  6330. swiper.autoplay.start();
  6331. document.addEventListener('visibilitychange', swiper.autoplay.onVisibilityChange);
  6332. }
  6333. },
  6334. beforeTransitionStart(speed, internal) {
  6335. const swiper = this;
  6336. if (swiper.autoplay.running) {
  6337. if (internal || !swiper.params.autoplay.disableOnInteraction) {
  6338. swiper.autoplay.pause(speed);
  6339. } else {
  6340. swiper.autoplay.stop();
  6341. }
  6342. }
  6343. },
  6344. sliderFirstMove() {
  6345. const swiper = this;
  6346. if (swiper.autoplay.running) {
  6347. if (swiper.params.autoplay.disableOnInteraction) {
  6348. swiper.autoplay.stop();
  6349. } else {
  6350. swiper.autoplay.pause();
  6351. }
  6352. }
  6353. },
  6354. touchEnd() {
  6355. const swiper = this;
  6356. if (swiper.params.cssMode && swiper.autoplay.paused && !swiper.params.autoplay.disableOnInteraction) {
  6357. swiper.autoplay.run();
  6358. }
  6359. },
  6360. destroy() {
  6361. const swiper = this;
  6362. if (swiper.autoplay.running) {
  6363. swiper.autoplay.stop();
  6364. }
  6365. document.removeEventListener('visibilitychange', swiper.autoplay.onVisibilityChange);
  6366. },
  6367. },
  6368. };
  6369. const Fade = {
  6370. setTranslate() {
  6371. const swiper = this;
  6372. const { slides } = swiper;
  6373. for (let i = 0; i < slides.length; i += 1) {
  6374. const $slideEl = swiper.slides.eq(i);
  6375. const offset = $slideEl[0].swiperSlideOffset;
  6376. let tx = -offset;
  6377. if (!swiper.params.virtualTranslate) tx -= swiper.translate;
  6378. let ty = 0;
  6379. if (!swiper.isHorizontal()) {
  6380. ty = tx;
  6381. tx = 0;
  6382. }
  6383. const slideOpacity = swiper.params.fadeEffect.crossFade
  6384. ? Math.max(1 - Math.abs($slideEl[0].progress), 0)
  6385. : 1 + Math.min(Math.max($slideEl[0].progress, -1), 0);
  6386. $slideEl
  6387. .css({
  6388. opacity: slideOpacity,
  6389. })
  6390. .transform(`translate3d(${tx}px, ${ty}px, 0px)`);
  6391. }
  6392. },
  6393. setTransition(duration) {
  6394. const swiper = this;
  6395. const { slides, $wrapperEl } = swiper;
  6396. slides.transition(duration);
  6397. if (swiper.params.virtualTranslate && duration !== 0) {
  6398. let eventTriggered = false;
  6399. slides.transitionEnd(() => {
  6400. if (eventTriggered) return;
  6401. if (!swiper || swiper.destroyed) return;
  6402. eventTriggered = true;
  6403. swiper.animating = false;
  6404. const triggerEvents = ['webkitTransitionEnd', 'transitionend'];
  6405. for (let i = 0; i < triggerEvents.length; i += 1) {
  6406. $wrapperEl.trigger(triggerEvents[i]);
  6407. }
  6408. });
  6409. }
  6410. },
  6411. };
  6412. var effectFade = {
  6413. name: 'effect-fade',
  6414. params: {
  6415. fadeEffect: {
  6416. crossFade: false,
  6417. },
  6418. },
  6419. create() {
  6420. const swiper = this;
  6421. Utils.extend(swiper, {
  6422. fadeEffect: {
  6423. setTranslate: Fade.setTranslate.bind(swiper),
  6424. setTransition: Fade.setTransition.bind(swiper),
  6425. },
  6426. });
  6427. },
  6428. on: {
  6429. beforeInit() {
  6430. const swiper = this;
  6431. if (swiper.params.effect !== 'fade') return;
  6432. swiper.classNames.push(`${swiper.params.containerModifierClass}fade`);
  6433. const overwriteParams = {
  6434. slidesPerView: 1,
  6435. slidesPerColumn: 1,
  6436. slidesPerGroup: 1,
  6437. watchSlidesProgress: true,
  6438. spaceBetween: 0,
  6439. virtualTranslate: true,
  6440. };
  6441. Utils.extend(swiper.params, overwriteParams);
  6442. Utils.extend(swiper.originalParams, overwriteParams);
  6443. },
  6444. setTranslate() {
  6445. const swiper = this;
  6446. if (swiper.params.effect !== 'fade') return;
  6447. swiper.fadeEffect.setTranslate();
  6448. },
  6449. setTransition(duration) {
  6450. const swiper = this;
  6451. if (swiper.params.effect !== 'fade') return;
  6452. swiper.fadeEffect.setTransition(duration);
  6453. },
  6454. },
  6455. };
  6456. const Cube = {
  6457. setTranslate() {
  6458. const swiper = this;
  6459. const {
  6460. $el, $wrapperEl, slides, width: swiperWidth, height: swiperHeight, rtlTranslate: rtl, size: swiperSize,
  6461. } = swiper;
  6462. const params = swiper.params.cubeEffect;
  6463. const isHorizontal = swiper.isHorizontal();
  6464. const isVirtual = swiper.virtual && swiper.params.virtual.enabled;
  6465. let wrapperRotate = 0;
  6466. let $cubeShadowEl;
  6467. if (params.shadow) {
  6468. if (isHorizontal) {
  6469. $cubeShadowEl = $wrapperEl.find('.swiper-cube-shadow');
  6470. if ($cubeShadowEl.length === 0) {
  6471. $cubeShadowEl = $('<div class="swiper-cube-shadow"></div>');
  6472. $wrapperEl.append($cubeShadowEl);
  6473. }
  6474. $cubeShadowEl.css({ height: `${swiperWidth}px` });
  6475. } else {
  6476. $cubeShadowEl = $el.find('.swiper-cube-shadow');
  6477. if ($cubeShadowEl.length === 0) {
  6478. $cubeShadowEl = $('<div class="swiper-cube-shadow"></div>');
  6479. $el.append($cubeShadowEl);
  6480. }
  6481. }
  6482. }
  6483. for (let i = 0; i < slides.length; i += 1) {
  6484. const $slideEl = slides.eq(i);
  6485. let slideIndex = i;
  6486. if (isVirtual) {
  6487. slideIndex = parseInt($slideEl.attr('data-swiper-slide-index'), 10);
  6488. }
  6489. let slideAngle = slideIndex * 90;
  6490. let round = Math.floor(slideAngle / 360);
  6491. if (rtl) {
  6492. slideAngle = -slideAngle;
  6493. round = Math.floor(-slideAngle / 360);
  6494. }
  6495. const progress = Math.max(Math.min($slideEl[0].progress, 1), -1);
  6496. let tx = 0;
  6497. let ty = 0;
  6498. let tz = 0;
  6499. if (slideIndex % 4 === 0) {
  6500. tx = -round * 4 * swiperSize;
  6501. tz = 0;
  6502. } else if ((slideIndex - 1) % 4 === 0) {
  6503. tx = 0;
  6504. tz = -round * 4 * swiperSize;
  6505. } else if ((slideIndex - 2) % 4 === 0) {
  6506. tx = swiperSize + (round * 4 * swiperSize);
  6507. tz = swiperSize;
  6508. } else if ((slideIndex - 3) % 4 === 0) {
  6509. tx = -swiperSize;
  6510. tz = (3 * swiperSize) + (swiperSize * 4 * round);
  6511. }
  6512. if (rtl) {
  6513. tx = -tx;
  6514. }
  6515. if (!isHorizontal) {
  6516. ty = tx;
  6517. tx = 0;
  6518. }
  6519. const transform = `rotateX(${isHorizontal ? 0 : -slideAngle}deg) rotateY(${isHorizontal ? slideAngle : 0}deg) translate3d(${tx}px, ${ty}px, ${tz}px)`;
  6520. if (progress <= 1 && progress > -1) {
  6521. wrapperRotate = (slideIndex * 90) + (progress * 90);
  6522. if (rtl) wrapperRotate = (-slideIndex * 90) - (progress * 90);
  6523. }
  6524. $slideEl.transform(transform);
  6525. if (params.slideShadows) {
  6526. // Set shadows
  6527. let shadowBefore = isHorizontal ? $slideEl.find('.swiper-slide-shadow-left') : $slideEl.find('.swiper-slide-shadow-top');
  6528. let shadowAfter = isHorizontal ? $slideEl.find('.swiper-slide-shadow-right') : $slideEl.find('.swiper-slide-shadow-bottom');
  6529. if (shadowBefore.length === 0) {
  6530. shadowBefore = $(`<div class="swiper-slide-shadow-${isHorizontal ? 'left' : 'top'}"></div>`);
  6531. $slideEl.append(shadowBefore);
  6532. }
  6533. if (shadowAfter.length === 0) {
  6534. shadowAfter = $(`<div class="swiper-slide-shadow-${isHorizontal ? 'right' : 'bottom'}"></div>`);
  6535. $slideEl.append(shadowAfter);
  6536. }
  6537. if (shadowBefore.length) shadowBefore[0].style.opacity = Math.max(-progress, 0);
  6538. if (shadowAfter.length) shadowAfter[0].style.opacity = Math.max(progress, 0);
  6539. }
  6540. }
  6541. $wrapperEl.css({
  6542. '-webkit-transform-origin': `50% 50% -${swiperSize / 2}px`,
  6543. '-moz-transform-origin': `50% 50% -${swiperSize / 2}px`,
  6544. '-ms-transform-origin': `50% 50% -${swiperSize / 2}px`,
  6545. 'transform-origin': `50% 50% -${swiperSize / 2}px`,
  6546. });
  6547. if (params.shadow) {
  6548. if (isHorizontal) {
  6549. $cubeShadowEl.transform(`translate3d(0px, ${(swiperWidth / 2) + params.shadowOffset}px, ${-swiperWidth / 2}px) rotateX(90deg) rotateZ(0deg) scale(${params.shadowScale})`);
  6550. } else {
  6551. const shadowAngle = Math.abs(wrapperRotate) - (Math.floor(Math.abs(wrapperRotate) / 90) * 90);
  6552. const multiplier = 1.5 - (
  6553. (Math.sin((shadowAngle * 2 * Math.PI) / 360) / 2)
  6554. + (Math.cos((shadowAngle * 2 * Math.PI) / 360) / 2)
  6555. );
  6556. const scale1 = params.shadowScale;
  6557. const scale2 = params.shadowScale / multiplier;
  6558. const offset = params.shadowOffset;
  6559. $cubeShadowEl.transform(`scale3d(${scale1}, 1, ${scale2}) translate3d(0px, ${(swiperHeight / 2) + offset}px, ${-swiperHeight / 2 / scale2}px) rotateX(-90deg)`);
  6560. }
  6561. }
  6562. const zFactor = (Browser.isSafari || Browser.isUiWebView) ? (-swiperSize / 2) : 0;
  6563. $wrapperEl
  6564. .transform(`translate3d(0px,0,${zFactor}px) rotateX(${swiper.isHorizontal() ? 0 : wrapperRotate}deg) rotateY(${swiper.isHorizontal() ? -wrapperRotate : 0}deg)`);
  6565. },
  6566. setTransition(duration) {
  6567. const swiper = this;
  6568. const { $el, slides } = swiper;
  6569. slides
  6570. .transition(duration)
  6571. .find('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left')
  6572. .transition(duration);
  6573. if (swiper.params.cubeEffect.shadow && !swiper.isHorizontal()) {
  6574. $el.find('.swiper-cube-shadow').transition(duration);
  6575. }
  6576. },
  6577. };
  6578. var effectCube = {
  6579. name: 'effect-cube',
  6580. params: {
  6581. cubeEffect: {
  6582. slideShadows: true,
  6583. shadow: true,
  6584. shadowOffset: 20,
  6585. shadowScale: 0.94,
  6586. },
  6587. },
  6588. create() {
  6589. const swiper = this;
  6590. Utils.extend(swiper, {
  6591. cubeEffect: {
  6592. setTranslate: Cube.setTranslate.bind(swiper),
  6593. setTransition: Cube.setTransition.bind(swiper),
  6594. },
  6595. });
  6596. },
  6597. on: {
  6598. beforeInit() {
  6599. const swiper = this;
  6600. if (swiper.params.effect !== 'cube') return;
  6601. swiper.classNames.push(`${swiper.params.containerModifierClass}cube`);
  6602. swiper.classNames.push(`${swiper.params.containerModifierClass}3d`);
  6603. const overwriteParams = {
  6604. slidesPerView: 1,
  6605. slidesPerColumn: 1,
  6606. slidesPerGroup: 1,
  6607. watchSlidesProgress: true,
  6608. resistanceRatio: 0,
  6609. spaceBetween: 0,
  6610. centeredSlides: false,
  6611. virtualTranslate: true,
  6612. };
  6613. Utils.extend(swiper.params, overwriteParams);
  6614. Utils.extend(swiper.originalParams, overwriteParams);
  6615. },
  6616. setTranslate() {
  6617. const swiper = this;
  6618. if (swiper.params.effect !== 'cube') return;
  6619. swiper.cubeEffect.setTranslate();
  6620. },
  6621. setTransition(duration) {
  6622. const swiper = this;
  6623. if (swiper.params.effect !== 'cube') return;
  6624. swiper.cubeEffect.setTransition(duration);
  6625. },
  6626. },
  6627. };
  6628. const Flip = {
  6629. setTranslate() {
  6630. const swiper = this;
  6631. const { slides, rtlTranslate: rtl } = swiper;
  6632. for (let i = 0; i < slides.length; i += 1) {
  6633. const $slideEl = slides.eq(i);
  6634. let progress = $slideEl[0].progress;
  6635. if (swiper.params.flipEffect.limitRotation) {
  6636. progress = Math.max(Math.min($slideEl[0].progress, 1), -1);
  6637. }
  6638. const offset = $slideEl[0].swiperSlideOffset;
  6639. const rotate = -180 * progress;
  6640. let rotateY = rotate;
  6641. let rotateX = 0;
  6642. let tx = -offset;
  6643. let ty = 0;
  6644. if (!swiper.isHorizontal()) {
  6645. ty = tx;
  6646. tx = 0;
  6647. rotateX = -rotateY;
  6648. rotateY = 0;
  6649. } else if (rtl) {
  6650. rotateY = -rotateY;
  6651. }
  6652. $slideEl[0].style.zIndex = -Math.abs(Math.round(progress)) + slides.length;
  6653. if (swiper.params.flipEffect.slideShadows) {
  6654. // Set shadows
  6655. let shadowBefore = swiper.isHorizontal() ? $slideEl.find('.swiper-slide-shadow-left') : $slideEl.find('.swiper-slide-shadow-top');
  6656. let shadowAfter = swiper.isHorizontal() ? $slideEl.find('.swiper-slide-shadow-right') : $slideEl.find('.swiper-slide-shadow-bottom');
  6657. if (shadowBefore.length === 0) {
  6658. shadowBefore = $(`<div class="swiper-slide-shadow-${swiper.isHorizontal() ? 'left' : 'top'}"></div>`);
  6659. $slideEl.append(shadowBefore);
  6660. }
  6661. if (shadowAfter.length === 0) {
  6662. shadowAfter = $(`<div class="swiper-slide-shadow-${swiper.isHorizontal() ? 'right' : 'bottom'}"></div>`);
  6663. $slideEl.append(shadowAfter);
  6664. }
  6665. if (shadowBefore.length) shadowBefore[0].style.opacity = Math.max(-progress, 0);
  6666. if (shadowAfter.length) shadowAfter[0].style.opacity = Math.max(progress, 0);
  6667. }
  6668. $slideEl
  6669. .transform(`translate3d(${tx}px, ${ty}px, 0px) rotateX(${rotateX}deg) rotateY(${rotateY}deg)`);
  6670. }
  6671. },
  6672. setTransition(duration) {
  6673. const swiper = this;
  6674. const { slides, activeIndex, $wrapperEl } = swiper;
  6675. slides
  6676. .transition(duration)
  6677. .find('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left')
  6678. .transition(duration);
  6679. if (swiper.params.virtualTranslate && duration !== 0) {
  6680. let eventTriggered = false;
  6681. // eslint-disable-next-line
  6682. slides.eq(activeIndex).transitionEnd(function onTransitionEnd() {
  6683. if (eventTriggered) return;
  6684. if (!swiper || swiper.destroyed) return;
  6685. // if (!$(this).hasClass(swiper.params.slideActiveClass)) return;
  6686. eventTriggered = true;
  6687. swiper.animating = false;
  6688. const triggerEvents = ['webkitTransitionEnd', 'transitionend'];
  6689. for (let i = 0; i < triggerEvents.length; i += 1) {
  6690. $wrapperEl.trigger(triggerEvents[i]);
  6691. }
  6692. });
  6693. }
  6694. },
  6695. };
  6696. var effectFlip = {
  6697. name: 'effect-flip',
  6698. params: {
  6699. flipEffect: {
  6700. slideShadows: true,
  6701. limitRotation: true,
  6702. },
  6703. },
  6704. create() {
  6705. const swiper = this;
  6706. Utils.extend(swiper, {
  6707. flipEffect: {
  6708. setTranslate: Flip.setTranslate.bind(swiper),
  6709. setTransition: Flip.setTransition.bind(swiper),
  6710. },
  6711. });
  6712. },
  6713. on: {
  6714. beforeInit() {
  6715. const swiper = this;
  6716. if (swiper.params.effect !== 'flip') return;
  6717. swiper.classNames.push(`${swiper.params.containerModifierClass}flip`);
  6718. swiper.classNames.push(`${swiper.params.containerModifierClass}3d`);
  6719. const overwriteParams = {
  6720. slidesPerView: 1,
  6721. slidesPerColumn: 1,
  6722. slidesPerGroup: 1,
  6723. watchSlidesProgress: true,
  6724. spaceBetween: 0,
  6725. virtualTranslate: true,
  6726. };
  6727. Utils.extend(swiper.params, overwriteParams);
  6728. Utils.extend(swiper.originalParams, overwriteParams);
  6729. },
  6730. setTranslate() {
  6731. const swiper = this;
  6732. if (swiper.params.effect !== 'flip') return;
  6733. swiper.flipEffect.setTranslate();
  6734. },
  6735. setTransition(duration) {
  6736. const swiper = this;
  6737. if (swiper.params.effect !== 'flip') return;
  6738. swiper.flipEffect.setTransition(duration);
  6739. },
  6740. },
  6741. };
  6742. const Coverflow = {
  6743. setTranslate() {
  6744. const swiper = this;
  6745. const {
  6746. width: swiperWidth, height: swiperHeight, slides, $wrapperEl, slidesSizesGrid,
  6747. } = swiper;
  6748. const params = swiper.params.coverflowEffect;
  6749. const isHorizontal = swiper.isHorizontal();
  6750. const transform = swiper.translate;
  6751. const center = isHorizontal ? -transform + (swiperWidth / 2) : -transform + (swiperHeight / 2);
  6752. const rotate = isHorizontal ? params.rotate : -params.rotate;
  6753. const translate = params.depth;
  6754. // Each slide offset from center
  6755. for (let i = 0, length = slides.length; i < length; i += 1) {
  6756. const $slideEl = slides.eq(i);
  6757. const slideSize = slidesSizesGrid[i];
  6758. const slideOffset = $slideEl[0].swiperSlideOffset;
  6759. const offsetMultiplier = ((center - slideOffset - (slideSize / 2)) / slideSize) * params.modifier;
  6760. let rotateY = isHorizontal ? rotate * offsetMultiplier : 0;
  6761. let rotateX = isHorizontal ? 0 : rotate * offsetMultiplier;
  6762. // var rotateZ = 0
  6763. let translateZ = -translate * Math.abs(offsetMultiplier);
  6764. let stretch = params.stretch;
  6765. // Allow percentage to make a relative stretch for responsive sliders
  6766. if (typeof stretch === 'string' && stretch.indexOf('%') !== -1) {
  6767. stretch = ((parseFloat(params.stretch) / 100) * slideSize);
  6768. }
  6769. let translateY = isHorizontal ? 0 : stretch * (offsetMultiplier);
  6770. let translateX = isHorizontal ? stretch * (offsetMultiplier) : 0;
  6771. // Fix for ultra small values
  6772. if (Math.abs(translateX) < 0.001) translateX = 0;
  6773. if (Math.abs(translateY) < 0.001) translateY = 0;
  6774. if (Math.abs(translateZ) < 0.001) translateZ = 0;
  6775. if (Math.abs(rotateY) < 0.001) rotateY = 0;
  6776. if (Math.abs(rotateX) < 0.001) rotateX = 0;
  6777. const slideTransform = `translate3d(${translateX}px,${translateY}px,${translateZ}px) rotateX(${rotateX}deg) rotateY(${rotateY}deg)`;
  6778. $slideEl.transform(slideTransform);
  6779. $slideEl[0].style.zIndex = -Math.abs(Math.round(offsetMultiplier)) + 1;
  6780. if (params.slideShadows) {
  6781. // Set shadows
  6782. let $shadowBeforeEl = isHorizontal ? $slideEl.find('.swiper-slide-shadow-left') : $slideEl.find('.swiper-slide-shadow-top');
  6783. let $shadowAfterEl = isHorizontal ? $slideEl.find('.swiper-slide-shadow-right') : $slideEl.find('.swiper-slide-shadow-bottom');
  6784. if ($shadowBeforeEl.length === 0) {
  6785. $shadowBeforeEl = $(`<div class="swiper-slide-shadow-${isHorizontal ? 'left' : 'top'}"></div>`);
  6786. $slideEl.append($shadowBeforeEl);
  6787. }
  6788. if ($shadowAfterEl.length === 0) {
  6789. $shadowAfterEl = $(`<div class="swiper-slide-shadow-${isHorizontal ? 'right' : 'bottom'}"></div>`);
  6790. $slideEl.append($shadowAfterEl);
  6791. }
  6792. if ($shadowBeforeEl.length) $shadowBeforeEl[0].style.opacity = offsetMultiplier > 0 ? offsetMultiplier : 0;
  6793. if ($shadowAfterEl.length) $shadowAfterEl[0].style.opacity = (-offsetMultiplier) > 0 ? -offsetMultiplier : 0;
  6794. }
  6795. }
  6796. // Set correct perspective for IE10
  6797. if (Support.pointerEvents || Support.prefixedPointerEvents) {
  6798. const ws = $wrapperEl[0].style;
  6799. ws.perspectiveOrigin = `${center}px 50%`;
  6800. }
  6801. },
  6802. setTransition(duration) {
  6803. const swiper = this;
  6804. swiper.slides
  6805. .transition(duration)
  6806. .find('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left')
  6807. .transition(duration);
  6808. },
  6809. };
  6810. var effectCoverflow = {
  6811. name: 'effect-coverflow',
  6812. params: {
  6813. coverflowEffect: {
  6814. rotate: 50,
  6815. stretch: 0,
  6816. depth: 100,
  6817. modifier: 1,
  6818. slideShadows: true,
  6819. },
  6820. },
  6821. create() {
  6822. const swiper = this;
  6823. Utils.extend(swiper, {
  6824. coverflowEffect: {
  6825. setTranslate: Coverflow.setTranslate.bind(swiper),
  6826. setTransition: Coverflow.setTransition.bind(swiper),
  6827. },
  6828. });
  6829. },
  6830. on: {
  6831. beforeInit() {
  6832. const swiper = this;
  6833. if (swiper.params.effect !== 'coverflow') return;
  6834. swiper.classNames.push(`${swiper.params.containerModifierClass}coverflow`);
  6835. swiper.classNames.push(`${swiper.params.containerModifierClass}3d`);
  6836. swiper.params.watchSlidesProgress = true;
  6837. swiper.originalParams.watchSlidesProgress = true;
  6838. },
  6839. setTranslate() {
  6840. const swiper = this;
  6841. if (swiper.params.effect !== 'coverflow') return;
  6842. swiper.coverflowEffect.setTranslate();
  6843. },
  6844. setTransition(duration) {
  6845. const swiper = this;
  6846. if (swiper.params.effect !== 'coverflow') return;
  6847. swiper.coverflowEffect.setTransition(duration);
  6848. },
  6849. },
  6850. };
  6851. const Thumbs = {
  6852. init() {
  6853. const swiper = this;
  6854. const { thumbs: thumbsParams } = swiper.params;
  6855. const SwiperClass = swiper.constructor;
  6856. if (thumbsParams.swiper instanceof SwiperClass) {
  6857. swiper.thumbs.swiper = thumbsParams.swiper;
  6858. Utils.extend(swiper.thumbs.swiper.originalParams, {
  6859. watchSlidesProgress: true,
  6860. slideToClickedSlide: false,
  6861. });
  6862. Utils.extend(swiper.thumbs.swiper.params, {
  6863. watchSlidesProgress: true,
  6864. slideToClickedSlide: false,
  6865. });
  6866. } else if (Utils.isObject(thumbsParams.swiper)) {
  6867. swiper.thumbs.swiper = new SwiperClass(Utils.extend({}, thumbsParams.swiper, {
  6868. watchSlidesVisibility: true,
  6869. watchSlidesProgress: true,
  6870. slideToClickedSlide: false,
  6871. }));
  6872. swiper.thumbs.swiperCreated = true;
  6873. }
  6874. swiper.thumbs.swiper.$el.addClass(swiper.params.thumbs.thumbsContainerClass);
  6875. swiper.thumbs.swiper.on('tap', swiper.thumbs.onThumbClick);
  6876. },
  6877. onThumbClick() {
  6878. const swiper = this;
  6879. const thumbsSwiper = swiper.thumbs.swiper;
  6880. if (!thumbsSwiper) return;
  6881. const clickedIndex = thumbsSwiper.clickedIndex;
  6882. const clickedSlide = thumbsSwiper.clickedSlide;
  6883. if (clickedSlide && $(clickedSlide).hasClass(swiper.params.thumbs.slideThumbActiveClass)) return;
  6884. if (typeof clickedIndex === 'undefined' || clickedIndex === null) return;
  6885. let slideToIndex;
  6886. if (thumbsSwiper.params.loop) {
  6887. slideToIndex = parseInt($(thumbsSwiper.clickedSlide).attr('data-swiper-slide-index'), 10);
  6888. } else {
  6889. slideToIndex = clickedIndex;
  6890. }
  6891. if (swiper.params.loop) {
  6892. let currentIndex = swiper.activeIndex;
  6893. if (swiper.slides.eq(currentIndex).hasClass(swiper.params.slideDuplicateClass)) {
  6894. swiper.loopFix();
  6895. // eslint-disable-next-line
  6896. swiper._clientLeft = swiper.$wrapperEl[0].clientLeft;
  6897. currentIndex = swiper.activeIndex;
  6898. }
  6899. const prevIndex = swiper.slides.eq(currentIndex).prevAll(`[data-swiper-slide-index="${slideToIndex}"]`).eq(0).index();
  6900. const nextIndex = swiper.slides.eq(currentIndex).nextAll(`[data-swiper-slide-index="${slideToIndex}"]`).eq(0).index();
  6901. if (typeof prevIndex === 'undefined') slideToIndex = nextIndex;
  6902. else if (typeof nextIndex === 'undefined') slideToIndex = prevIndex;
  6903. else if (nextIndex - currentIndex < currentIndex - prevIndex) slideToIndex = nextIndex;
  6904. else slideToIndex = prevIndex;
  6905. }
  6906. swiper.slideTo(slideToIndex);
  6907. },
  6908. update(initial) {
  6909. const swiper = this;
  6910. const thumbsSwiper = swiper.thumbs.swiper;
  6911. if (!thumbsSwiper) return;
  6912. const slidesPerView = thumbsSwiper.params.slidesPerView === 'auto'
  6913. ? thumbsSwiper.slidesPerViewDynamic()
  6914. : thumbsSwiper.params.slidesPerView;
  6915. if (swiper.realIndex !== thumbsSwiper.realIndex) {
  6916. let currentThumbsIndex = thumbsSwiper.activeIndex;
  6917. let newThumbsIndex;
  6918. if (thumbsSwiper.params.loop) {
  6919. if (thumbsSwiper.slides.eq(currentThumbsIndex).hasClass(thumbsSwiper.params.slideDuplicateClass)) {
  6920. thumbsSwiper.loopFix();
  6921. // eslint-disable-next-line
  6922. thumbsSwiper._clientLeft = thumbsSwiper.$wrapperEl[0].clientLeft;
  6923. currentThumbsIndex = thumbsSwiper.activeIndex;
  6924. }
  6925. // Find actual thumbs index to slide to
  6926. const prevThumbsIndex = thumbsSwiper.slides.eq(currentThumbsIndex).prevAll(`[data-swiper-slide-index="${swiper.realIndex}"]`).eq(0).index();
  6927. const nextThumbsIndex = thumbsSwiper.slides.eq(currentThumbsIndex).nextAll(`[data-swiper-slide-index="${swiper.realIndex}"]`).eq(0).index();
  6928. if (typeof prevThumbsIndex === 'undefined') newThumbsIndex = nextThumbsIndex;
  6929. else if (typeof nextThumbsIndex === 'undefined') newThumbsIndex = prevThumbsIndex;
  6930. else if (nextThumbsIndex - currentThumbsIndex === currentThumbsIndex - prevThumbsIndex) newThumbsIndex = currentThumbsIndex;
  6931. else if (nextThumbsIndex - currentThumbsIndex < currentThumbsIndex - prevThumbsIndex) newThumbsIndex = nextThumbsIndex;
  6932. else newThumbsIndex = prevThumbsIndex;
  6933. } else {
  6934. newThumbsIndex = swiper.realIndex;
  6935. }
  6936. if (thumbsSwiper.visibleSlidesIndexes && thumbsSwiper.visibleSlidesIndexes.indexOf(newThumbsIndex) < 0) {
  6937. if (thumbsSwiper.params.centeredSlides) {
  6938. if (newThumbsIndex > currentThumbsIndex) {
  6939. newThumbsIndex = newThumbsIndex - Math.floor(slidesPerView / 2) + 1;
  6940. } else {
  6941. newThumbsIndex = newThumbsIndex + Math.floor(slidesPerView / 2) - 1;
  6942. }
  6943. } else if (newThumbsIndex > currentThumbsIndex) {
  6944. newThumbsIndex = newThumbsIndex - slidesPerView + 1;
  6945. }
  6946. thumbsSwiper.slideTo(newThumbsIndex, initial ? 0 : undefined);
  6947. }
  6948. }
  6949. // Activate thumbs
  6950. let thumbsToActivate = 1;
  6951. const thumbActiveClass = swiper.params.thumbs.slideThumbActiveClass;
  6952. if (swiper.params.slidesPerView > 1 && !swiper.params.centeredSlides) {
  6953. thumbsToActivate = swiper.params.slidesPerView;
  6954. }
  6955. if (!swiper.params.thumbs.multipleActiveThumbs) {
  6956. thumbsToActivate = 1;
  6957. }
  6958. thumbsToActivate = Math.floor(thumbsToActivate);
  6959. thumbsSwiper.slides.removeClass(thumbActiveClass);
  6960. if (thumbsSwiper.params.loop || (thumbsSwiper.params.virtual && thumbsSwiper.params.virtual.enabled)) {
  6961. for (let i = 0; i < thumbsToActivate; i += 1) {
  6962. thumbsSwiper.$wrapperEl.children(`[data-swiper-slide-index="${swiper.realIndex + i}"]`).addClass(thumbActiveClass);
  6963. }
  6964. } else {
  6965. for (let i = 0; i < thumbsToActivate; i += 1) {
  6966. thumbsSwiper.slides.eq(swiper.realIndex + i).addClass(thumbActiveClass);
  6967. }
  6968. }
  6969. },
  6970. };
  6971. var thumbs = {
  6972. name: 'thumbs',
  6973. params: {
  6974. thumbs: {
  6975. multipleActiveThumbs: true,
  6976. swiper: null,
  6977. slideThumbActiveClass: 'swiper-slide-thumb-active',
  6978. thumbsContainerClass: 'swiper-container-thumbs',
  6979. },
  6980. },
  6981. create() {
  6982. const swiper = this;
  6983. Utils.extend(swiper, {
  6984. thumbs: {
  6985. swiper: null,
  6986. init: Thumbs.init.bind(swiper),
  6987. update: Thumbs.update.bind(swiper),
  6988. onThumbClick: Thumbs.onThumbClick.bind(swiper),
  6989. },
  6990. });
  6991. },
  6992. on: {
  6993. beforeInit() {
  6994. const swiper = this;
  6995. const { thumbs } = swiper.params;
  6996. if (!thumbs || !thumbs.swiper) return;
  6997. swiper.thumbs.init();
  6998. swiper.thumbs.update(true);
  6999. },
  7000. slideChange() {
  7001. const swiper = this;
  7002. if (!swiper.thumbs.swiper) return;
  7003. swiper.thumbs.update();
  7004. },
  7005. update() {
  7006. const swiper = this;
  7007. if (!swiper.thumbs.swiper) return;
  7008. swiper.thumbs.update();
  7009. },
  7010. resize() {
  7011. const swiper = this;
  7012. if (!swiper.thumbs.swiper) return;
  7013. swiper.thumbs.update();
  7014. },
  7015. observerUpdate() {
  7016. const swiper = this;
  7017. if (!swiper.thumbs.swiper) return;
  7018. swiper.thumbs.update();
  7019. },
  7020. setTransition(duration) {
  7021. const swiper = this;
  7022. const thumbsSwiper = swiper.thumbs.swiper;
  7023. if (!thumbsSwiper) return;
  7024. thumbsSwiper.setTransition(duration);
  7025. },
  7026. beforeDestroy() {
  7027. const swiper = this;
  7028. const thumbsSwiper = swiper.thumbs.swiper;
  7029. if (!thumbsSwiper) return;
  7030. if (swiper.thumbs.swiperCreated && thumbsSwiper) {
  7031. thumbsSwiper.destroy();
  7032. }
  7033. },
  7034. },
  7035. };
  7036. // Swiper Class
  7037. const components = [
  7038. Device$1,
  7039. Support$1,
  7040. Browser$1,
  7041. Resize,
  7042. Observer$1,
  7043. ];
  7044. if (typeof Swiper.use === 'undefined') {
  7045. Swiper.use = Swiper.Class.use;
  7046. Swiper.installModule = Swiper.Class.installModule;
  7047. }
  7048. Swiper.use(components);
  7049. export { a11y$1 as A11y, autoplay as Autoplay, controller as Controller, effectCoverflow as EffectCoverflow, effectCube as EffectCube, effectFade as EffectFade, effectFlip as EffectFlip, hashNavigation as HashNavigation, history as History, keyboard as Keyboard, lazy as Lazy, mousewheel as Mousewheel, navigation as Navigation, pagination as Pagination, parallax as Parallax, scrollbar as Scrollbar, Swiper, thumbs as Thumbs, virtual as Virtual, zoom as Zoom };
  7050. //# sourceMappingURL=swiper.esm.js.map