swiper.esm.js 225 KB

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