swiper-bundle.js 313 KB

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