swiper.esm.bundle.js 224 KB

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