swiper.esm.js 248 KB

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