splide.js 133 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757
  1. /*!
  2. * Splide.js
  3. * Version : 2.2.3
  4. * License : MIT
  5. * Copyright: 2020 Naotoshi Fujita
  6. */
  7. (function webpackUniversalModuleDefinition(root, factory) {
  8. if(typeof exports === 'object' && typeof module === 'object')
  9. module.exports = factory();
  10. else if(typeof define === 'function' && define.amd)
  11. define([], factory);
  12. else if(typeof exports === 'object')
  13. exports["Splide"] = factory();
  14. else
  15. root["Splide"] = factory();
  16. })(window, function() {
  17. return /******/ (function(modules) { // webpackBootstrap
  18. /******/ // The module cache
  19. /******/ var installedModules = {};
  20. /******/
  21. /******/ // The require function
  22. /******/ function __webpack_require__(moduleId) {
  23. /******/
  24. /******/ // Check if module is in cache
  25. /******/ if(installedModules[moduleId]) {
  26. /******/ return installedModules[moduleId].exports;
  27. /******/ }
  28. /******/ // Create a new module (and put it into the cache)
  29. /******/ var module = installedModules[moduleId] = {
  30. /******/ i: moduleId,
  31. /******/ l: false,
  32. /******/ exports: {}
  33. /******/ };
  34. /******/
  35. /******/ // Execute the module function
  36. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  37. /******/
  38. /******/ // Flag the module as loaded
  39. /******/ module.l = true;
  40. /******/
  41. /******/ // Return the exports of the module
  42. /******/ return module.exports;
  43. /******/ }
  44. /******/
  45. /******/
  46. /******/ // expose the modules object (__webpack_modules__)
  47. /******/ __webpack_require__.m = modules;
  48. /******/
  49. /******/ // expose the module cache
  50. /******/ __webpack_require__.c = installedModules;
  51. /******/
  52. /******/ // define getter function for harmony exports
  53. /******/ __webpack_require__.d = function(exports, name, getter) {
  54. /******/ if(!__webpack_require__.o(exports, name)) {
  55. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  56. /******/ }
  57. /******/ };
  58. /******/
  59. /******/ // define __esModule on exports
  60. /******/ __webpack_require__.r = function(exports) {
  61. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  62. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  63. /******/ }
  64. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  65. /******/ };
  66. /******/
  67. /******/ // create a fake namespace object
  68. /******/ // mode & 1: value is a module id, require it
  69. /******/ // mode & 2: merge all properties of value into the ns
  70. /******/ // mode & 4: return value when already ns object
  71. /******/ // mode & 8|1: behave like require
  72. /******/ __webpack_require__.t = function(value, mode) {
  73. /******/ if(mode & 1) value = __webpack_require__(value);
  74. /******/ if(mode & 8) return value;
  75. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  76. /******/ var ns = Object.create(null);
  77. /******/ __webpack_require__.r(ns);
  78. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  79. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  80. /******/ return ns;
  81. /******/ };
  82. /******/
  83. /******/ // getDefaultExport function for compatibility with non-harmony modules
  84. /******/ __webpack_require__.n = function(module) {
  85. /******/ var getter = module && module.__esModule ?
  86. /******/ function getDefault() { return module['default']; } :
  87. /******/ function getModuleExports() { return module; };
  88. /******/ __webpack_require__.d(getter, 'a', getter);
  89. /******/ return getter;
  90. /******/ };
  91. /******/
  92. /******/ // Object.prototype.hasOwnProperty.call
  93. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  94. /******/
  95. /******/ // __webpack_public_path__
  96. /******/ __webpack_require__.p = "";
  97. /******/
  98. /******/
  99. /******/ // Load entry module and return exports
  100. /******/ return __webpack_require__(__webpack_require__.s = 0);
  101. /******/ })
  102. /************************************************************************/
  103. /******/ ([
  104. /* 0 */
  105. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  106. "use strict";
  107. // ESM COMPAT FLAG
  108. __webpack_require__.r(__webpack_exports__);
  109. // EXPORTS
  110. __webpack_require__.d(__webpack_exports__, "default", function() { return /* binding */ module_Splide; });
  111. // NAMESPACE OBJECT: ./src/js/constants/states.js
  112. var states_namespaceObject = {};
  113. __webpack_require__.r(states_namespaceObject);
  114. __webpack_require__.d(states_namespaceObject, "CREATED", function() { return CREATED; });
  115. __webpack_require__.d(states_namespaceObject, "MOUNTED", function() { return MOUNTED; });
  116. __webpack_require__.d(states_namespaceObject, "IDLE", function() { return IDLE; });
  117. __webpack_require__.d(states_namespaceObject, "MOVING", function() { return MOVING; });
  118. __webpack_require__.d(states_namespaceObject, "DESTROYED", function() { return DESTROYED; });
  119. // CONCATENATED MODULE: ./src/js/core/event.js
  120. /**
  121. * The function for providing an Event object simply managing events.
  122. *
  123. * @author Naotoshi Fujita
  124. * @copyright Naotoshi Fujita. All rights reserved.
  125. */
  126. /**
  127. * The function for providing an Event object simply managing events.
  128. */
  129. /* harmony default export */ var core_event = (function () {
  130. /**
  131. * Store all event data.
  132. *
  133. * @type {Array}
  134. */
  135. var data = [];
  136. var Event = {
  137. /**
  138. * Subscribe the given event(s).
  139. *
  140. * @param {string} events - An event name. Use space to separate multiple events.
  141. * Also, namespace is accepted by dot, such as 'resize.{namespace}'.
  142. * @param {function} handler - A callback function.
  143. * @param {Element} elm - Optional. Native event will be listened to when this arg is provided.
  144. * @param {Object} options - Optional. Options for addEventListener.
  145. */
  146. on: function on(events, handler, elm, options) {
  147. if (elm === void 0) {
  148. elm = null;
  149. }
  150. if (options === void 0) {
  151. options = {};
  152. }
  153. events.split(' ').forEach(function (event) {
  154. if (elm) {
  155. elm.addEventListener(event, handler, options);
  156. }
  157. data.push({
  158. event: event,
  159. handler: handler,
  160. elm: elm,
  161. options: options
  162. });
  163. });
  164. },
  165. /**
  166. * Unsubscribe the given event(s).
  167. *
  168. * @param {string} events - A event name or names split by space.
  169. * @param {Element} elm - Optional. removeEventListener() will be called when this arg is provided.
  170. */
  171. off: function off(events, elm) {
  172. if (elm === void 0) {
  173. elm = null;
  174. }
  175. events.split(' ').forEach(function (event) {
  176. data = data.filter(function (item) {
  177. if (item && item.event === event && item.elm === elm) {
  178. unsubscribe(item);
  179. return false;
  180. }
  181. return true;
  182. });
  183. });
  184. },
  185. /**
  186. * Emit an event.
  187. * This method is only for custom events.
  188. *
  189. * @param {string} event - An event name.
  190. * @param {*} args - Any number of arguments passed to handlers.
  191. */
  192. emit: function emit(event) {
  193. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  194. args[_key - 1] = arguments[_key];
  195. }
  196. data.forEach(function (item) {
  197. if (!item.elm && item.event.split('.')[0] === event) {
  198. item.handler.apply(item, args);
  199. }
  200. });
  201. },
  202. /**
  203. * Clear event data.
  204. */
  205. destroy: function destroy() {
  206. data.forEach(unsubscribe);
  207. data = [];
  208. }
  209. };
  210. /**
  211. * Remove the registered event listener.
  212. *
  213. * @param {Object} item - An object containing event data.
  214. */
  215. function unsubscribe(item) {
  216. if (item.elm) {
  217. item.elm.removeEventListener(item.event, item.handler, item.options);
  218. }
  219. }
  220. return Event;
  221. });
  222. // CONCATENATED MODULE: ./src/js/core/state.js
  223. /**
  224. * The function providing a super simple state system.
  225. *
  226. * @author Naotoshi Fujita
  227. * @copyright Naotoshi Fujita. All rights reserved.
  228. */
  229. /**
  230. * The function providing a super simple state system.
  231. *
  232. * @param {string|number} initialState - Provide the initial state value.
  233. */
  234. /* harmony default export */ var state = (function (initialState) {
  235. /**
  236. * Store the current state.
  237. *
  238. * @type {string|number}
  239. */
  240. var curr = initialState;
  241. return {
  242. /**
  243. * Change state.
  244. *
  245. * @param {string|number} state - A new state.
  246. */
  247. set: function set(state) {
  248. curr = state;
  249. },
  250. /**
  251. * Verify if the current state is given one or not.
  252. *
  253. * @param {string|number} state - A state name to be verified.
  254. *
  255. * @return {boolean} - True if the current state is the given one.
  256. */
  257. is: function is(state) {
  258. return state === curr;
  259. }
  260. };
  261. });
  262. // CONCATENATED MODULE: ./src/js/constants/classes.js
  263. /**
  264. * Export class names.
  265. *
  266. * @author Naotoshi Fujita
  267. * @copyright Naotoshi Fujita. All rights reserved.
  268. */
  269. /**
  270. * A root class name.
  271. *
  272. * @type {string}
  273. */
  274. var ROOT = 'splide';
  275. /**
  276. * The definition table of all classes for elements.
  277. * They might be modified by options.
  278. *
  279. * @type {Object}
  280. */
  281. var ELEMENT_CLASSES = {
  282. root: ROOT,
  283. slider: ROOT + "__slider",
  284. track: ROOT + "__track",
  285. list: ROOT + "__list",
  286. slide: ROOT + "__slide",
  287. container: ROOT + "__slide__container",
  288. arrows: ROOT + "__arrows",
  289. arrow: ROOT + "__arrow",
  290. prev: ROOT + "__arrow--prev",
  291. next: ROOT + "__arrow--next",
  292. pagination: ROOT + "__pagination",
  293. page: ROOT + "__pagination__page",
  294. clone: ROOT + "__slide--clone",
  295. progress: ROOT + "__progress",
  296. bar: ROOT + "__progress__bar",
  297. autoplay: ROOT + "__autoplay",
  298. play: ROOT + "__play",
  299. pause: ROOT + "__pause",
  300. spinner: ROOT + "__spinner",
  301. sr: ROOT + "__sr"
  302. };
  303. /**
  304. * Definitions of status classes.
  305. *
  306. * @type {Object}
  307. */
  308. var STATUS_CLASSES = {
  309. active: 'is-active',
  310. visible: 'is-visible',
  311. loading: 'is-loading'
  312. };
  313. // CONCATENATED MODULE: ./src/js/constants/i18n.js
  314. /**
  315. * Export i18n texts as object.
  316. *
  317. * @author Naotoshi Fujita
  318. * @copyright Naotoshi Fujita. All rights reserved.
  319. */
  320. /**
  321. * Texts for i18n.
  322. *
  323. * @type {Object}
  324. */
  325. var I18N = {
  326. prev: 'Previous slide',
  327. next: 'Next slide',
  328. first: 'Go to first slide',
  329. last: 'Go to last slide',
  330. slideX: 'Go to slide %s',
  331. pageX: 'Go to page %s',
  332. play: 'Start autoplay',
  333. pause: 'Pause autoplay'
  334. };
  335. // CONCATENATED MODULE: ./src/js/constants/defaults.js
  336. /**
  337. * Export default options.
  338. *
  339. * @author Naotoshi Fujita
  340. * @copyright Naotoshi Fujita. All rights reserved.
  341. */
  342. var DEFAULTS = {
  343. /**
  344. * Determine a slider type.
  345. * - 'slide': Regular slider.
  346. * - 'loop' : Carousel slider.
  347. * - 'fade' : Change slides with fade transition. perPage, drag options are ignored.
  348. *
  349. * @type {string}
  350. */
  351. type: 'slide',
  352. /**
  353. * Whether to rewind a slider before the first slide or after the last one.
  354. * In "loop" mode, this option is ignored.
  355. *
  356. * @type {boolean}
  357. */
  358. rewind: false,
  359. /**
  360. * Transition speed in milliseconds.
  361. *
  362. * @type {number}
  363. */
  364. speed: 400,
  365. /**
  366. * Transition speed on rewind in milliseconds.
  367. *
  368. * @type {number}
  369. */
  370. rewindSpeed: 0,
  371. /**
  372. * Define slider max width.
  373. *
  374. * @type {number}
  375. */
  376. width: 0,
  377. /**
  378. * Define slider height.
  379. *
  380. * @type {number}
  381. */
  382. height: 0,
  383. /**
  384. * Fix width of slides. CSS format is allowed such as 10em, 80% or 80vw.
  385. * perPage number will be ignored when this option is falsy.
  386. *
  387. * @type {number|string}
  388. */
  389. fixedWidth: 0,
  390. /**
  391. * Fix height of slides. CSS format is allowed such as 10em, 80vh but % unit is not accepted.
  392. * heightRatio option will be ignored when this option is falsy.
  393. *
  394. * @type {number}
  395. */
  396. fixedHeight: 0,
  397. /**
  398. * Determine height of slides by ratio to a slider width.
  399. * This will be ignored when the fixedHeight is provided.
  400. *
  401. * @type {number}
  402. */
  403. heightRatio: 0,
  404. /**
  405. * If true, slide width will be determined by the element width itself.
  406. * - perPage/perMove should be 1.
  407. * - lazyLoad should be false.
  408. *
  409. * @type {boolean}
  410. */
  411. autoWidth: false,
  412. /**
  413. * Determine how many slides should be displayed per page.
  414. *
  415. * @type {number}
  416. */
  417. perPage: 1,
  418. /**
  419. * Determine how many slides should be moved when a slider goes to next or perv.
  420. *
  421. * @type {number}
  422. */
  423. perMove: 0,
  424. /**
  425. * Start index.
  426. *
  427. * @type {number}
  428. */
  429. start: 0,
  430. /**
  431. * Determine which slide should be focused if there are multiple slides in a page.
  432. * A string "center" is acceptable for centering slides.
  433. *
  434. * @type {boolean|number|string}
  435. */
  436. focus: false,
  437. /**
  438. * Gap between slides. CSS format is allowed such as 1em.
  439. *
  440. * @type {number|string}
  441. */
  442. gap: 0,
  443. /**
  444. * Set padding-left/right in horizontal mode or padding-top/bottom in vertical one.
  445. * Give a single value to set a same size for both sides or
  446. * do an object for different sizes.
  447. * Also, CSS format is allowed such as 1em.
  448. *
  449. * @example
  450. * - 10: Number
  451. * - '1em': CSS format.
  452. * - { left: 0, right: 20 }: Object for different sizes in horizontal mode.
  453. * - { top: 0, bottom: 20 }: Object for different sizes in vertical mode.
  454. *
  455. * @type {number|string|Object}
  456. */
  457. padding: 0,
  458. /**
  459. * Whether to append arrows.
  460. *
  461. * @type {boolean}
  462. */
  463. arrows: true,
  464. /**
  465. * Change the arrow SVG path like 'm7.61 0.807-2.12...'.
  466. *
  467. * @type {string}
  468. */
  469. arrowPath: '',
  470. /**
  471. * Whether to append pagination(indicator dots) or not.
  472. *
  473. * @type {boolean}
  474. */
  475. pagination: true,
  476. /**
  477. * Activate autoplay.
  478. *
  479. * @type {boolean}
  480. */
  481. autoplay: false,
  482. /**
  483. * Autoplay interval in milliseconds.
  484. *
  485. * @type {number}
  486. */
  487. interval: 5000,
  488. /**
  489. * Whether to stop autoplay when a slider is hovered.
  490. *
  491. * @type {boolean}
  492. */
  493. pauseOnHover: true,
  494. /**
  495. * Whether to stop autoplay when a slider elements are focused.
  496. * True is recommended for accessibility.
  497. *
  498. * @type {boolean}
  499. */
  500. pauseOnFocus: true,
  501. /**
  502. * Loading images lazily.
  503. * Image src must be provided by a data-splide-lazy attribute.
  504. *
  505. * - false: Do nothing.
  506. * - 'nearby': Only images around an active slide will be loaded.
  507. * - 'sequential': All images will be sequentially loaded.
  508. *
  509. * @type {boolean|string}
  510. */
  511. lazyLoad: false,
  512. /**
  513. * This option works only when a lazyLoad option is "nearby".
  514. * Determine how many pages(not slides) around an active slide should be loaded beforehand.
  515. *
  516. * @type {number}
  517. */
  518. preloadPages: 1,
  519. /**
  520. * Easing for CSS transition. For example, linear, ease or cubic-bezier().
  521. *
  522. * @type {string}
  523. */
  524. easing: 'cubic-bezier(.42,.65,.27,.99)',
  525. /**
  526. * Whether to control a slide via keyboard.
  527. *
  528. * @type {boolean}
  529. */
  530. keyboard: true,
  531. /**
  532. * Whether to allow mouse drag and touch swipe.
  533. *
  534. * @type {boolean}
  535. */
  536. drag: true,
  537. /**
  538. * Threshold for determining if the action is "flick" or "swipe".
  539. * Around 0.5 is recommended.
  540. *
  541. * @type {number}
  542. */
  543. flickThreshold: .6,
  544. /**
  545. * Determine power of flick. The larger number this is, the farther a slider runs by flick.
  546. * Around 500 is recommended.
  547. *
  548. * @type {number}
  549. */
  550. flickPower: 600,
  551. /**
  552. * Limit a number of pages to move by flick.
  553. *
  554. * @type {number}
  555. */
  556. flickMaxPages: 1,
  557. /**
  558. * Slider direction.
  559. * - 'ltr': Left to right.
  560. * - 'rtl': Right to left.
  561. * - 'ttb': Top to bottom.
  562. *
  563. * @type {string}
  564. */
  565. direction: 'ltr',
  566. /**
  567. * Set img src to background-image of its parent element.
  568. * Images with various sizes can be displayed as same dimension without cropping work.
  569. * fixedHeight or heightRatio is required.
  570. *
  571. * @type {boolean}
  572. */
  573. cover: false,
  574. /**
  575. * Whether to enable accessibility(aria and screen reader texts) or not.
  576. *
  577. * @type {boolean}
  578. */
  579. accessibility: true,
  580. /**
  581. * Determine if a slider is navigation for another.
  582. * Use "sync" API to synchronize two sliders.
  583. *
  584. * @type {boolean}
  585. */
  586. isNavigation: false,
  587. /**
  588. * Whether to trim spaces before the fist slide or after the last one when "focus" is not 0.
  589. *
  590. * @type {boolean}
  591. */
  592. trimSpace: true,
  593. /**
  594. * Slide status is updated after move as default.
  595. * If true, it will be updated before move.
  596. *
  597. * @type {boolean}
  598. */
  599. updateOnMove: false,
  600. /**
  601. * Breakpoints definitions.
  602. *
  603. * @example
  604. * {
  605. * '1000': {
  606. * perPage: 3,
  607. * gap: 20
  608. * },
  609. * '600': {
  610. * perPage: 1,
  611. * gap: 5,
  612. * }
  613. * }
  614. *
  615. * @type {boolean|Object}
  616. */
  617. breakpoints: false,
  618. /**
  619. * Collection of class names.
  620. *
  621. * @see ./classes.js
  622. *
  623. * @type {Object}
  624. */
  625. classes: ELEMENT_CLASSES,
  626. /**
  627. * Collection of i18n texts.
  628. *
  629. * @see ./i18n.js
  630. *
  631. * @type {Object}
  632. */
  633. i18n: I18N
  634. };
  635. // CONCATENATED MODULE: ./src/js/utils/object.js
  636. function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
  637. /**
  638. * Some utility functions related with Object, supporting IE.
  639. *
  640. * @author Naotoshi Fujita
  641. * @copyright Naotoshi Fujita. All rights reserved.
  642. */
  643. /**
  644. * Iterate an object like Array.forEach.
  645. * IE doesn't support forEach of HTMLCollection.
  646. *
  647. * @param {Object} obj - An object.
  648. * @param {function} callback - A function handling each value. Arguments are value, property and index.
  649. */
  650. function each(obj, callback) {
  651. Object.keys(obj).some(function (key, index) {
  652. return callback(obj[key], key, index);
  653. });
  654. }
  655. /**
  656. * Return values of the given object as an array.
  657. * IE doesn't support Object.values.
  658. *
  659. * @param {Object} obj - An object.
  660. *
  661. * @return {Array} - An array containing all values of the given object.
  662. */
  663. function values(obj) {
  664. return Object.keys(obj).map(function (key) {
  665. return obj[key];
  666. });
  667. }
  668. /**
  669. * Check if the given subject is object or not.
  670. *
  671. * @param {*} subject - A subject to be verified.
  672. *
  673. * @return {boolean} - True if object, false otherwise.
  674. */
  675. function isObject(subject) {
  676. return typeof subject === 'object';
  677. }
  678. /**
  679. * Merge two objects deeply.
  680. *
  681. * @param {Object} to - An object where "from" is merged.
  682. * @param {Object} from - An object merged to "to".
  683. *
  684. * @return {Object} - A merged object.
  685. */
  686. function merge(_ref, from) {
  687. var to = _extends({}, _ref);
  688. each(from, function (value, key) {
  689. if (isObject(value)) {
  690. if (!isObject(to[key])) {
  691. to[key] = {};
  692. }
  693. to[key] = merge(to[key], value);
  694. } else {
  695. to[key] = value;
  696. }
  697. });
  698. return to;
  699. }
  700. /**
  701. * Assign all properties "from" to "to" object.
  702. *
  703. * @param {Object} to - An object where properties are assigned.
  704. * @param {Object} from - An object whose properties are assigned to "to".
  705. *
  706. * @return {Object} - An assigned object.
  707. */
  708. function object_assign(to, from) {
  709. to._s = from;
  710. Object.keys(from).forEach(function (key) {
  711. if (!to[key]) {
  712. Object.defineProperty(to, key, Object.getOwnPropertyDescriptor(from, key));
  713. }
  714. });
  715. return to;
  716. }
  717. // CONCATENATED MODULE: ./src/js/utils/utils.js
  718. /**
  719. * A package of some miscellaneous utility functions.
  720. *
  721. * @author Naotoshi Fujita
  722. * @copyright Naotoshi Fujita. All rights reserved.
  723. */
  724. /**
  725. * Convert the given value to array.
  726. *
  727. * @param {*} value - Any value.
  728. *
  729. * @return {*[]} - Array containing the given value.
  730. */
  731. function toArray(value) {
  732. return Array.isArray(value) ? value : [value];
  733. }
  734. /**
  735. * Check if the given value is between min and max.
  736. * Min will be returned when the value is less than min or max will do when greater than max.
  737. *
  738. * @param {number} value - A number to be checked.
  739. * @param {number} m1 - Minimum or maximum number.
  740. * @param {number} m2 - Maximum or minimum number.
  741. *
  742. * @return {number} - A value itself, min or max.
  743. */
  744. function between(value, m1, m2) {
  745. return Math.min(Math.max(value, m1 > m2 ? m2 : m1), m1 > m2 ? m1 : m2);
  746. }
  747. /**
  748. * The sprintf method with minimum functionality.
  749. *
  750. * @param {string} format - The string format.
  751. * @param {string|Array} replacements - Replacements accepting multiple arguments.
  752. *
  753. * @returns {string} - Converted string.
  754. */
  755. function sprintf(format, replacements) {
  756. var i = 0;
  757. return format.replace(/%s/g, function () {
  758. return toArray(replacements)[i++];
  759. });
  760. }
  761. /**
  762. * Append px unit to the given subject if necessary.
  763. *
  764. * @param {number|string} value - A value that may not include an unit.
  765. *
  766. * @return {string} - If the value is string, return itself.
  767. * If number, do value + "px". An empty string, otherwise.
  768. */
  769. function unit(value) {
  770. var type = typeof value;
  771. if (type === 'number' && value > 0) {
  772. return parseFloat(value) + 'px';
  773. }
  774. return type === 'string' ? value : '';
  775. }
  776. /**
  777. * Pad start with 0.
  778. *
  779. * @param {number} number - A number to be filled with 0.
  780. *
  781. * @return {string|number} - Padded number.
  782. */
  783. function pad(number) {
  784. return number < 10 ? '0' + number : number;
  785. }
  786. /**
  787. * Convert the given value to pixel.
  788. *
  789. * @param {Element} root - Root element where a dummy div is appended.
  790. * @param {string|number} value - CSS value to be converted, such as 10rem.
  791. *
  792. * @return {number} - Pixel.
  793. */
  794. function toPixel(root, value) {
  795. if (typeof value === 'string') {
  796. var div = create('div', {});
  797. applyStyle(div, {
  798. position: 'absolute',
  799. width: value
  800. });
  801. append(root, div);
  802. value = div.clientWidth;
  803. dom_remove(div);
  804. }
  805. return value;
  806. }
  807. // CONCATENATED MODULE: ./src/js/utils/dom.js
  808. /**
  809. * Some utility functions related with DOM.
  810. *
  811. * @author Naotoshi Fujita
  812. * @copyright Naotoshi Fujita. All rights reserved.
  813. */
  814. /**
  815. * Find the first element matching the given selector.
  816. * Be aware that all selectors after a space are ignored.
  817. *
  818. * @param {Element|Node} elm - An ancestor element.
  819. * @param {string} selector - DOMString.
  820. *
  821. * @return {Element|null} - A found element or null.
  822. */
  823. function find(elm, selector) {
  824. return elm ? elm.querySelector(selector.split(' ')[0]) : null;
  825. }
  826. /**
  827. * Find a first child having the given tag or class name.
  828. *
  829. * @param {Element} parent - A parent element.
  830. * @param {string} tagOrClassName - A tag or class name.
  831. *
  832. * @return {Element|null} - A found element on success. Null on failure.
  833. */
  834. function child(parent, tagOrClassName) {
  835. if (parent) {
  836. return values(parent.children).filter(function (child) {
  837. return hasClass(child, tagOrClassName.split(' ')[0]) || child.tagName.toLowerCase() === tagOrClassName;
  838. })[0] || null;
  839. }
  840. return null;
  841. }
  842. /**
  843. * Create an element with some optional attributes.
  844. *
  845. * @param {string} tag - A tag name.
  846. * @param {Object} attrs - An object any attribute pairs of name and value.
  847. *
  848. * @return {Element} - A created element.
  849. */
  850. function create(tag, attrs) {
  851. var elm = document.createElement(tag);
  852. each(attrs, function (value, key) {
  853. return setAttribute(elm, key, value);
  854. });
  855. return elm;
  856. }
  857. /**
  858. * Convert HTML string to DOM node.
  859. *
  860. * @param {string} html - HTML string.
  861. *
  862. * @return {Node} - A created node.
  863. */
  864. function domify(html) {
  865. var div = create('div', {});
  866. div.innerHTML = html;
  867. return div.firstChild;
  868. }
  869. /**
  870. * Remove a given element from a DOM tree.
  871. *
  872. * @param {Element|Element[]} elms - Element(s) to be removed.
  873. */
  874. function dom_remove(elms) {
  875. toArray(elms).forEach(function (elm) {
  876. if (elm && elm.parentElement) {
  877. elm.parentElement.removeChild(elm);
  878. }
  879. });
  880. }
  881. /**
  882. * Append a child to a given element.
  883. *
  884. * @param {Element} parent - A parent element.
  885. * @param {Element} child - An element to be appended.
  886. */
  887. function append(parent, child) {
  888. if (parent) {
  889. parent.appendChild(child);
  890. }
  891. }
  892. /**
  893. * Insert an element before the reference element.
  894. *
  895. * @param {Element|Node} ref - A reference element.
  896. * @param {Element} elm - An element to be inserted.
  897. */
  898. function before(elm, ref) {
  899. if (elm && ref && ref.parentElement) {
  900. ref.parentElement.insertBefore(elm, ref);
  901. }
  902. }
  903. /**
  904. * Apply styles to the given element.
  905. *
  906. * @param {Element} elm - An element where styles are applied.
  907. * @param {Object} styles - Object containing styles.
  908. */
  909. function applyStyle(elm, styles) {
  910. if (elm) {
  911. each(styles, function (value, prop) {
  912. if (value !== null) {
  913. elm.style[prop] = value;
  914. }
  915. });
  916. }
  917. }
  918. /**
  919. * Add or remove classes to/from the element.
  920. * This function is for internal usage.
  921. *
  922. * @param {Element} elm - An element where classes are added.
  923. * @param {string|string[]} classes - Class names being added.
  924. * @param {boolean} remove - Whether to remove or add classes.
  925. */
  926. function addOrRemoveClasses(elm, classes, remove) {
  927. if (elm) {
  928. toArray(classes).forEach(function (name) {
  929. if (name) {
  930. elm.classList[remove ? 'remove' : 'add'](name);
  931. }
  932. });
  933. }
  934. }
  935. /**
  936. * Add classes to the element.
  937. *
  938. * @param {Element} elm - An element where classes are added.
  939. * @param {string|string[]} classes - Class names being added.
  940. */
  941. function addClass(elm, classes) {
  942. addOrRemoveClasses(elm, classes, false);
  943. }
  944. /**
  945. * Remove a class from the element.
  946. *
  947. * @param {Element} elm - An element where classes are removed.
  948. * @param {string|string[]} classes - A class name being removed.
  949. */
  950. function removeClass(elm, classes) {
  951. addOrRemoveClasses(elm, classes, true);
  952. }
  953. /**
  954. * Verify if the provided element has the class or not.
  955. *
  956. * @param {Element} elm - An element.
  957. * @param {string} className - A class name.
  958. *
  959. * @return {boolean} - True if the element has the class or false if not.
  960. */
  961. function hasClass(elm, className) {
  962. return !!elm && elm.classList.contains(className);
  963. }
  964. /**
  965. * Set attribute to the given element.
  966. *
  967. * @param {Element} elm - An element where an attribute is assigned.
  968. * @param {string} name - Attribute name.
  969. * @param {string|number|boolean} value - Attribute value.
  970. */
  971. function setAttribute(elm, name, value) {
  972. if (elm) {
  973. elm.setAttribute(name, value);
  974. }
  975. }
  976. /**
  977. * Get attribute from the given element.
  978. *
  979. * @param {Element} elm - An element where an attribute is assigned.
  980. * @param {string} name - Attribute name.
  981. *
  982. * @return {string} - The value of the given attribute if available. An empty string if not.
  983. */
  984. function getAttribute(elm, name) {
  985. return elm ? elm.getAttribute(name) : '';
  986. }
  987. /**
  988. * Remove attribute from the given element.
  989. *
  990. * @param {Element|Element[]} elms - An element where an attribute is removed.
  991. * @param {string|string[]} names - Attribute name.
  992. */
  993. function removeAttribute(elms, names) {
  994. toArray(names).forEach(function (name) {
  995. toArray(elms).forEach(function (elm) {
  996. return elm && elm.removeAttribute(name);
  997. });
  998. });
  999. }
  1000. /**
  1001. * Trigger the given callback after all images contained by the element are loaded.
  1002. *
  1003. * @param {Element} elm - Element that may contain images.
  1004. * @param {Function} callback - Callback function fired right after all images are loaded.
  1005. */
  1006. function dom_loaded(elm, callback) {
  1007. var images = elm.querySelectorAll('img');
  1008. var length = images.length;
  1009. if (length) {
  1010. var count = 0;
  1011. each(images, function (img) {
  1012. img.onload = img.onerror = function () {
  1013. if (++count === length) {
  1014. callback();
  1015. }
  1016. };
  1017. });
  1018. } else {
  1019. // Trigger the callback immediately if there is no image.
  1020. callback();
  1021. }
  1022. }
  1023. // CONCATENATED MODULE: ./src/js/constants/types.js
  1024. /**
  1025. * Export slider types.
  1026. *
  1027. * @author Naotoshi Fujita
  1028. * @copyright Naotoshi Fujita. All rights reserved.
  1029. */
  1030. /**
  1031. * Normal slider.
  1032. *
  1033. * @type {string}
  1034. */
  1035. var SLIDE = 'slide';
  1036. /**
  1037. * Loop after the last slide and before the first one.
  1038. *
  1039. * @type {string}
  1040. */
  1041. var LOOP = 'loop';
  1042. /**
  1043. * The track doesn't move.
  1044. *
  1045. * @type {string}
  1046. */
  1047. var FADE = 'fade';
  1048. // CONCATENATED MODULE: ./src/js/transitions/slide/index.js
  1049. /**
  1050. * The component for general slide effect transition.
  1051. *
  1052. * @author Naotoshi Fujita
  1053. * @copyright Naotoshi Fujita. All rights reserved.
  1054. */
  1055. /**
  1056. * The component for general slide effect transition.
  1057. *
  1058. * @param {Splide} Splide - A Splide instance.
  1059. * @param {Object} Components - An object containing components.
  1060. *
  1061. * @return {Object} - The component object.
  1062. */
  1063. /* harmony default export */ var transitions_slide = (function (Splide, Components) {
  1064. /**
  1065. * Hold the list element.
  1066. *
  1067. * @type {Element}
  1068. */
  1069. var list;
  1070. /**
  1071. * Hold the onEnd callback function.
  1072. *
  1073. * @type {function}
  1074. */
  1075. var endCallback;
  1076. return {
  1077. /**
  1078. * Called when the component is mounted.
  1079. */
  1080. mount: function mount() {
  1081. list = Components.Elements.list;
  1082. Splide.on('transitionend', function (e) {
  1083. if (e.target === list && endCallback) {
  1084. endCallback();
  1085. }
  1086. }, list);
  1087. },
  1088. /**
  1089. * Start transition.
  1090. *
  1091. * @param {number} destIndex - Destination slide index that might be clone's.
  1092. * @param {number} newIndex - New index.
  1093. * @param {number} prevIndex - Previous index.
  1094. * @param {Object} coord - Destination coordinates.
  1095. * @param {function} done - Callback function must be invoked when transition is completed.
  1096. */
  1097. start: function start(destIndex, newIndex, prevIndex, coord, done) {
  1098. var options = Splide.options;
  1099. var edgeIndex = Components.Controller.edgeIndex;
  1100. var speed = options.speed;
  1101. endCallback = done;
  1102. if (Splide.is(SLIDE)) {
  1103. if (prevIndex === 0 && newIndex >= edgeIndex || prevIndex >= edgeIndex && newIndex === 0) {
  1104. speed = options.rewindSpeed || speed;
  1105. }
  1106. }
  1107. applyStyle(list, {
  1108. transition: "transform " + speed + "ms " + options.easing,
  1109. transform: "translate(" + coord.x + "px," + coord.y + "px)"
  1110. });
  1111. }
  1112. };
  1113. });
  1114. // CONCATENATED MODULE: ./src/js/transitions/fade/index.js
  1115. /**
  1116. * The component for fade transition.
  1117. *
  1118. * @author Naotoshi Fujita
  1119. * @copyright Naotoshi Fujita. All rights reserved.
  1120. */
  1121. /**
  1122. * The component for fade transition.
  1123. *
  1124. * @param {Splide} Splide - A Splide instance.
  1125. * @param {Object} Components - An object containing components.
  1126. *
  1127. * @return {Object} - The component object.
  1128. */
  1129. /* harmony default export */ var fade = (function (Splide, Components) {
  1130. if (Components.Drag) {
  1131. Components.Drag.required = false;
  1132. }
  1133. var Fade = {
  1134. /**
  1135. * Called when the component is mounted.
  1136. * Apply transition style to the first slide.
  1137. */
  1138. mount: function mount() {
  1139. apply(Splide.index);
  1140. },
  1141. /**
  1142. * Start transition.
  1143. *
  1144. * @param {number} destIndex - Destination slide index that might be clone's.
  1145. * @param {number} newIndex - New index.
  1146. * @param {number} prevIndex - Previous index.
  1147. * @param {Object} coord - Destination coordinates.
  1148. * @param {function} done - Callback function must be invoked when transition is completed.
  1149. */
  1150. start: function start(destIndex, newIndex, prevIndex, coord, done) {
  1151. var track = Components.Elements.track;
  1152. applyStyle(track, {
  1153. height: unit(track.clientHeight)
  1154. });
  1155. apply(newIndex);
  1156. done();
  1157. applyStyle(track, {
  1158. height: ''
  1159. });
  1160. }
  1161. };
  1162. /**
  1163. * Apply transition style to the slide specified by the given index.
  1164. *
  1165. * @param {number} index - A slide index.
  1166. */
  1167. function apply(index) {
  1168. var options = Splide.options;
  1169. applyStyle(Components.Elements.slides[index], {
  1170. transition: "opacity " + options.speed + "ms " + options.easing
  1171. });
  1172. }
  1173. return Fade;
  1174. });
  1175. // CONCATENATED MODULE: ./src/js/transitions/index.js
  1176. /**
  1177. * Export transition components.
  1178. *
  1179. * @author Naotoshi Fujita
  1180. * @copyright Naotoshi Fujita. All rights reserved.
  1181. */
  1182. // CONCATENATED MODULE: ./src/js/core/composer.js
  1183. /**
  1184. * Provide a function for composing components.
  1185. *
  1186. * @author Naotoshi Fujita
  1187. * @copyright Naotoshi Fujita. All rights reserved.
  1188. */
  1189. /**
  1190. * Compose components.
  1191. *
  1192. * @param {Splide} Splide - Splide instance.
  1193. * @param {Object} Components - Additional components.
  1194. * @param {function} Transition - Change component for transition.
  1195. *
  1196. * @return {Object} - An object containing all components.
  1197. */
  1198. function compose(Splide, Components, Transition) {
  1199. var components = {};
  1200. each(Components, function (Component, name) {
  1201. components[name] = Component(Splide, components, name.toLowerCase());
  1202. });
  1203. if (!Transition) {
  1204. Transition = Splide.is(FADE) ? fade : transitions_slide;
  1205. }
  1206. components.Transition = Transition(Splide, components);
  1207. return components;
  1208. }
  1209. // CONCATENATED MODULE: ./src/js/utils/error.js
  1210. /**
  1211. * Utility functions for outputting logs.
  1212. *
  1213. * @author Naotoshi Fujita
  1214. * @copyright Naotoshi Fujita. All rights reserved.
  1215. */
  1216. /**
  1217. * Prefix of an error massage.
  1218. *
  1219. * @type {string}
  1220. */
  1221. var MESSAGE_PREFIX = '[SPLIDE]';
  1222. /**
  1223. * Display an error message on the browser console.
  1224. *
  1225. * @param {string} message - An error message.
  1226. */
  1227. function error_error(message) {
  1228. console.error(MESSAGE_PREFIX + " " + message);
  1229. }
  1230. /**
  1231. * Check existence of the given object and throw an error if it doesn't.
  1232. *
  1233. * @throws {Error}
  1234. *
  1235. * @param {*} subject - A subject to be confirmed.
  1236. * @param {string} message - An error message.
  1237. */
  1238. function exist(subject, message) {
  1239. if (!subject) {
  1240. throw new Error(message);
  1241. }
  1242. }
  1243. // CONCATENATED MODULE: ./src/js/constants/states.js
  1244. /**
  1245. * Export state constants.
  1246. *
  1247. * @author Naotoshi Fujita
  1248. * @copyright Naotoshi Fujita. All rights reserved.
  1249. */
  1250. /**
  1251. * Splide has been just created.
  1252. *
  1253. * @type {number}
  1254. */
  1255. var CREATED = 1;
  1256. /**
  1257. * All components have been mounted and initialized.
  1258. *
  1259. * @type {number}
  1260. */
  1261. var MOUNTED = 2;
  1262. /**
  1263. * Splide is ready for transition.
  1264. *
  1265. * @type {number}
  1266. */
  1267. var IDLE = 3;
  1268. /**
  1269. * Splide is moving.
  1270. *
  1271. * @type {number}
  1272. */
  1273. var MOVING = 4;
  1274. /**
  1275. * Splide is moving.
  1276. *
  1277. * @type {number}
  1278. */
  1279. var DESTROYED = 5;
  1280. // CONCATENATED MODULE: ./src/js/splide.js
  1281. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  1282. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  1283. /**
  1284. * The main class for applying Splide to an element.
  1285. *
  1286. * @author Naotoshi Fujita
  1287. * @copyright Naotoshi Fujita. All rights reserved.
  1288. */
  1289. /**
  1290. * The main class for applying Splide to an element,
  1291. * providing some APIs to control the behavior.
  1292. */
  1293. var splide_Splide = /*#__PURE__*/function () {
  1294. /**
  1295. * Splide constructor.
  1296. *
  1297. * @throws {Error} When the given root element or selector is invalid.
  1298. *
  1299. * @param {Element|string} root - A selector for a root element or an element itself.
  1300. * @param {Object} options - Optional. Options to change default behaviour.
  1301. * @param {Object} Components - Optional. Components.
  1302. */
  1303. function Splide(root, options, Components) {
  1304. if (options === void 0) {
  1305. options = {};
  1306. }
  1307. if (Components === void 0) {
  1308. Components = {};
  1309. }
  1310. this.root = root instanceof Element ? root : find(document, root);
  1311. exist(this.root, 'An invalid element/selector was given.');
  1312. this.Components = null;
  1313. this.Event = core_event();
  1314. this.State = state(CREATED);
  1315. this.STATES = states_namespaceObject;
  1316. this._o = merge(DEFAULTS, options);
  1317. this._i = 0;
  1318. this._c = Components;
  1319. }
  1320. /**
  1321. * Compose and mount components.
  1322. *
  1323. * @param {Object} Extensions - Optional. Additional components.
  1324. * @param {function} Transition - Optional. Set a custom transition component.
  1325. *
  1326. * @return {Splide|null} - This instance or null if an exception occurred.
  1327. */
  1328. var _proto = Splide.prototype;
  1329. _proto.mount = function mount(Extensions, Transition) {
  1330. var _this = this;
  1331. if (Extensions === void 0) {
  1332. Extensions = {};
  1333. }
  1334. if (Transition === void 0) {
  1335. Transition = null;
  1336. }
  1337. this.Components = this.Components || compose(this, merge(this._c, Extensions), Transition);
  1338. try {
  1339. each(this.Components, function (component, key) {
  1340. var required = component.required;
  1341. if (required === undefined || required) {
  1342. component.mount && component.mount();
  1343. } else {
  1344. delete _this.Components[key];
  1345. }
  1346. });
  1347. } catch (e) {
  1348. error_error(e.message);
  1349. return null;
  1350. }
  1351. this.State.set(MOUNTED);
  1352. each(this.Components, function (component) {
  1353. component.mounted && component.mounted();
  1354. });
  1355. this.emit('mounted');
  1356. this.State.set(IDLE);
  1357. this.emit('ready');
  1358. applyStyle(this.root, {
  1359. visibility: 'visible'
  1360. });
  1361. this.on('move drag', function () {
  1362. return _this.State.set(MOVING);
  1363. }).on('moved dragged', function () {
  1364. return _this.State.set(IDLE);
  1365. });
  1366. return this;
  1367. }
  1368. /**
  1369. * Set sync target.
  1370. *
  1371. * @param {Splide} splide - A Splide instance.
  1372. *
  1373. * @return {Splide} - This instance.
  1374. */
  1375. ;
  1376. _proto.sync = function sync(splide) {
  1377. this.sibling = splide;
  1378. return this;
  1379. }
  1380. /**
  1381. * Register callback fired on the given event(s).
  1382. *
  1383. * @param {string} events - An event name. Use space to separate multiple events.
  1384. * Also, namespace is accepted by dot, such as 'resize.{namespace}'.
  1385. * @param {function} handler - A callback function.
  1386. * @param {Element} elm - Optional. Native event will be listened to when this arg is provided.
  1387. * @param {Object} options - Optional. Options for addEventListener.
  1388. *
  1389. * @return {Splide} - This instance.
  1390. */
  1391. ;
  1392. _proto.on = function on(events, handler, elm, options) {
  1393. if (elm === void 0) {
  1394. elm = null;
  1395. }
  1396. if (options === void 0) {
  1397. options = {};
  1398. }
  1399. this.Event.on(events, handler, elm, options);
  1400. return this;
  1401. }
  1402. /**
  1403. * Unsubscribe the given event.
  1404. *
  1405. * @param {string} events - A event name.
  1406. * @param {Element} elm - Optional. removeEventListener() will be called when this arg is provided.
  1407. *
  1408. * @return {Splide} - This instance.
  1409. */
  1410. ;
  1411. _proto.off = function off(events, elm) {
  1412. if (elm === void 0) {
  1413. elm = null;
  1414. }
  1415. this.Event.off(events, elm);
  1416. return this;
  1417. }
  1418. /**
  1419. * Emit an event.
  1420. *
  1421. * @param {string} event - An event name.
  1422. * @param {*} args - Any number of arguments passed to handlers.
  1423. */
  1424. ;
  1425. _proto.emit = function emit(event) {
  1426. var _this$Event;
  1427. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  1428. args[_key - 1] = arguments[_key];
  1429. }
  1430. (_this$Event = this.Event).emit.apply(_this$Event, [event].concat(args));
  1431. return this;
  1432. }
  1433. /**
  1434. * Go to the slide specified by the given control.
  1435. *
  1436. * @param {string|number} control - A control pattern.
  1437. * @param {boolean} wait - Optional. Whether to wait for transition.
  1438. */
  1439. ;
  1440. _proto.go = function go(control, wait) {
  1441. if (wait === void 0) {
  1442. wait = true;
  1443. }
  1444. if (this.State.is(IDLE) || this.State.is(MOVING) && !wait) {
  1445. this.Components.Controller.go(control, false);
  1446. }
  1447. return this;
  1448. }
  1449. /**
  1450. * Verify whether the slider type is the given one or not.
  1451. *
  1452. * @param {string} type - A slider type.
  1453. *
  1454. * @return {boolean} - True if the slider type is the provided type or false if not.
  1455. */
  1456. ;
  1457. _proto.is = function is(type) {
  1458. return type === this._o.type;
  1459. }
  1460. /**
  1461. * Insert a slide.
  1462. *
  1463. * @param {Element|string} slide - A slide element to be added.
  1464. * @param {number} index - A slide will be added at the position.
  1465. */
  1466. ;
  1467. _proto.add = function add(slide, index) {
  1468. if (index === void 0) {
  1469. index = -1;
  1470. }
  1471. this.Components.Elements.add(slide, index, this.refresh.bind(this));
  1472. return this;
  1473. }
  1474. /**
  1475. * Remove the slide designated by the index.
  1476. *
  1477. * @param {number} index - A slide index.
  1478. */
  1479. ;
  1480. _proto.remove = function remove(index) {
  1481. this.Components.Elements.remove(index);
  1482. this.refresh();
  1483. return this;
  1484. }
  1485. /**
  1486. * Destroy all Slide objects and clones and recreate them again.
  1487. */
  1488. ;
  1489. _proto.refresh = function refresh() {
  1490. this.emit('refresh').emit('resize');
  1491. return this;
  1492. }
  1493. /**
  1494. * Destroy the Splide.
  1495. * "Completely" boolean is mainly for breakpoints.
  1496. *
  1497. * @param {boolean} completely - Destroy completely.
  1498. */
  1499. ;
  1500. _proto.destroy = function destroy(completely) {
  1501. var _this2 = this;
  1502. if (completely === void 0) {
  1503. completely = true;
  1504. }
  1505. // Postpone destroy because it should be done after mount.
  1506. if (this.State.is(CREATED)) {
  1507. this.on('ready', function () {
  1508. return _this2.destroy(completely);
  1509. });
  1510. return;
  1511. }
  1512. values(this.Components).reverse().forEach(function (component) {
  1513. component.destroy && component.destroy(completely);
  1514. });
  1515. this.emit('destroy', completely); // Destroy all event handlers, including ones for native events.
  1516. this.Event.destroy();
  1517. this.State.set(DESTROYED);
  1518. return this;
  1519. }
  1520. /**
  1521. * Return the current slide index.
  1522. *
  1523. * @return {number} - The current slide index.
  1524. // */
  1525. ;
  1526. _createClass(Splide, [{
  1527. key: "index",
  1528. get: function get() {
  1529. return this._i;
  1530. }
  1531. /**
  1532. * Set the current slide index.
  1533. *
  1534. * @param {number|string} index - A new index.
  1535. */
  1536. ,
  1537. set: function set(index) {
  1538. this._i = parseInt(index);
  1539. }
  1540. /**
  1541. * Return length of slides.
  1542. * This is an alias of Elements.length.
  1543. *
  1544. * @return {number} - A number of slides.
  1545. */
  1546. }, {
  1547. key: "length",
  1548. get: function get() {
  1549. return this.Components.Elements.length;
  1550. }
  1551. /**
  1552. * Return options.
  1553. *
  1554. * @return {Object} - Options object.
  1555. */
  1556. }, {
  1557. key: "options",
  1558. get: function get() {
  1559. return this._o;
  1560. }
  1561. /**
  1562. * Set options with merging the given object to the current one.
  1563. *
  1564. * @param {Object} options - New options.
  1565. */
  1566. ,
  1567. set: function set(options) {
  1568. var created = this.State.is(CREATED);
  1569. if (!created) {
  1570. this.emit('update');
  1571. }
  1572. this._o = merge(this._o, options);
  1573. if (!created) {
  1574. this.emit('updated', this._o);
  1575. }
  1576. }
  1577. /**
  1578. * Return the class list.
  1579. * This is an alias of Splide.options.classList.
  1580. *
  1581. * @return {Object} - An object containing all class list.
  1582. */
  1583. }, {
  1584. key: "classes",
  1585. get: function get() {
  1586. return this._o.classes;
  1587. }
  1588. /**
  1589. * Return the i18n strings.
  1590. * This is an alias of Splide.options.i18n.
  1591. *
  1592. * @return {Object} - An object containing all i18n strings.
  1593. */
  1594. }, {
  1595. key: "i18n",
  1596. get: function get() {
  1597. return this._o.i18n;
  1598. }
  1599. }]);
  1600. return Splide;
  1601. }();
  1602. // CONCATENATED MODULE: ./src/js/components/options/index.js
  1603. /**
  1604. * The component for initializing options.
  1605. *
  1606. * @author Naotoshi Fujita
  1607. * @copyright Naotoshi Fujita. All rights reserved.
  1608. */
  1609. /**
  1610. * The component for initializing options.
  1611. *
  1612. * @param {Splide} Splide - A Splide instance.
  1613. *
  1614. * @return {Object} - The component object.
  1615. */
  1616. /* harmony default export */ var components_options = (function (Splide) {
  1617. /**
  1618. * Retrieve options from the data attribute.
  1619. * Note that IE10 doesn't support dataset property.
  1620. *
  1621. * @type {string}
  1622. */
  1623. var options = getAttribute(Splide.root, 'data-splide');
  1624. if (options) {
  1625. try {
  1626. Splide.options = JSON.parse(options);
  1627. } catch (e) {
  1628. error_error(e.message);
  1629. }
  1630. }
  1631. return {
  1632. /**
  1633. * Called when the component is mounted.
  1634. */
  1635. mount: function mount() {
  1636. if (Splide.State.is(CREATED)) {
  1637. Splide.index = Splide.options.start;
  1638. }
  1639. }
  1640. };
  1641. });
  1642. // CONCATENATED MODULE: ./src/js/constants/directions.js
  1643. /**
  1644. * Export layout modes.
  1645. *
  1646. * @author Naotoshi Fujita
  1647. * @copyright Naotoshi Fujita. All rights reserved.
  1648. */
  1649. /**
  1650. * Enumerate slides from left to right.
  1651. *
  1652. * @type {string}
  1653. */
  1654. var LTR = 'ltr';
  1655. /**
  1656. * Enumerate slides from right to left.
  1657. *
  1658. * @type {string}
  1659. */
  1660. var RTL = 'rtl';
  1661. /**
  1662. * Enumerate slides in a col.
  1663. *
  1664. * @type {string}
  1665. */
  1666. var TTB = 'ttb';
  1667. // CONCATENATED MODULE: ./src/js/components/elements/slide.js
  1668. /**
  1669. * The sub component for handling each slide.
  1670. *
  1671. * @author Naotoshi Fujita
  1672. * @copyright Naotoshi Fujita. All rights reserved.
  1673. */
  1674. /**
  1675. * Events for restoring original styles.
  1676. *
  1677. * @type {string}
  1678. */
  1679. var STYLE_RESTORE_EVENTS = 'update.slide';
  1680. /**
  1681. * The sub component for handling each slide.
  1682. *
  1683. * @param {Splide} Splide - A Splide instance.
  1684. * @param {number} index - An unique slide index.
  1685. * @param {number} realIndex - Clones should pass a real slide index.
  1686. * @param {Element} slide - A slide element.
  1687. *
  1688. * @return {Object} - The sub component object.
  1689. */
  1690. /* harmony default export */ var elements_slide = (function (Splide, index, realIndex, slide) {
  1691. /**
  1692. * Events when the slide status is updated.
  1693. * Append a namespace to remove listeners later.
  1694. *
  1695. * @type {string}
  1696. */
  1697. var STATUS_UPDATE_EVENTS = 'ready.slide updated.slide resize.slide ' + (Splide.options.updateOnMove ? 'move.slide' : 'moved.slide');
  1698. /**
  1699. * Slide sub component object.
  1700. *
  1701. * @type {Object}
  1702. */
  1703. var Slide = {
  1704. /**
  1705. * Slide element.
  1706. *
  1707. * @type {Element}
  1708. */
  1709. slide: slide,
  1710. /**
  1711. * Slide index.
  1712. *
  1713. * @type {number}
  1714. */
  1715. index: index,
  1716. /**
  1717. * Real index for clones.
  1718. *
  1719. * @type {number}
  1720. */
  1721. realIndex: realIndex,
  1722. /**
  1723. * Container element if available.
  1724. *
  1725. * @type {Element|null}
  1726. */
  1727. container: find(slide, "." + Splide.classes.container),
  1728. /**
  1729. * Whether this is a cloned slide or not.
  1730. *
  1731. * @type {boolean}
  1732. */
  1733. isClone: realIndex > -1,
  1734. /**
  1735. * Hold the original styles.
  1736. *
  1737. * @type {string}
  1738. */
  1739. styles: getAttribute(slide, 'style') || '',
  1740. /**
  1741. * Called when the component is mounted.
  1742. */
  1743. mount: function mount() {
  1744. var _this = this;
  1745. if (!this.isClone) {
  1746. slide.id = Splide.root.id + "-slide" + pad(index + 1);
  1747. }
  1748. Splide.on(STATUS_UPDATE_EVENTS, function () {
  1749. return _this.update();
  1750. }).on(STYLE_RESTORE_EVENTS, restoreStyles);
  1751. },
  1752. /**
  1753. * Destroy.
  1754. */
  1755. destroy: function destroy() {
  1756. Splide.off(STATUS_UPDATE_EVENTS).off(STYLE_RESTORE_EVENTS);
  1757. removeClass(slide, values(STATUS_CLASSES));
  1758. restoreStyles();
  1759. },
  1760. /**
  1761. * Update active and visible status.
  1762. */
  1763. update: function update() {
  1764. _update(this.isActive(), false);
  1765. _update(this.isVisible(), true);
  1766. },
  1767. /**
  1768. * Check whether this slide is active or not.
  1769. *
  1770. * @return {boolean} - True if the slide is active or false if not.
  1771. */
  1772. isActive: function isActive() {
  1773. return Splide.index === index;
  1774. },
  1775. /**
  1776. * Check whether this slide is visible in the viewport or not.
  1777. *
  1778. * @return {boolean} - True if the slide is visible or false if not.
  1779. */
  1780. isVisible: function isVisible() {
  1781. var active = this.isActive();
  1782. if (Splide.is(FADE) || active) {
  1783. return active;
  1784. }
  1785. var floor = Math.floor;
  1786. var Components = Splide.Components;
  1787. var Track = Components.Track;
  1788. var prop = Splide.options.direction === TTB ? 'clientHeight' : 'clientWidth';
  1789. var position = floor((Track.toPosition(index) + Track.offset(index) - Track.position) * Track.sign);
  1790. var edge = floor(position + slide[prop]);
  1791. var size = Components.Elements.track[prop];
  1792. return 0 <= position && position <= size && 0 <= edge && edge <= size;
  1793. },
  1794. /**
  1795. * Calculate how far this slide is from another slide and
  1796. * return true if the distance is within the given number.
  1797. *
  1798. * @param {number} from - Index of a target slide.
  1799. * @param {number} within - True if the slide is within this number.
  1800. *
  1801. * @return {boolean} - True if the slide is within the number or false otherwise.
  1802. */
  1803. isWithin: function isWithin(from, within) {
  1804. var diff = Math.abs(from - index);
  1805. if (!Splide.is(SLIDE) && !this.isClone) {
  1806. diff = Math.min(diff, Splide.length - diff);
  1807. }
  1808. return diff < within;
  1809. }
  1810. };
  1811. /**
  1812. * Update classes for activity or visibility.
  1813. *
  1814. * @param {boolean} active - Is active/visible or not.
  1815. * @param {boolean} forVisibility - Toggle classes for activity or visibility.
  1816. */
  1817. function _update(active, forVisibility) {
  1818. var type = forVisibility ? 'visible' : 'active';
  1819. var className = STATUS_CLASSES[type];
  1820. if (active) {
  1821. addClass(slide, className);
  1822. Splide.emit("" + type, Slide);
  1823. } else {
  1824. if (hasClass(slide, className)) {
  1825. removeClass(slide, className);
  1826. Splide.emit("" + (forVisibility ? 'hidden' : 'inactive'), Slide);
  1827. }
  1828. }
  1829. }
  1830. /**
  1831. * Restore the original styles.
  1832. */
  1833. function restoreStyles() {
  1834. setAttribute(slide, 'style', Slide.styles);
  1835. }
  1836. return Slide;
  1837. });
  1838. // CONCATENATED MODULE: ./src/js/components/elements/index.js
  1839. /**
  1840. * The component for main elements.
  1841. *
  1842. * @author Naotoshi Fujita
  1843. * @copyright Naotoshi Fujita. All rights reserved.
  1844. */
  1845. /**
  1846. * The property name for UID stored in a window object.
  1847. *
  1848. * @type {string}
  1849. */
  1850. var UID_NAME = 'uid';
  1851. /**
  1852. * The component for main elements.
  1853. *
  1854. * @param {Splide} Splide - A Splide instance.
  1855. * @param {Object} Components - An object containing components.
  1856. *
  1857. * @return {Object} - The component object.
  1858. */
  1859. /* harmony default export */ var components_elements = (function (Splide, Components) {
  1860. /**
  1861. * Hold the root element.
  1862. *
  1863. * @type {Element}
  1864. */
  1865. var root = Splide.root;
  1866. /**
  1867. * Hold the class list.
  1868. *
  1869. * @type {Object}
  1870. */
  1871. var classes = Splide.classes;
  1872. /**
  1873. * Store Slide objects.
  1874. *
  1875. * @type {Array}
  1876. */
  1877. var Slides = [];
  1878. /*
  1879. * Assign unique ID to the root element if it doesn't have the one.
  1880. * Note that IE doesn't support padStart() to fill the uid by 0.
  1881. */
  1882. if (!root.id) {
  1883. window.splide = window.splide || {};
  1884. var uid = window.splide[UID_NAME] || 0;
  1885. window.splide[UID_NAME] = ++uid;
  1886. root.id = "splide" + pad(uid);
  1887. }
  1888. /**
  1889. * Elements component object.
  1890. *
  1891. * @type {Object}
  1892. */
  1893. var Elements = {
  1894. /**
  1895. * Called when the component is mounted.
  1896. * Collect main elements and store them as member properties.
  1897. */
  1898. mount: function mount() {
  1899. var _this = this;
  1900. collect();
  1901. this.init();
  1902. Splide.on('refresh', function () {
  1903. _this.destroy();
  1904. _this.init();
  1905. });
  1906. Splide.on('updated', function () {
  1907. removeClass(root, getClasses());
  1908. addClass(root, getClasses());
  1909. });
  1910. },
  1911. /**
  1912. * Destroy.
  1913. */
  1914. destroy: function destroy() {
  1915. Slides.forEach(function (Slide) {
  1916. Slide.destroy();
  1917. });
  1918. Slides = [];
  1919. removeClass(root, getClasses());
  1920. },
  1921. /**
  1922. * Initialization.
  1923. */
  1924. init: function init() {
  1925. addClass(root, getClasses());
  1926. Elements.slides.forEach(function (slide, index) {
  1927. Elements.register(slide, index, -1);
  1928. });
  1929. },
  1930. /**
  1931. * Register a slide to create a Slide object and handle its behavior.
  1932. *
  1933. * @param {Element} slide - A slide element.
  1934. * @param {number} index - A unique index. This can be negative.
  1935. * @param {number} realIndex - A real index for clones. Set -1 for real slides.
  1936. */
  1937. register: function register(slide, index, realIndex) {
  1938. var SlideObject = elements_slide(Splide, index, realIndex, slide);
  1939. SlideObject.mount();
  1940. Slides.push(SlideObject);
  1941. },
  1942. /**
  1943. * Return the Slide object designated by the index.
  1944. * Note that "find" is not supported by IE.
  1945. *
  1946. * @return {Object|undefined} - A Slide object if available. Undefined if not.
  1947. */
  1948. getSlide: function getSlide(index) {
  1949. return Slides.filter(function (Slide) {
  1950. return Slide.index === index;
  1951. })[0];
  1952. },
  1953. /**
  1954. * Return all Slide objects.
  1955. *
  1956. * @param {boolean} includeClones - Whether to include cloned slides or not.
  1957. *
  1958. * @return {Object[]} - Slide objects.
  1959. */
  1960. getSlides: function getSlides(includeClones) {
  1961. return includeClones ? Slides : Slides.filter(function (Slide) {
  1962. return !Slide.isClone;
  1963. });
  1964. },
  1965. /**
  1966. * Return Slide objects belonging to the given page.
  1967. *
  1968. * @param {number} page - A page number.
  1969. *
  1970. * @return {Object[]} - An array containing Slide objects.
  1971. */
  1972. getSlidesByPage: function getSlidesByPage(page) {
  1973. var idx = Components.Controller.toIndex(page);
  1974. var options = Splide.options;
  1975. var max = options.focus !== false ? 1 : options.perPage;
  1976. return Slides.filter(function (_ref) {
  1977. var index = _ref.index;
  1978. return idx <= index && index < idx + max;
  1979. });
  1980. },
  1981. /**
  1982. * Insert a slide to a slider.
  1983. * Need to refresh Splide after adding a slide.
  1984. *
  1985. * @param {Node|string} slide - A slide element to be added.
  1986. * @param {number} index - A slide will be added at the position.
  1987. * @param {Function} callback - Called right after the slide is added to the DOM tree.
  1988. */
  1989. add: function add(slide, index, callback) {
  1990. if (typeof slide === 'string') {
  1991. slide = domify(slide);
  1992. }
  1993. if (slide instanceof Element) {
  1994. var ref = this.slides[index];
  1995. applyStyle(slide, {
  1996. display: 'none'
  1997. });
  1998. if (ref) {
  1999. before(slide, ref);
  2000. this.slides.splice(index, 0, slide);
  2001. } else {
  2002. append(this.list, slide);
  2003. this.slides.push(slide);
  2004. }
  2005. dom_loaded(slide, function () {
  2006. applyStyle(slide, {
  2007. display: ''
  2008. });
  2009. callback && callback(slide);
  2010. });
  2011. }
  2012. },
  2013. /**
  2014. * Remove a slide from a slider.
  2015. * Need to refresh Splide after removing a slide.
  2016. *
  2017. * @param index - Slide index.
  2018. */
  2019. remove: function remove(index) {
  2020. dom_remove(this.slides.splice(index, 1)[0]);
  2021. },
  2022. /**
  2023. * Trigger the provided callback for each Slide object.
  2024. *
  2025. * @param {Function} callback - A callback function. The first argument will be the Slide object.
  2026. */
  2027. each: function each(callback) {
  2028. Slides.forEach(callback);
  2029. },
  2030. /**
  2031. * Return slides length without clones.
  2032. *
  2033. * @return {number} - Slide length.
  2034. */
  2035. get length() {
  2036. return this.slides.length;
  2037. },
  2038. /**
  2039. * Return "SlideObjects" length including clones.
  2040. *
  2041. * @return {number} - Slide length including clones.
  2042. */
  2043. get total() {
  2044. return Slides.length;
  2045. }
  2046. };
  2047. /**
  2048. * Collect elements.
  2049. */
  2050. function collect() {
  2051. Elements.slider = child(root, classes.slider);
  2052. Elements.track = find(root, "." + classes.track);
  2053. Elements.list = child(Elements.track, classes.list);
  2054. exist(Elements.track && Elements.list, 'Track or list was not found.');
  2055. Elements.slides = values(Elements.list.children);
  2056. var arrows = findParts(classes.arrows);
  2057. Elements.arrows = {
  2058. prev: find(arrows, "." + classes.prev),
  2059. next: find(arrows, "." + classes.next)
  2060. };
  2061. var autoplay = findParts(classes.autoplay);
  2062. Elements.bar = find(findParts(classes.progress), "." + classes.bar);
  2063. Elements.play = find(autoplay, "." + classes.play);
  2064. Elements.pause = find(autoplay, "." + classes.pause);
  2065. Elements.track.id = Elements.track.id || root.id + "-track";
  2066. Elements.list.id = Elements.list.id || root.id + "-list";
  2067. }
  2068. /**
  2069. * Return class names for the root element.
  2070. */
  2071. function getClasses() {
  2072. var rootClass = classes.root;
  2073. var options = Splide.options;
  2074. return [rootClass + "--" + options.type, rootClass + "--" + options.direction, options.drag ? rootClass + "--draggable" : '', options.isNavigation ? rootClass + "--nav" : ''];
  2075. }
  2076. /**
  2077. * Find parts only from children of the root or track.
  2078. *
  2079. * @return {Element|null} - A found element or null.
  2080. */
  2081. function findParts(className) {
  2082. return child(root, className) || child(Elements.slider, className);
  2083. }
  2084. return Elements;
  2085. });
  2086. // CONCATENATED MODULE: ./src/js/components/controller/index.js
  2087. /**
  2088. * The component for controlling the track.
  2089. *
  2090. * @author Naotoshi Fujita
  2091. * @copyright Naotoshi Fujita. All rights reserved.
  2092. */
  2093. var controller_floor = Math.floor;
  2094. /**
  2095. * The component for controlling the track.
  2096. *
  2097. * @param {Splide} Splide - A Splide instance.
  2098. * @param {Object} Components - An object containing components.
  2099. *
  2100. * @return {Object} - The component object.
  2101. */
  2102. /* harmony default export */ var controller = (function (Splide, Components) {
  2103. /**
  2104. * Store current options.
  2105. *
  2106. * @type {Object}
  2107. */
  2108. var options;
  2109. /**
  2110. * True if the slide is LOOP mode.
  2111. *
  2112. * @type {boolean}
  2113. */
  2114. var isLoop;
  2115. /**
  2116. * Controller component object.
  2117. *
  2118. * @type {Object}
  2119. */
  2120. var Controller = {
  2121. /**
  2122. * Called when the component is mounted.
  2123. */
  2124. mount: function mount() {
  2125. options = Splide.options;
  2126. isLoop = Splide.is(LOOP);
  2127. bind();
  2128. },
  2129. /**
  2130. * Make track run by the given control.
  2131. * - "+{i}" : Increment the slide index by i.
  2132. * - "-{i}" : Decrement the slide index by i.
  2133. * - "{i}" : Go to the slide whose index is i.
  2134. * - ">" : Go to next page.
  2135. * - "<" : Go to prev page.
  2136. * - ">{i}" : Go to page i.
  2137. *
  2138. * @param {string|number} control - A control pattern.
  2139. * @param {boolean} silently - Go to the destination without event emission.
  2140. */
  2141. go: function go(control, silently) {
  2142. var destIndex = this.trim(this.parse(control));
  2143. Components.Track.go(destIndex, this.rewind(destIndex), silently);
  2144. },
  2145. /**
  2146. * Parse the given control and return the destination index for the track.
  2147. *
  2148. * @param {string} control - A control target pattern.
  2149. *
  2150. * @return {string|number} - A parsed target.
  2151. */
  2152. parse: function parse(control) {
  2153. var index = Splide.index;
  2154. var matches = String(control).match(/([+\-<>])(\d+)?/);
  2155. var indicator = matches ? matches[1] : '';
  2156. var number = matches ? parseInt(matches[2]) : 0;
  2157. switch (indicator) {
  2158. case '+':
  2159. index += number || 1;
  2160. break;
  2161. case '-':
  2162. index -= number || 1;
  2163. break;
  2164. case '>':
  2165. index = this.toIndex(number > -1 ? number : this.toPage(index) + 1);
  2166. break;
  2167. case '<':
  2168. index = this.toIndex(number > -1 ? number : this.toPage(index) - 1);
  2169. break;
  2170. default:
  2171. index = parseInt(control);
  2172. }
  2173. return index;
  2174. },
  2175. /**
  2176. * Compute index from the given page number.
  2177. *
  2178. * @param {number} page - Page number.
  2179. *
  2180. * @return {number} - A computed page number.
  2181. */
  2182. toIndex: function toIndex(page) {
  2183. if (hasFocus()) {
  2184. return page;
  2185. }
  2186. var length = Splide.length;
  2187. var perPage = options.perPage;
  2188. var index = page * perPage;
  2189. index = index - (this.pageLength * perPage - length) * controller_floor(index / length); // Adjustment for the last page.
  2190. if (length - perPage <= index && index < length) {
  2191. index = length - perPage;
  2192. }
  2193. return index;
  2194. },
  2195. /**
  2196. * Compute page number from the given slide index.
  2197. *
  2198. * @param index - Slide index.
  2199. *
  2200. * @return {number} - A computed page number.
  2201. */
  2202. toPage: function toPage(index) {
  2203. if (hasFocus()) {
  2204. return index;
  2205. }
  2206. var length = Splide.length;
  2207. var perPage = options.perPage; // Make the last "perPage" number of slides belong to the last page.
  2208. if (length - perPage <= index && index < length) {
  2209. return controller_floor((length - 1) / perPage);
  2210. }
  2211. return controller_floor(index / perPage);
  2212. },
  2213. /**
  2214. * Trim the given index according to the current mode.
  2215. * Index being returned could be less than 0 or greater than the length in Loop mode.
  2216. *
  2217. * @param {number} index - An index being trimmed.
  2218. *
  2219. * @return {number} - A trimmed index.
  2220. */
  2221. trim: function trim(index) {
  2222. if (!isLoop) {
  2223. index = options.rewind ? this.rewind(index) : between(index, 0, this.edgeIndex);
  2224. }
  2225. return index;
  2226. },
  2227. /**
  2228. * Rewind the given index if it's out of range.
  2229. *
  2230. * @param {number} index - An index.
  2231. *
  2232. * @return {number} - A rewound index.
  2233. */
  2234. rewind: function rewind(index) {
  2235. var edge = this.edgeIndex;
  2236. if (isLoop) {
  2237. while (index > edge) {
  2238. index -= edge + 1;
  2239. }
  2240. while (index < 0) {
  2241. index += edge + 1;
  2242. }
  2243. } else {
  2244. if (index > edge) {
  2245. index = 0;
  2246. } else if (index < 0) {
  2247. index = edge;
  2248. }
  2249. }
  2250. return index;
  2251. },
  2252. /**
  2253. * Check if the direction is "rtl" or not.
  2254. *
  2255. * @return {boolean} - True if "rtl" or false if not.
  2256. */
  2257. isRtl: function isRtl() {
  2258. return options.direction === RTL;
  2259. },
  2260. /**
  2261. * Return the page length.
  2262. *
  2263. * @return {number} - Max page number.
  2264. */
  2265. get pageLength() {
  2266. var length = Splide.length;
  2267. return hasFocus() ? length : Math.ceil(length / options.perPage);
  2268. },
  2269. /**
  2270. * Return the edge index.
  2271. *
  2272. * @return {number} - Edge index.
  2273. */
  2274. get edgeIndex() {
  2275. var length = Splide.length;
  2276. if (!length) {
  2277. return 0;
  2278. }
  2279. if (hasFocus() || options.isNavigation || isLoop) {
  2280. return length - 1;
  2281. }
  2282. return length - options.perPage;
  2283. },
  2284. /**
  2285. * Return the index of the previous slide.
  2286. *
  2287. * @return {number} - The index of the previous slide if available. -1 otherwise.
  2288. */
  2289. get prevIndex() {
  2290. var prev = Splide.index - 1;
  2291. if (isLoop || options.rewind) {
  2292. prev = this.rewind(prev);
  2293. }
  2294. return prev > -1 ? prev : -1;
  2295. },
  2296. /**
  2297. * Return the index of the next slide.
  2298. *
  2299. * @return {number} - The index of the next slide if available. -1 otherwise.
  2300. */
  2301. get nextIndex() {
  2302. var next = Splide.index + 1;
  2303. if (isLoop || options.rewind) {
  2304. next = this.rewind(next);
  2305. }
  2306. return Splide.index < next && next <= this.edgeIndex || next === 0 ? next : -1;
  2307. }
  2308. };
  2309. /**
  2310. * Listen some events.
  2311. */
  2312. function bind() {
  2313. Splide.on('move', function (newIndex) {
  2314. Splide.index = newIndex;
  2315. }).on('updated refresh', function (newOptions) {
  2316. options = newOptions || options;
  2317. Splide.index = between(Splide.index, 0, Controller.edgeIndex);
  2318. });
  2319. }
  2320. /**
  2321. * Verify if the focus option is available or not.
  2322. *
  2323. * @return {boolean} - True if a slider has the focus option.
  2324. */
  2325. function hasFocus() {
  2326. return options.focus !== false;
  2327. }
  2328. return Controller;
  2329. });
  2330. // CONCATENATED MODULE: ./src/js/components/track/directions/vertical.js
  2331. /**
  2332. * The resolver component for vertical move.
  2333. *
  2334. * @author Naotoshi Fujita
  2335. * @copyright Naotoshi Fujita. All rights reserved.
  2336. */
  2337. /**
  2338. * The resolver component for vertical move.
  2339. *
  2340. * @param {Splide} Splide - A Splide instance.
  2341. * @param {Object} Components - An object containing components.
  2342. *
  2343. * @return {Object} - The resolver object.
  2344. */
  2345. /* harmony default export */ var vertical = (function (Splide, Components) {
  2346. /**
  2347. * Hold the Layout object.
  2348. *
  2349. * @type {Object}
  2350. */
  2351. var Layout;
  2352. return {
  2353. /**
  2354. * Axis of translate.
  2355. *
  2356. * @type {string}
  2357. */
  2358. axis: 'Y',
  2359. /**
  2360. * Sign for the direction.
  2361. *
  2362. * @return {number}
  2363. */
  2364. sign: -1,
  2365. /**
  2366. * Initialization.
  2367. */
  2368. init: function init() {
  2369. Layout = Components.Layout;
  2370. },
  2371. /**
  2372. * Calculate position by index.
  2373. *
  2374. * @param {number} index - Slide index.
  2375. *
  2376. * @return {Object} - Calculated position.
  2377. */
  2378. toPosition: function toPosition(index) {
  2379. return -((index + Components.Clones.length / 2) * (Layout.slideHeight() + Layout.gap) + this.offset());
  2380. },
  2381. /**
  2382. * Calculate the closest slide index from the given position.
  2383. *
  2384. * @return {number} - The closest slide index.
  2385. */
  2386. toIndex: function toIndex(position) {
  2387. var slideHeight = Layout.slideHeight();
  2388. var cloneOffset = (slideHeight + Layout.gap) * Components.Clones.length / 2;
  2389. return Math.round(-(position + cloneOffset + this.offset()) / (slideHeight + Layout.gap));
  2390. },
  2391. /**
  2392. * Trim redundant spaces on the left or right edge if necessary.
  2393. *
  2394. * @param {number} position - Position value to be trimmed.
  2395. *
  2396. * @return {number} - Trimmed position.
  2397. */
  2398. trim: function trim(position) {
  2399. var edge = -(Layout.listHeight - (Layout.height + Layout.gap));
  2400. return between(position, edge, 0);
  2401. },
  2402. /**
  2403. * Return current offset value, considering direction.
  2404. *
  2405. * @return {number} - Offset amount.
  2406. */
  2407. offset: function offset() {
  2408. var focus = Splide.options.focus;
  2409. var slideHeight = Layout.slideHeight();
  2410. if (focus === 'center') {
  2411. return -(Layout.height - slideHeight) / 2;
  2412. }
  2413. return -(parseInt(focus) || 0) * (slideHeight + Layout.gap);
  2414. }
  2415. };
  2416. });
  2417. // CONCATENATED MODULE: ./src/js/components/track/directions/horizontal.js
  2418. /**
  2419. * The resolver component for horizontal move.
  2420. *
  2421. * @author Naotoshi Fujita
  2422. * @copyright Naotoshi Fujita. All rights reserved.
  2423. */
  2424. /**
  2425. * The resolver component for horizontal move.
  2426. *
  2427. * @param {Splide} Splide - A Splide instance.
  2428. * @param {Object} Components - An object containing components.
  2429. *
  2430. * @return {Object} - The resolver object.
  2431. */
  2432. /* harmony default export */ var horizontal = (function (Splide, Components) {
  2433. /**
  2434. * Hold the Layout component.
  2435. *
  2436. * @type {Object}
  2437. */
  2438. var Layout;
  2439. /**
  2440. * Hold the Elements component.
  2441. *
  2442. * @type {Object}
  2443. */
  2444. var Elements;
  2445. return {
  2446. /**
  2447. * Axis of translate.
  2448. *
  2449. * @type {string}
  2450. */
  2451. axis: 'X',
  2452. /**
  2453. * Sign for the direction.
  2454. *
  2455. * @type {number}
  2456. */
  2457. sign: Splide.options.direction === RTL ? 1 : -1,
  2458. /**
  2459. * Initialization.
  2460. */
  2461. init: function init() {
  2462. Layout = Components.Layout;
  2463. Elements = Components.Elements;
  2464. },
  2465. /**
  2466. * Calculate position by index.
  2467. *
  2468. * @param {number} index - Slide index.
  2469. *
  2470. * @return {Object} - Calculated position.
  2471. */
  2472. toPosition: function toPosition(index) {
  2473. return this.sign * (Layout.totalWidth(index - 1) + this.offset(index));
  2474. },
  2475. /**
  2476. * Calculate the closest slide index from the given position.
  2477. *
  2478. * @return {number} - The closest slide position.
  2479. */
  2480. toIndex: function toIndex(position) {
  2481. position *= this.sign;
  2482. if (Splide.is(SLIDE)) {
  2483. position = between(position, Layout.totalWidth(Elements.total), 0);
  2484. }
  2485. var Slides = Elements.getSlides(true);
  2486. for (var i in Slides) {
  2487. var Slide = Slides[i];
  2488. var slideIndex = Slide.index;
  2489. var slidePosition = this.sign * this.toPosition(slideIndex);
  2490. if (slidePosition < position && position <= slidePosition + Layout.slideWidth(slideIndex) + Layout.gap) {
  2491. return slideIndex;
  2492. }
  2493. }
  2494. return 0;
  2495. },
  2496. /**
  2497. * Trim redundant spaces on the left or right edge if necessary.
  2498. *
  2499. * @param {number} position - Position value to be trimmed.
  2500. *
  2501. * @return {number} - Trimmed position.
  2502. */
  2503. trim: function trim(position) {
  2504. var edge = this.sign * (Layout.totalWidth(Elements.total) - (Layout.width + Layout.gap));
  2505. return between(position, edge, 0);
  2506. },
  2507. /**
  2508. * Return current offset value, considering direction.
  2509. *
  2510. * @return {number} - Offset amount.
  2511. */
  2512. offset: function offset(index) {
  2513. var focus = Splide.options.focus;
  2514. var slideWidth = Layout.slideWidth(index);
  2515. if (focus === 'center') {
  2516. return -(Layout.width - slideWidth) / 2;
  2517. }
  2518. return -(parseInt(focus) || 0) * (slideWidth + Layout.gap);
  2519. }
  2520. };
  2521. });
  2522. // CONCATENATED MODULE: ./src/js/components/track/index.js
  2523. /**
  2524. * The component for moving list in the track.
  2525. *
  2526. * @author Naotoshi Fujita
  2527. * @copyright Naotoshi Fujita. All rights reserved.
  2528. */
  2529. /**
  2530. * The component for moving list in the track.
  2531. *
  2532. * @param {Splide} Splide - A Splide instance.
  2533. * @param {Object} Components - An object containing components.
  2534. *
  2535. * @return {Object} - The component object.
  2536. */
  2537. /* harmony default export */ var components_track = (function (Splide, Components) {
  2538. /**
  2539. * Store the list element.
  2540. *
  2541. * @type {Element}
  2542. */
  2543. var list;
  2544. /**
  2545. * Store the current position.
  2546. *
  2547. * @type {number}
  2548. */
  2549. var currPosition = 0;
  2550. /**
  2551. * Whether the current direction is vertical or not.
  2552. *
  2553. * @type {boolean}
  2554. */
  2555. var isVertical = Splide.options.direction === TTB;
  2556. /**
  2557. * Whether the slider type is FADE or not.
  2558. *
  2559. * @type {boolean}
  2560. */
  2561. var isFade = Splide.is(FADE);
  2562. /**
  2563. * Track component object.
  2564. *
  2565. * @type {Object}
  2566. */
  2567. var Track = object_assign({
  2568. /**
  2569. * Called when the component is mounted.
  2570. */
  2571. mount: function mount() {
  2572. list = Components.Elements.list;
  2573. this.init();
  2574. },
  2575. /**
  2576. * Called after the component is mounted.
  2577. * The resize event must be registered after the Layout's one is done.
  2578. */
  2579. mounted: function mounted() {
  2580. var _this = this;
  2581. if (!isFade) {
  2582. Splide.on('mounted resize updated', function () {
  2583. _this.jump(Splide.index);
  2584. });
  2585. }
  2586. },
  2587. /**
  2588. * Go to the given destination index.
  2589. * After arriving there, the track is jump to the new index without animation, mainly for loop mode.
  2590. *
  2591. * @param {number} destIndex - A destination index.
  2592. * This can be negative or greater than slides length for reaching clones.
  2593. * @param {number} newIndex - An actual new index. They are always same in Slide and Rewind mode.
  2594. * @param {boolean} silently - If true, suppress emitting events.
  2595. */
  2596. go: function go(destIndex, newIndex, silently) {
  2597. var _this2 = this;
  2598. var newPosition = getTrimmedPosition(destIndex);
  2599. var prevIndex = Splide.index;
  2600. if (!silently) {
  2601. Splide.emit('move', newIndex, prevIndex, destIndex);
  2602. }
  2603. if (Math.abs(newPosition - currPosition) >= 1 || isFade) {
  2604. Components.Transition.start(destIndex, newIndex, prevIndex, this.toCoord(newPosition), function () {
  2605. _this2.end(destIndex, newIndex, prevIndex, silently);
  2606. });
  2607. } else {
  2608. if (destIndex !== prevIndex && Splide.options.trimSpace === 'move') {
  2609. Components.Controller.go(destIndex + destIndex - prevIndex, silently);
  2610. } else {
  2611. this.end(destIndex, newIndex, prevIndex, silently);
  2612. }
  2613. }
  2614. },
  2615. /**
  2616. * Called whenever slides arrive at a destination.
  2617. *
  2618. * @param {number} destIndex - A destination index.
  2619. * @param {number} newIndex - A new index.
  2620. * @param {number} prevIndex - A previous index.
  2621. * @param {boolean} silently - If true, suppress emitting events.
  2622. */
  2623. end: function end(destIndex, newIndex, prevIndex, silently) {
  2624. applyStyle(list, {
  2625. transition: ''
  2626. });
  2627. if (!isFade) {
  2628. this.jump(newIndex);
  2629. }
  2630. if (!silently) {
  2631. Splide.emit('moved', newIndex, prevIndex, destIndex);
  2632. }
  2633. },
  2634. /**
  2635. * Move the track to the specified index.
  2636. *
  2637. * @param {number} index - A destination index where the track jumps.
  2638. */
  2639. jump: function jump(index) {
  2640. this.translate(getTrimmedPosition(index));
  2641. },
  2642. /**
  2643. * Set position.
  2644. *
  2645. * @param {number} position - A new position value.
  2646. */
  2647. translate: function translate(position) {
  2648. currPosition = position;
  2649. applyStyle(list, {
  2650. transform: "translate" + this.axis + "(" + position + "px)"
  2651. });
  2652. },
  2653. /**
  2654. * Trim redundant spaces on the left or right edge if necessary.
  2655. *
  2656. * @param {number} position - Position value to be trimmed.
  2657. *
  2658. * @return {number} - Trimmed position.
  2659. */
  2660. trim: function trim(position) {
  2661. if (!Splide.options.trimSpace || Splide.is(LOOP)) {
  2662. return position;
  2663. }
  2664. return this._s.trim(position);
  2665. },
  2666. /**
  2667. * Return coordinates object by the given position.
  2668. *
  2669. * @param {number} position - A position value.
  2670. *
  2671. * @return {Object} - A coordinates object.
  2672. */
  2673. toCoord: function toCoord(position) {
  2674. return {
  2675. x: isVertical ? 0 : position,
  2676. y: isVertical ? position : 0
  2677. };
  2678. },
  2679. /**
  2680. * Return current position.
  2681. *
  2682. * @return {number} - Current position.
  2683. */
  2684. get position() {
  2685. return currPosition;
  2686. }
  2687. }, isVertical ? vertical(Splide, Components) : horizontal(Splide, Components));
  2688. /**
  2689. * Convert index to the trimmed position.
  2690. *
  2691. * @return {number} - Trimmed position.
  2692. */
  2693. function getTrimmedPosition(index) {
  2694. return Track.trim(Track.toPosition(index));
  2695. }
  2696. return Track;
  2697. });
  2698. // CONCATENATED MODULE: ./src/js/components/clones/index.js
  2699. /**
  2700. * The component for cloning some slides for "loop" mode of the track.
  2701. *
  2702. * @author Naotoshi Fujita
  2703. * @copyright Naotoshi Fujita. All rights reserved.
  2704. */
  2705. /**
  2706. * The component for cloning some slides for "loop" mode of the track.
  2707. *
  2708. * @param {Splide} Splide - A Splide instance.
  2709. * @param {Object} Components - An object containing components.
  2710. *
  2711. * @return {Object} - The component object.
  2712. */
  2713. /* harmony default export */ var components_clones = (function (Splide, Components) {
  2714. /**
  2715. * Store information of all clones.
  2716. *
  2717. * @type {Array}
  2718. */
  2719. var clones = [];
  2720. /**
  2721. * Keep Elements component.
  2722. *
  2723. * @type {Object}
  2724. */
  2725. var Elements = Components.Elements;
  2726. /**
  2727. * Clones component object.
  2728. *
  2729. * @type {Object}
  2730. */
  2731. var Clones = {
  2732. /**
  2733. * Called when the component is mounted.
  2734. */
  2735. mount: function mount() {
  2736. var _this = this;
  2737. if (Splide.is(LOOP)) {
  2738. generateClones();
  2739. Splide.on('refresh', function () {
  2740. _this.destroy();
  2741. generateClones();
  2742. });
  2743. }
  2744. },
  2745. /**
  2746. * Destroy.
  2747. */
  2748. destroy: function destroy() {
  2749. dom_remove(clones);
  2750. clones = [];
  2751. },
  2752. /**
  2753. * Return all clones.
  2754. *
  2755. * @return {Element[]} - Cloned elements.
  2756. */
  2757. get clones() {
  2758. return clones;
  2759. },
  2760. /**
  2761. * Return clone length.
  2762. *
  2763. * @return {number} - A length of clones.
  2764. */
  2765. get length() {
  2766. return clones.length;
  2767. }
  2768. };
  2769. /**
  2770. * Generate and append clones.
  2771. */
  2772. function generateClones() {
  2773. var length = Elements.length;
  2774. if (!length) {
  2775. return;
  2776. }
  2777. var count = getCloneCount();
  2778. var slides = Elements.slides;
  2779. while (slides.length < count) {
  2780. slides = slides.concat(slides);
  2781. }
  2782. slides.slice(0, count).forEach(function (elm, index) {
  2783. var clone = cloneDeeply(elm);
  2784. append(Elements.list, clone);
  2785. clones.push(clone);
  2786. Elements.register(clone, index + length, index);
  2787. });
  2788. slides.slice(-count).forEach(function (elm, index) {
  2789. var clone = cloneDeeply(elm);
  2790. before(clone, slides[0]);
  2791. clones.push(clone);
  2792. Elements.register(clone, index - count, index);
  2793. });
  2794. }
  2795. /**
  2796. * Return half count of clones to be generated.
  2797. * Clone count is determined by:
  2798. * - Max pages a flick action can move.
  2799. * - Whether the slide length is enough for perPage.
  2800. *
  2801. * @return {number} - Count for clones.
  2802. */
  2803. function getCloneCount() {
  2804. var options = Splide.options;
  2805. if (options.autoWidth) {
  2806. return Elements.length;
  2807. }
  2808. return options.perPage * (options.drag ? options.flickMaxPages + 1 : 1);
  2809. }
  2810. /**
  2811. * Clone deeply the given element.
  2812. *
  2813. * @param {Element} elm - An element being duplicated.
  2814. *
  2815. * @return {Node} - A cloned node(element).
  2816. */
  2817. function cloneDeeply(elm) {
  2818. var clone = elm.cloneNode(true);
  2819. addClass(clone, Splide.classes.clone); // ID should not be duplicated.
  2820. removeAttribute(clone, 'id');
  2821. return clone;
  2822. }
  2823. return Clones;
  2824. });
  2825. // CONCATENATED MODULE: ./src/js/components/layout/directions/horizontal.js
  2826. /**
  2827. * The resolver component for horizontal layout.
  2828. *
  2829. * @author Naotoshi Fujita
  2830. * @copyright Naotoshi Fujita. All rights reserved.
  2831. */
  2832. /**
  2833. * Max width of a slide.
  2834. *
  2835. * @type {number}
  2836. */
  2837. var SLIDE_MAX_WIDTH = 5000;
  2838. /**
  2839. * The resolver component for horizontal layout.
  2840. *
  2841. * @param {Splide} Splide - A Splide instance.
  2842. * @param {Object} Components - An object containing components.
  2843. *
  2844. * @return {Object} - The resolver object.
  2845. */
  2846. /* harmony default export */ var directions_horizontal = (function (Splide, Components) {
  2847. /**
  2848. * Keep the Elements component.
  2849. *
  2850. * @type {string}
  2851. */
  2852. var Elements = Components.Elements;
  2853. /**
  2854. * Keep the root element.
  2855. *
  2856. * @type {Element}
  2857. */
  2858. var root = Splide.root;
  2859. /**
  2860. * Keep the track element.
  2861. *
  2862. * @type {Element}
  2863. */
  2864. var track;
  2865. /**
  2866. * Keep the latest options.
  2867. *
  2868. * @type {Element}
  2869. */
  2870. var options = Splide.options;
  2871. return {
  2872. /**
  2873. * Margin property name.
  2874. *
  2875. * @type {string}
  2876. */
  2877. margin: 'margin' + (options.direction === RTL ? 'Left' : 'Right'),
  2878. /**
  2879. * Always 0 because the height will be determined by inner contents.
  2880. *
  2881. * @type {number}
  2882. */
  2883. height: 0,
  2884. /**
  2885. * Always 0 because the height will be determined by inner contents.
  2886. *
  2887. * @type {number}
  2888. */
  2889. listHeight: 0,
  2890. /**
  2891. * Initialization.
  2892. */
  2893. init: function init() {
  2894. options = Splide.options;
  2895. track = Elements.track;
  2896. this.gap = toPixel(root, options.gap);
  2897. var padding = options.padding;
  2898. var _padding$left = padding.left,
  2899. left = _padding$left === void 0 ? padding : _padding$left,
  2900. _padding$right = padding.right,
  2901. right = _padding$right === void 0 ? padding : _padding$right;
  2902. this.padding = {
  2903. left: toPixel(root, left),
  2904. right: toPixel(root, right)
  2905. };
  2906. applyStyle(track, {
  2907. paddingLeft: unit(left),
  2908. paddingRight: unit(right)
  2909. });
  2910. },
  2911. /**
  2912. * Accumulate slide width including the gap to the designated index.
  2913. *
  2914. * @param {number|undefined} index - If undefined, width of all slides will be accumulated.
  2915. *
  2916. * @return {number} - Accumulated width.
  2917. */
  2918. totalWidth: function totalWidth(index) {
  2919. var _this = this;
  2920. return Elements.getSlides(true).filter(function (Slide) {
  2921. return Slide.index <= index;
  2922. }).reduce(function (accumulator, Slide) {
  2923. return accumulator + _this.slideWidth(Slide.index) + _this.gap;
  2924. }, 0);
  2925. },
  2926. /**
  2927. * Return the slide width in px.
  2928. *
  2929. * @param {number} index - Slide index.
  2930. *
  2931. * @return {number} - The slide width.
  2932. */
  2933. slideWidth: function slideWidth(index) {
  2934. if (options.autoWidth) {
  2935. var Slide = Elements.getSlide(index);
  2936. return Slide ? Slide.slide.offsetWidth : 0;
  2937. }
  2938. var width = options.fixedWidth || (this.width + this.gap) / options.perPage - this.gap;
  2939. return toPixel(root, width);
  2940. },
  2941. /**
  2942. * Return the slide height in px.
  2943. *
  2944. * @return {number} - The slide height.
  2945. */
  2946. slideHeight: function slideHeight() {
  2947. var height = options.height || options.fixedHeight || this.width * options.heightRatio;
  2948. return toPixel(root, height);
  2949. },
  2950. /**
  2951. * Return slider width without padding.
  2952. *
  2953. * @return {number} - Current slider width.
  2954. */
  2955. get width() {
  2956. return track.clientWidth - this.padding.left - this.padding.right;
  2957. },
  2958. /**
  2959. * Return list width.
  2960. *
  2961. * @return {number} - Current list width.
  2962. */
  2963. get listWidth() {
  2964. var total = Elements.total;
  2965. return options.autoWidth ? total * SLIDE_MAX_WIDTH : this.totalWidth(total);
  2966. }
  2967. };
  2968. });
  2969. // CONCATENATED MODULE: ./src/js/components/layout/directions/vertical.js
  2970. /**
  2971. * The resolver component for vertical layout.
  2972. *
  2973. * @author Naotoshi Fujita
  2974. * @copyright Naotoshi Fujita. All rights reserved.
  2975. */
  2976. /**
  2977. * The resolver component for vertical layout.
  2978. *
  2979. * @param {Splide} Splide - A Splide instance.
  2980. * @param {Object} Components - An object containing components.
  2981. *
  2982. * @return {Object} - The resolver object.
  2983. */
  2984. /* harmony default export */ var directions_vertical = (function (Splide, Components) {
  2985. /**
  2986. * Keep the Elements component.
  2987. *
  2988. * @type {string}
  2989. */
  2990. var Elements = Components.Elements;
  2991. /**
  2992. * Keep the root element.
  2993. *
  2994. * @type {Element}
  2995. */
  2996. var root = Splide.root;
  2997. /**
  2998. * Keep the track element.
  2999. *
  3000. * @type {Element}
  3001. */
  3002. var track;
  3003. /**
  3004. * Keep the latest options.
  3005. *
  3006. * @type {Element}
  3007. */
  3008. var options;
  3009. return {
  3010. /**
  3011. * Margin property name.
  3012. *
  3013. * @type {string}
  3014. */
  3015. margin: 'marginBottom',
  3016. /**
  3017. * Init slider styles according to options.
  3018. */
  3019. init: function init() {
  3020. options = Splide.options;
  3021. track = Elements.track;
  3022. this.gap = toPixel(root, options.gap);
  3023. var padding = options.padding;
  3024. var _padding$top = padding.top,
  3025. top = _padding$top === void 0 ? padding : _padding$top,
  3026. _padding$bottom = padding.bottom,
  3027. bottom = _padding$bottom === void 0 ? padding : _padding$bottom;
  3028. this.padding = {
  3029. top: toPixel(root, top),
  3030. bottom: toPixel(root, bottom)
  3031. };
  3032. applyStyle(track, {
  3033. paddingTop: unit(top),
  3034. paddingBottom: unit(bottom)
  3035. });
  3036. },
  3037. /**
  3038. * Return the slide width in px.
  3039. *
  3040. * @return {number} - The slide width.
  3041. */
  3042. slideWidth: function slideWidth() {
  3043. return toPixel(root, options.fixedWidth || this.width);
  3044. },
  3045. /**
  3046. * Return the slide height in px.
  3047. *
  3048. * @return {number} - The slide height.
  3049. */
  3050. slideHeight: function slideHeight() {
  3051. var height = options.fixedHeight || (this.height + this.gap) / options.perPage - this.gap;
  3052. return toPixel(root, height);
  3053. },
  3054. /**
  3055. * Return slider width without padding.
  3056. *
  3057. * @return {number} - Current slider width.
  3058. */
  3059. get width() {
  3060. return track.clientWidth;
  3061. },
  3062. /**
  3063. * Return slide height without padding.
  3064. *
  3065. * @return {number} - Slider height.
  3066. */
  3067. get height() {
  3068. var height = options.height || this.width * options.heightRatio;
  3069. exist(height, '"height" or "heightRatio" is missing.');
  3070. return toPixel(root, height) - this.padding.top - this.padding.bottom;
  3071. },
  3072. /**
  3073. * Return list width.
  3074. *
  3075. * @return {number} - Current list width.
  3076. */
  3077. get listWidth() {
  3078. return this.width;
  3079. },
  3080. /**
  3081. * Return list height.
  3082. *
  3083. * @return {number} - Current list height.
  3084. */
  3085. get listHeight() {
  3086. return (this.slideHeight() + this.gap) * Elements.total;
  3087. }
  3088. };
  3089. });
  3090. // CONCATENATED MODULE: ./src/js/utils/time.js
  3091. /**
  3092. * A package of utility functions related with time.
  3093. *
  3094. * @author Naotoshi Fujita
  3095. * @copyright Naotoshi Fujita. All rights reserved.
  3096. */
  3097. /**
  3098. * Simple throttle function that controls how often the given function is executed.
  3099. *
  3100. * @param {function} func - A function to be throttled.
  3101. * @param {number} wait - Time in millisecond for interval of execution.
  3102. *
  3103. * @return {Function} - A debounced function.
  3104. */
  3105. function throttle(func, wait) {
  3106. var timeout; // Declare function by the "function" keyword to prevent "this" from being inherited.
  3107. return function () {
  3108. if (!timeout) {
  3109. timeout = setTimeout(function () {
  3110. func();
  3111. timeout = null;
  3112. }, wait);
  3113. }
  3114. };
  3115. }
  3116. /**
  3117. * Custom setInterval function that provides progress rate as callback.
  3118. *
  3119. * @param {function} callback - A callback function fired every time the interval time passes.
  3120. * @param {number} interval - Interval duration in milliseconds.
  3121. * @param {function} progress - A callback function fired whenever the progress goes.
  3122. *
  3123. * @return {Object} - An object containing play() and pause() functions.
  3124. */
  3125. function createInterval(callback, interval, progress) {
  3126. var _window = window,
  3127. requestAnimationFrame = _window.requestAnimationFrame;
  3128. var start,
  3129. elapse,
  3130. rate,
  3131. _pause = true;
  3132. var step = function step(timestamp) {
  3133. if (!_pause) {
  3134. if (!start) {
  3135. start = timestamp;
  3136. }
  3137. elapse = timestamp - start;
  3138. rate = elapse / interval;
  3139. if (elapse >= interval) {
  3140. start = 0;
  3141. rate = 1;
  3142. callback();
  3143. }
  3144. if (progress) {
  3145. progress(rate);
  3146. }
  3147. requestAnimationFrame(step);
  3148. }
  3149. };
  3150. return {
  3151. pause: function pause() {
  3152. _pause = true;
  3153. start = 0;
  3154. },
  3155. play: function play() {
  3156. start = 0;
  3157. if (_pause) {
  3158. _pause = false;
  3159. requestAnimationFrame(step);
  3160. }
  3161. }
  3162. };
  3163. }
  3164. // CONCATENATED MODULE: ./src/js/components/layout/index.js
  3165. /**
  3166. * The component for handing slide layouts and their sizes.
  3167. *
  3168. * @author Naotoshi Fujita
  3169. * @copyright Naotoshi Fujita. All rights reserved.
  3170. */
  3171. /**
  3172. * Interval time for throttle.
  3173. *
  3174. * @type {number}
  3175. */
  3176. var THROTTLE = 100;
  3177. /**
  3178. * The component for handing slide layouts and their sizes.
  3179. *
  3180. * @param {Splide} Splide - A Splide instance.
  3181. * @param {Object} Components - An object containing components.
  3182. *
  3183. * @return {Object} - The component object.
  3184. */
  3185. /* harmony default export */ var layout = (function (Splide, Components) {
  3186. /**
  3187. * Keep the Elements component.
  3188. *
  3189. * @type {string}
  3190. */
  3191. var Elements = Components.Elements;
  3192. /**
  3193. * Layout component object.
  3194. *
  3195. * @type {Object}
  3196. */
  3197. var Layout = object_assign({
  3198. /**
  3199. * Called when the component is mounted.
  3200. */
  3201. mount: function mount() {
  3202. bind();
  3203. init();
  3204. },
  3205. /**
  3206. * Destroy.
  3207. */
  3208. destroy: function destroy() {
  3209. removeAttribute([Elements.list, Elements.track], 'style');
  3210. }
  3211. }, Splide.options.direction === TTB ? directions_vertical(Splide, Components) : directions_horizontal(Splide, Components));
  3212. /**
  3213. * Init slider styles according to options.
  3214. */
  3215. function init() {
  3216. Layout.init();
  3217. applyStyle(Splide.root, {
  3218. maxWidth: unit(Splide.options.width)
  3219. });
  3220. Elements.each(function (Slide) {
  3221. Slide.slide.style[Layout.margin] = unit(Layout.gap);
  3222. });
  3223. resize();
  3224. }
  3225. /**
  3226. * Listen the resize native event with throttle.
  3227. * Initialize when the component is mounted or options are updated.
  3228. */
  3229. function bind() {
  3230. Splide.on('resize load', throttle(function () {
  3231. Splide.emit('resize');
  3232. }, THROTTLE), window).on('resize', resize).on('updated refresh', init);
  3233. }
  3234. /**
  3235. * Resize the list and slides including clones.
  3236. */
  3237. function resize() {
  3238. applyStyle(Elements.list, {
  3239. width: unit(Layout.listWidth),
  3240. height: unit(Layout.listHeight)
  3241. });
  3242. applyStyle(Elements.track, {
  3243. height: unit(Layout.height)
  3244. });
  3245. var slideHeight = unit(Layout.slideHeight());
  3246. Elements.each(function (Slide) {
  3247. applyStyle(Slide.container, {
  3248. height: slideHeight
  3249. });
  3250. applyStyle(Slide.slide, {
  3251. width: Splide.options.autoWidth ? null : unit(Layout.slideWidth(Slide.index)),
  3252. height: Slide.container ? null : slideHeight
  3253. });
  3254. });
  3255. }
  3256. return Layout;
  3257. });
  3258. // CONCATENATED MODULE: ./src/js/components/drag/index.js
  3259. /**
  3260. * The component for supporting mouse drag and swipe.
  3261. *
  3262. * @author Naotoshi Fujita
  3263. * @copyright Naotoshi Fujita. All rights reserved.
  3264. */
  3265. var abs = Math.abs;
  3266. /**
  3267. * Adjust how much the track can be pulled on the first or last page.
  3268. * The larger number this is, the farther the track moves.
  3269. * This should be around 5 - 9.
  3270. *
  3271. * @type {number}
  3272. */
  3273. var FRICTION_REDUCER = 7;
  3274. /**
  3275. * To start dragging the track, the drag angle must be less than this threshold.
  3276. *
  3277. * @type {number}
  3278. */
  3279. var ANGLE_THRESHOLD = 30;
  3280. /**
  3281. * When a drag distance is over this value, the action will be treated as "swipe", not "flick".
  3282. *
  3283. * @type {number}
  3284. */
  3285. var SWIPE_THRESHOLD = 150;
  3286. /**
  3287. * The component supporting mouse drag and swipe.
  3288. *
  3289. * @param {Splide} Splide - A Splide instance.
  3290. * @param {Object} Components - An object containing components.
  3291. *
  3292. * @return {Object} - The component object.
  3293. */
  3294. /* harmony default export */ var drag = (function (Splide, Components) {
  3295. /**
  3296. * Store the Move component.
  3297. *
  3298. * @type {Object}
  3299. */
  3300. var Track = Components.Track;
  3301. /**
  3302. * Store the Controller component.
  3303. *
  3304. * @type {Object}
  3305. */
  3306. var Controller = Components.Controller;
  3307. /**
  3308. * Coordinate of the track on starting drag.
  3309. *
  3310. * @type {Object}
  3311. */
  3312. var startCoord;
  3313. /**
  3314. * Analyzed info on starting drag.
  3315. *
  3316. * @type {Object|null}
  3317. */
  3318. var startInfo;
  3319. /**
  3320. * Analyzed info being updated while dragging/swiping.
  3321. *
  3322. * @type {Object}
  3323. */
  3324. var currentInfo;
  3325. /**
  3326. * Determine whether slides are being dragged or not.
  3327. *
  3328. * @type {boolean}
  3329. */
  3330. var isDragging;
  3331. /**
  3332. * Whether the slider direction is vertical or not.
  3333. *
  3334. * @type {boolean}
  3335. */
  3336. var isVertical = Splide.options.direction === TTB;
  3337. /**
  3338. * Axis for the direction.
  3339. *
  3340. * @type {string}
  3341. */
  3342. var axis = isVertical ? 'y' : 'x';
  3343. /**
  3344. * Drag component object.
  3345. *
  3346. * @type {Object}
  3347. */
  3348. var Drag = {
  3349. /**
  3350. * Mount only when the drag option is true.
  3351. *
  3352. * @type {boolean}
  3353. */
  3354. required: Splide.options.drag,
  3355. /**
  3356. * Whether dragging is disabled or not.
  3357. *
  3358. * @type {boolean}
  3359. */
  3360. disabled: false,
  3361. /**
  3362. * Called when the component is mounted.
  3363. */
  3364. mount: function mount() {
  3365. var list = Components.Elements.list;
  3366. Splide.on('touchstart mousedown', start, list).on('touchmove mousemove', move, list, {
  3367. passive: false
  3368. }).on('touchend touchcancel mouseleave mouseup dragend', end, list).on('mounted refresh', function () {
  3369. // Prevent dragging an image or anchor itself.
  3370. each(list.querySelectorAll('img, a'), function (elm) {
  3371. Splide.off('dragstart', elm).on('dragstart', function (e) {
  3372. e.preventDefault();
  3373. }, elm, {
  3374. passive: false
  3375. });
  3376. });
  3377. });
  3378. }
  3379. };
  3380. /**
  3381. * Called when the track starts to be dragged.
  3382. *
  3383. * @param {TouchEvent|MouseEvent} e - TouchEvent or MouseEvent object.
  3384. */
  3385. function start(e) {
  3386. if (!Drag.disabled && !isDragging && Splide.State.is(IDLE)) {
  3387. startCoord = Track.toCoord(Track.position);
  3388. startInfo = analyze(e, {});
  3389. currentInfo = startInfo;
  3390. }
  3391. }
  3392. /**
  3393. * Called while the track being dragged.
  3394. *
  3395. * @param {TouchEvent|MouseEvent} e - TouchEvent or MouseEvent object.
  3396. */
  3397. function move(e) {
  3398. if (startInfo) {
  3399. currentInfo = analyze(e, startInfo);
  3400. if (isDragging) {
  3401. if (e.cancelable) {
  3402. e.preventDefault();
  3403. }
  3404. var position = startCoord[axis] + currentInfo.offset[axis];
  3405. Track.translate(resist(position));
  3406. } else {
  3407. if (shouldMove(currentInfo)) {
  3408. Splide.emit('drag', startInfo);
  3409. isDragging = true;
  3410. }
  3411. }
  3412. }
  3413. }
  3414. /**
  3415. * Determine whether to start moving the track or not by drag angle.
  3416. *
  3417. * @param {Object} info - An information object.
  3418. *
  3419. * @return {boolean} - True if the track should be moved or false if not.
  3420. */
  3421. function shouldMove(_ref) {
  3422. var offset = _ref.offset;
  3423. if (Splide.State.is(IDLE)) {
  3424. var angle = Math.atan(abs(offset.y) / abs(offset.x)) * 180 / Math.PI;
  3425. if (isVertical) {
  3426. angle = 90 - angle;
  3427. }
  3428. return angle < ANGLE_THRESHOLD;
  3429. }
  3430. return false;
  3431. }
  3432. /**
  3433. * Resist dragging the track on the first/last page because there is no more.
  3434. *
  3435. * @param {number} position - A position being applied to the track.
  3436. *
  3437. * @return {Object} - Adjusted position.
  3438. */
  3439. function resist(position) {
  3440. if (!Splide.is(LOOP)) {
  3441. var sign = Track.sign;
  3442. var _start = sign * Track.trim(Track.toPosition(0));
  3443. var _end = sign * Track.trim(Track.toPosition(Controller.edgeIndex));
  3444. position *= sign;
  3445. if (position < _start) {
  3446. position = _start - FRICTION_REDUCER * Math.log(_start - position);
  3447. } else if (position > _end) {
  3448. position = _end + FRICTION_REDUCER * Math.log(position - _end);
  3449. }
  3450. position *= sign;
  3451. }
  3452. return position;
  3453. }
  3454. /**
  3455. * Called when dragging ends.
  3456. */
  3457. function end() {
  3458. startInfo = null;
  3459. if (isDragging) {
  3460. Splide.emit('dragged', currentInfo);
  3461. go(currentInfo);
  3462. isDragging = false;
  3463. }
  3464. }
  3465. /**
  3466. * Go to the slide determined by the analyzed data.
  3467. *
  3468. * @param {Object} info - An info object.
  3469. */
  3470. function go(info) {
  3471. var velocity = info.velocity[axis];
  3472. var absV = abs(velocity);
  3473. if (absV > 0) {
  3474. var Layout = Components.Layout;
  3475. var options = Splide.options;
  3476. var sign = velocity < 0 ? -1 : 1;
  3477. var destination = Track.position;
  3478. if (absV > options.flickThreshold && abs(info.offset[axis]) < SWIPE_THRESHOLD) {
  3479. destination += sign * Math.min(absV * options.flickPower, Layout.width * (options.flickMaxPages || 1));
  3480. }
  3481. var index = Track.toIndex(destination); // Do not allow the track to go to a previous position.
  3482. if (index === Splide.index) {
  3483. index += sign * Track.sign;
  3484. }
  3485. if (!Splide.is(LOOP)) {
  3486. index = between(index, 0, Controller.edgeIndex);
  3487. }
  3488. Controller.go(index, options.isNavigation);
  3489. }
  3490. }
  3491. /**
  3492. * Analyze the given event object and return important information for handling swipe behavior.
  3493. *
  3494. * @param {Event} e - Touch or Mouse event object.
  3495. * @param {Object} startInfo - Information analyzed on start for calculating difference from the current one.
  3496. *
  3497. * @return {Object} - An object containing analyzed information, such as offset, velocity, etc.
  3498. */
  3499. function analyze(e, startInfo) {
  3500. var timeStamp = e.timeStamp,
  3501. touches = e.touches;
  3502. var _ref2 = touches ? touches[0] : e,
  3503. clientX = _ref2.clientX,
  3504. clientY = _ref2.clientY;
  3505. var _ref3 = startInfo.to || {},
  3506. _ref3$x = _ref3.x,
  3507. fromX = _ref3$x === void 0 ? clientX : _ref3$x,
  3508. _ref3$y = _ref3.y,
  3509. fromY = _ref3$y === void 0 ? clientY : _ref3$y;
  3510. var startTime = startInfo.time || 0;
  3511. var offset = {
  3512. x: clientX - fromX,
  3513. y: clientY - fromY
  3514. };
  3515. var duration = timeStamp - startTime;
  3516. var velocity = {
  3517. x: offset.x / duration,
  3518. y: offset.y / duration
  3519. };
  3520. return {
  3521. to: {
  3522. x: clientX,
  3523. y: clientY
  3524. },
  3525. offset: offset,
  3526. time: timeStamp,
  3527. velocity: velocity
  3528. };
  3529. }
  3530. return Drag;
  3531. });
  3532. // CONCATENATED MODULE: ./src/js/components/click/index.js
  3533. /**
  3534. * The component for handling a click event.
  3535. *
  3536. * @author Naotoshi Fujita
  3537. * @copyright Naotoshi Fujita. All rights reserved.
  3538. */
  3539. /**
  3540. * The component for handling a click event.
  3541. * Click should be disabled during drag/swipe.
  3542. *
  3543. * @param {Splide} Splide - A Splide instance.
  3544. * @param {Object} Components - An object containing components.
  3545. *
  3546. * @return {Object} - The component object.
  3547. */
  3548. /* harmony default export */ var click = (function (Splide, Components) {
  3549. /**
  3550. * Whether click is disabled or not.
  3551. *
  3552. * @type {boolean}
  3553. */
  3554. var disabled = false;
  3555. /**
  3556. * Click component object.
  3557. *
  3558. * @type {Object}
  3559. */
  3560. var Click = {
  3561. /**
  3562. * Mount only when the drag is activated and the slide type is not "fade".
  3563. *
  3564. * @type {boolean}
  3565. */
  3566. required: Splide.options.drag && !Splide.is(FADE),
  3567. /**
  3568. * Called when the component is mounted.
  3569. */
  3570. mount: function mount() {
  3571. Splide.on('click', onClick, Components.Elements.track, {
  3572. capture: true
  3573. }).on('drag', function () {
  3574. disabled = true;
  3575. }).on('moved', function () {
  3576. disabled = false;
  3577. });
  3578. }
  3579. };
  3580. /**
  3581. * Called when a track element is clicked.
  3582. *
  3583. * @param {Event} e - A click event.
  3584. */
  3585. function onClick(e) {
  3586. if (disabled) {
  3587. e.preventDefault();
  3588. e.stopPropagation();
  3589. e.stopImmediatePropagation();
  3590. }
  3591. }
  3592. return Click;
  3593. });
  3594. // CONCATENATED MODULE: ./src/js/components/autoplay/index.js
  3595. /**
  3596. * The component for playing slides automatically.
  3597. *
  3598. * @author Naotoshi Fujita
  3599. * @copyright Naotoshi Fujita. All rights reserved.
  3600. */
  3601. /**
  3602. * Set of pause flags.
  3603. */
  3604. var PAUSE_FLAGS = {
  3605. HOVER: 1,
  3606. FOCUS: 2,
  3607. MANUAL: 3
  3608. };
  3609. /**
  3610. * The component for playing slides automatically.
  3611. *
  3612. * @param {Splide} Splide - A Splide instance.
  3613. * @param {Object} Components - An object containing components.
  3614. * @param {string} name - A component name as a lowercase string.
  3615. *
  3616. * @return {Object} - The component object.
  3617. */
  3618. /* harmony default export */ var components_autoplay = (function (Splide, Components, name) {
  3619. /**
  3620. * Store pause flags.
  3621. *
  3622. * @type {Array}
  3623. */
  3624. var flags = [];
  3625. /**
  3626. * Store an interval object.
  3627. *
  3628. * @type {Object};
  3629. */
  3630. var interval;
  3631. /**
  3632. * Keep the Elements component.
  3633. *
  3634. * @type {string}
  3635. */
  3636. var Elements = Components.Elements;
  3637. /**
  3638. * Autoplay component object.
  3639. *
  3640. * @type {Object}
  3641. */
  3642. var Autoplay = {
  3643. /**
  3644. * Required only when the autoplay option is true.
  3645. *
  3646. * @type {boolean}
  3647. */
  3648. required: Splide.options.autoplay,
  3649. /**
  3650. * Called when the component is mounted.
  3651. * Note that autoplay starts only if there are slides over perPage number.
  3652. */
  3653. mount: function mount() {
  3654. var options = Splide.options;
  3655. if (Elements.slides.length > options.perPage) {
  3656. interval = createInterval(function () {
  3657. Splide.go('>');
  3658. }, options.interval, function (rate) {
  3659. Splide.emit(name + ":playing", rate);
  3660. if (Elements.bar) {
  3661. applyStyle(Elements.bar, {
  3662. width: rate * 100 + "%"
  3663. });
  3664. }
  3665. });
  3666. bind();
  3667. this.play();
  3668. }
  3669. },
  3670. /**
  3671. * Start autoplay.
  3672. *
  3673. * @param {number} flag - A pause flag to be removed.
  3674. */
  3675. play: function play(flag) {
  3676. if (flag === void 0) {
  3677. flag = 0;
  3678. }
  3679. flags = flags.filter(function (f) {
  3680. return f !== flag;
  3681. });
  3682. if (!flags.length) {
  3683. Splide.emit(name + ":play");
  3684. interval.play();
  3685. }
  3686. },
  3687. /**
  3688. * Pause autoplay.
  3689. * Note that Array.includes is not supported by IE.
  3690. *
  3691. * @param {number} flag - A pause flag to be added.
  3692. */
  3693. pause: function pause(flag) {
  3694. if (flag === void 0) {
  3695. flag = 0;
  3696. }
  3697. interval.pause();
  3698. if (flags.indexOf(flag) === -1) {
  3699. flags.push(flag);
  3700. }
  3701. if (flags.length === 1) {
  3702. Splide.emit(name + ":pause");
  3703. }
  3704. }
  3705. };
  3706. /**
  3707. * Listen some events.
  3708. */
  3709. function bind() {
  3710. var options = Splide.options;
  3711. var sibling = Splide.sibling;
  3712. var elms = [Splide.root, sibling ? sibling.root : null];
  3713. if (options.pauseOnHover) {
  3714. switchOn(elms, 'mouseleave', PAUSE_FLAGS.HOVER, true);
  3715. switchOn(elms, 'mouseenter', PAUSE_FLAGS.HOVER, false);
  3716. }
  3717. if (options.pauseOnFocus) {
  3718. switchOn(elms, 'focusout', PAUSE_FLAGS.FOCUS, true);
  3719. switchOn(elms, 'focusin', PAUSE_FLAGS.FOCUS, false);
  3720. }
  3721. Splide.on('click', function () {
  3722. // Need to be removed a focus flag at first.
  3723. Autoplay.play(PAUSE_FLAGS.FOCUS);
  3724. Autoplay.play(PAUSE_FLAGS.MANUAL);
  3725. }, Elements.play).on('move refresh', function () {
  3726. Autoplay.play();
  3727. }) // Rewind the timer.
  3728. .on('destroy', function () {
  3729. Autoplay.pause();
  3730. });
  3731. switchOn([Elements.pause], 'click', PAUSE_FLAGS.MANUAL, false);
  3732. }
  3733. /**
  3734. * Play or pause on the given event.
  3735. *
  3736. * @param {Element[]} elms - Elements.
  3737. * @param {string} event - An event name or names.
  3738. * @param {number} flag - A pause flag defined on the top.
  3739. * @param {boolean} play - Determine whether to play or pause.
  3740. */
  3741. function switchOn(elms, event, flag, play) {
  3742. for (var i in elms) {
  3743. Splide.on(event, function () {
  3744. Autoplay[play ? 'play' : 'pause'](flag);
  3745. }, elms[i]);
  3746. }
  3747. }
  3748. return Autoplay;
  3749. });
  3750. // CONCATENATED MODULE: ./src/js/components/cover/index.js
  3751. /**
  3752. * The component for change an img element to background image of its wrapper.
  3753. *
  3754. * @author Naotoshi Fujita
  3755. * @copyright Naotoshi Fujita. All rights reserved.
  3756. */
  3757. /**
  3758. * The component for change an img element to background image of its wrapper.
  3759. *
  3760. * @param {Splide} Splide - A Splide instance.
  3761. * @param {Object} Components - An object containing components.
  3762. *
  3763. * @return {Object} - The component object.
  3764. */
  3765. /* harmony default export */ var components_cover = (function (Splide, Components) {
  3766. /**
  3767. * Hold options.
  3768. *
  3769. * @type {Object}
  3770. */
  3771. var options = Splide.options;
  3772. /**
  3773. * Cover component object.
  3774. *
  3775. * @type {Object}
  3776. */
  3777. var Cover = {
  3778. /**
  3779. * Required only when "cover" option is true.
  3780. *
  3781. * @type {boolean}
  3782. */
  3783. required: options.cover,
  3784. /**
  3785. * Called when the component is mounted.
  3786. */
  3787. mount: function mount() {
  3788. Splide.on('lazyload:loaded', function (img) {
  3789. cover(img, false);
  3790. });
  3791. Splide.on('mounted updated refresh', function () {
  3792. return apply(false);
  3793. });
  3794. },
  3795. /**
  3796. * Destroy.
  3797. */
  3798. destroy: function destroy() {
  3799. apply(true);
  3800. }
  3801. };
  3802. /**
  3803. * Apply "cover" to all slides.
  3804. *
  3805. * @param {boolean} uncover - If true, "cover" will be clear.
  3806. */
  3807. function apply(uncover) {
  3808. Components.Elements.each(function (Slide) {
  3809. var img = child(Slide.slide, 'img') || child(Slide.container, 'img');
  3810. if (img && img.src) {
  3811. cover(img, uncover);
  3812. }
  3813. });
  3814. }
  3815. /**
  3816. * Set background image of the parent element, using source of the given image element.
  3817. *
  3818. * @param {Element} img - An image element.
  3819. * @param {boolean} uncover - Reset "cover".
  3820. */
  3821. function cover(img, uncover) {
  3822. applyStyle(img.parentElement, {
  3823. background: uncover ? '' : "center/cover no-repeat url(\"" + img.src + "\")"
  3824. });
  3825. applyStyle(img, {
  3826. display: uncover ? '' : 'none'
  3827. });
  3828. }
  3829. return Cover;
  3830. });
  3831. // CONCATENATED MODULE: ./src/js/components/arrows/path.js
  3832. /**
  3833. * Export vector path for an arrow.
  3834. *
  3835. * @author Naotoshi Fujita
  3836. * @copyright Naotoshi Fujita. All rights reserved.
  3837. */
  3838. /**
  3839. * Namespace definition for SVG element.
  3840. *
  3841. * @type {string}
  3842. */
  3843. var XML_NAME_SPACE = 'http://www.w3.org/2000/svg';
  3844. /**
  3845. * The arrow vector path.
  3846. *
  3847. * @type {number}
  3848. */
  3849. var PATH = 'm15.5 0.932-4.3 4.38 14.5 14.6-14.5 14.5 4.3 4.4 14.6-14.6 4.4-4.3-4.4-4.4-14.6-14.6z';
  3850. /**
  3851. * SVG width and height.
  3852. *
  3853. * @type {number}
  3854. */
  3855. var SIZE = 40;
  3856. // CONCATENATED MODULE: ./src/js/components/arrows/index.js
  3857. /**
  3858. * The component for appending prev/next arrows.
  3859. *
  3860. * @author Naotoshi Fujita
  3861. * @copyright Naotoshi Fujita. All rights reserved.
  3862. */
  3863. /**
  3864. * The component for appending prev/next arrows.
  3865. *
  3866. * @param {Splide} Splide - A Splide instance.
  3867. * @param {Object} Components - An object containing components.
  3868. * @param {string} name - A component name as a lowercase string.
  3869. *
  3870. * @return {Object} - The component object.
  3871. */
  3872. /* harmony default export */ var components_arrows = (function (Splide, Components, name) {
  3873. /**
  3874. * Previous arrow element.
  3875. *
  3876. * @type {Element|undefined}
  3877. */
  3878. var prev;
  3879. /**
  3880. * Next arrow element.
  3881. *
  3882. * @type {Element|undefined}
  3883. */
  3884. var next;
  3885. /**
  3886. * Store the class list.
  3887. *
  3888. * @type {Object}
  3889. */
  3890. var classes = Splide.classes;
  3891. /**
  3892. * Hold the root element.
  3893. *
  3894. * @type {Element}
  3895. */
  3896. var root = Splide.root;
  3897. /**
  3898. * Whether arrows are created programmatically or not.
  3899. *
  3900. * @type {boolean}
  3901. */
  3902. var created;
  3903. /**
  3904. * Hold the Elements component.
  3905. *
  3906. * @type {Object}
  3907. */
  3908. var Elements = Components.Elements;
  3909. /**
  3910. * Arrows component object.
  3911. *
  3912. * @type {Object}
  3913. */
  3914. var Arrows = {
  3915. /**
  3916. * Required when the arrows option is true.
  3917. *
  3918. * @type {boolean}
  3919. */
  3920. required: Splide.options.arrows,
  3921. /**
  3922. * Called when the component is mounted.
  3923. */
  3924. mount: function mount() {
  3925. // Attempt to get arrows from HTML source.
  3926. prev = Elements.arrows.prev;
  3927. next = Elements.arrows.next; // If arrows were not found in HTML, let's generate them.
  3928. if ((!prev || !next) && Splide.options.arrows) {
  3929. prev = createArrow(true);
  3930. next = createArrow(false);
  3931. created = true;
  3932. appendArrows();
  3933. }
  3934. if (prev && next) {
  3935. bind();
  3936. }
  3937. this.arrows = {
  3938. prev: prev,
  3939. next: next
  3940. };
  3941. },
  3942. /**
  3943. * Called after all components are mounted.
  3944. */
  3945. mounted: function mounted() {
  3946. Splide.emit(name + ":mounted", prev, next);
  3947. },
  3948. /**
  3949. * Destroy.
  3950. */
  3951. destroy: function destroy() {
  3952. removeAttribute([prev, next], 'disabled');
  3953. if (created) {
  3954. dom_remove(prev.parentElement);
  3955. }
  3956. }
  3957. };
  3958. /**
  3959. * Listen native and custom events.
  3960. */
  3961. function bind() {
  3962. Splide.on('click', function () {
  3963. return onClick(true);
  3964. }, prev).on('click', function () {
  3965. return onClick(false);
  3966. }, next).on('mounted move updated refresh', updateDisabled);
  3967. }
  3968. /**
  3969. * Called when an arrow is clicked.
  3970. *
  3971. * @param {boolean} prev - If true, the previous arrow is clicked.
  3972. */
  3973. function onClick(prev) {
  3974. var perMove = Splide.options.perMove;
  3975. Splide.go(perMove ? "" + (prev ? '-' : '+') + perMove : prev ? '<' : '>');
  3976. }
  3977. /**
  3978. * Update a disabled attribute.
  3979. */
  3980. function updateDisabled() {
  3981. var _Components$Controlle = Components.Controller,
  3982. prevIndex = _Components$Controlle.prevIndex,
  3983. nextIndex = _Components$Controlle.nextIndex;
  3984. var isEnough = Splide.length > Splide.options.perPage || Splide.is(LOOP);
  3985. prev.disabled = prevIndex < 0 || !isEnough;
  3986. next.disabled = nextIndex < 0 || !isEnough;
  3987. Splide.emit(name + ":updated", prev, next, prevIndex, nextIndex);
  3988. }
  3989. /**
  3990. * Create a wrapper element and append arrows.
  3991. */
  3992. function appendArrows() {
  3993. var wrapper = create('div', {
  3994. "class": classes.arrows
  3995. });
  3996. append(wrapper, prev);
  3997. append(wrapper, next);
  3998. var slider = Elements.slider;
  3999. var parent = Splide.options.arrows === 'slider' && slider ? slider : root;
  4000. before(wrapper, parent.firstElementChild);
  4001. }
  4002. /**
  4003. * Create an arrow element.
  4004. *
  4005. * @param {boolean} prev - Determine to create a prev arrow or next arrow.
  4006. *
  4007. * @return {Element} - A created arrow element.
  4008. */
  4009. function createArrow(prev) {
  4010. var arrow = "<button class=\"" + classes.arrow + " " + (prev ? classes.prev : classes.next) + "\" type=\"button\">" + ("<svg xmlns=\"" + XML_NAME_SPACE + "\"\tviewBox=\"0 0 " + SIZE + " " + SIZE + "\"\twidth=\"" + SIZE + "\"\theight=\"" + SIZE + "\">") + ("<path d=\"" + (Splide.options.arrowPath || PATH) + "\" />");
  4011. return domify(arrow);
  4012. }
  4013. return Arrows;
  4014. });
  4015. // CONCATENATED MODULE: ./src/js/components/pagination/index.js
  4016. /**
  4017. * The component for handling pagination
  4018. *
  4019. * @author Naotoshi Fujita
  4020. * @copyright Naotoshi Fujita. All rights reserved.
  4021. */
  4022. /**
  4023. * The event name for updating some attributes of pagination nodes.
  4024. *
  4025. * @type {string}
  4026. */
  4027. var ATTRIBUTES_UPDATE_EVENT = 'move.page';
  4028. /**
  4029. * The event name for recreating pagination.
  4030. *
  4031. * @type {string}
  4032. */
  4033. var UPDATE_EVENT = 'updated.page refresh.page';
  4034. /**
  4035. * The component for handling pagination
  4036. *
  4037. * @param {Splide} Splide - A Splide instance.
  4038. * @param {Object} Components - An object containing components.
  4039. * @param {string} name - A component name as a lowercase string.
  4040. *
  4041. * @return {Object} - The component object.
  4042. */
  4043. /* harmony default export */ var pagination = (function (Splide, Components, name) {
  4044. /**
  4045. * Store all data for pagination.
  4046. * - list: A list element.
  4047. * - items: An array that contains objects(li, button, index, page).
  4048. *
  4049. * @type {Object}
  4050. */
  4051. var data = {};
  4052. /**
  4053. * Hold the Elements component.
  4054. *
  4055. * @type {Object}
  4056. */
  4057. var Elements = Components.Elements;
  4058. /**
  4059. * Pagination component object.
  4060. *
  4061. * @type {Object}
  4062. */
  4063. var Pagination = {
  4064. /**
  4065. * Required only when the pagination option is true.
  4066. *
  4067. * @type {boolean}
  4068. */
  4069. required: Splide.options.pagination,
  4070. /**
  4071. * Called when the component is mounted.
  4072. */
  4073. mount: function mount() {
  4074. data = createPagination();
  4075. var slider = Elements.slider;
  4076. var parent = Splide.options.pagination === 'slider' && slider ? slider : Splide.root;
  4077. append(parent, data.list);
  4078. bind();
  4079. },
  4080. /**
  4081. * Called after all components are mounted.
  4082. */
  4083. mounted: function mounted() {
  4084. var index = Splide.index;
  4085. Splide.emit(name + ":mounted", data, this.getItem(index));
  4086. update(index, -1);
  4087. },
  4088. /**
  4089. * Destroy the pagination.
  4090. * Be aware that node.remove() is not supported by IE.
  4091. */
  4092. destroy: function destroy() {
  4093. dom_remove(data.list);
  4094. if (data.items) {
  4095. data.items.forEach(function (item) {
  4096. Splide.off('click', item.button);
  4097. });
  4098. }
  4099. Splide.off(ATTRIBUTES_UPDATE_EVENT).off(UPDATE_EVENT);
  4100. data = {};
  4101. },
  4102. /**
  4103. * Return an item by index.
  4104. *
  4105. * @param {number} index - A slide index.
  4106. *
  4107. * @return {Object|undefined} - An item object on success or undefined on failure.
  4108. */
  4109. getItem: function getItem(index) {
  4110. return data.items[Components.Controller.toPage(index)];
  4111. },
  4112. /**
  4113. * Return object containing pagination data.
  4114. *
  4115. * @return {Object} - Pagination data including list and items.
  4116. */
  4117. get data() {
  4118. return data;
  4119. }
  4120. };
  4121. /**
  4122. * Listen some events.
  4123. */
  4124. function bind() {
  4125. Splide.on(ATTRIBUTES_UPDATE_EVENT, update).on(UPDATE_EVENT, function () {
  4126. Pagination.destroy();
  4127. if (Splide.options.pagination) {
  4128. Pagination.mount();
  4129. Pagination.mounted();
  4130. }
  4131. });
  4132. }
  4133. /**
  4134. * Update attributes.
  4135. *
  4136. * @param {number} index - Active index.
  4137. * @param {number} prevIndex - Prev index.
  4138. */
  4139. function update(index, prevIndex) {
  4140. var prev = Pagination.getItem(prevIndex);
  4141. var curr = Pagination.getItem(index);
  4142. var active = STATUS_CLASSES.active;
  4143. if (prev) {
  4144. removeClass(prev.button, active);
  4145. }
  4146. if (curr) {
  4147. addClass(curr.button, active);
  4148. }
  4149. Splide.emit(name + ":updated", data, prev, curr);
  4150. }
  4151. /**
  4152. * Create a wrapper and button elements.
  4153. *
  4154. * @return {Object} - An object contains all data.
  4155. */
  4156. function createPagination() {
  4157. var options = Splide.options;
  4158. var classes = Splide.classes;
  4159. var list = create('ul', {
  4160. "class": classes.pagination
  4161. });
  4162. var items = Elements.getSlides(false).filter(function (Slide) {
  4163. return options.focus !== false || Slide.index % options.perPage === 0;
  4164. }).map(function (Slide, page) {
  4165. var li = create('li', {});
  4166. var button = create('button', {
  4167. "class": classes.page,
  4168. type: 'button'
  4169. });
  4170. append(li, button);
  4171. append(list, li);
  4172. Splide.on('click', function () {
  4173. Splide.go(">" + page);
  4174. }, button);
  4175. return {
  4176. li: li,
  4177. button: button,
  4178. page: page,
  4179. Slides: Elements.getSlidesByPage(page)
  4180. };
  4181. });
  4182. return {
  4183. list: list,
  4184. items: items
  4185. };
  4186. }
  4187. return Pagination;
  4188. });
  4189. // CONCATENATED MODULE: ./src/js/components/lazyload/index.js
  4190. /**
  4191. * The component for loading slider images lazily.
  4192. *
  4193. * @author Naotoshi Fujita
  4194. * @copyright Naotoshi Fujita. All rights reserved.
  4195. */
  4196. /**
  4197. * The name for a data attribute.
  4198. *
  4199. * @type {string}
  4200. */
  4201. var SRC_DATA_NAME = 'data-splide-lazy';
  4202. /**
  4203. * The component for loading slider images lazily.
  4204. *
  4205. * @param {Splide} Splide - A Splide instance.
  4206. * @param {Object} Components - An object containing components.
  4207. * @param {string} name - A component name as a lowercase string.
  4208. *
  4209. * @return {Object} - The component object.
  4210. */
  4211. /* harmony default export */ var lazyload = (function (Splide, Components, name) {
  4212. /**
  4213. * Next index for sequential loading.
  4214. *
  4215. * @type {number}
  4216. */
  4217. var nextIndex;
  4218. /**
  4219. * Store objects containing an img element and a Slide object.
  4220. *
  4221. * @type {Object[]}
  4222. */
  4223. var images;
  4224. /**
  4225. * Store the options.
  4226. *
  4227. * @type {Object}
  4228. */
  4229. var options = Splide.options;
  4230. /**
  4231. * Whether to load images sequentially or not.
  4232. *
  4233. * @type {boolean}
  4234. */
  4235. var isSequential = options.lazyLoad === 'sequential';
  4236. /**
  4237. * Lazyload component object.
  4238. *
  4239. * @type {Object}
  4240. */
  4241. var Lazyload = {
  4242. /**
  4243. * Mount only when the lazyload option is provided.
  4244. *
  4245. * @type {boolean}
  4246. */
  4247. required: options.lazyLoad,
  4248. /**
  4249. * Called when the component is mounted.
  4250. */
  4251. mount: function mount() {
  4252. Splide.on('mounted refresh', function () {
  4253. init();
  4254. Components.Elements.each(function (Slide) {
  4255. each(Slide.slide.querySelectorAll("[" + SRC_DATA_NAME + "]"), function (img) {
  4256. if (!img.src) {
  4257. images.push({
  4258. img: img,
  4259. Slide: Slide
  4260. });
  4261. applyStyle(img, {
  4262. display: 'none'
  4263. });
  4264. }
  4265. });
  4266. });
  4267. if (isSequential) {
  4268. loadNext();
  4269. }
  4270. });
  4271. if (!isSequential) {
  4272. Splide.on("mounted refresh moved." + name, check);
  4273. }
  4274. },
  4275. /**
  4276. * Destroy.
  4277. */
  4278. destroy: init
  4279. };
  4280. /**
  4281. * Initialize parameters.
  4282. */
  4283. function init() {
  4284. images = [];
  4285. nextIndex = 0;
  4286. }
  4287. /**
  4288. * Check how close each image is from the active slide and
  4289. * determine whether to start loading or not, according to the distance.
  4290. *
  4291. * @param {number} index - Current index.
  4292. */
  4293. function check(index) {
  4294. index = isNaN(index) ? Splide.index : index;
  4295. images = images.filter(function (image) {
  4296. if (image.Slide.isWithin(index, options.perPage * (options.preloadPages + 1))) {
  4297. load(image.img, image.Slide);
  4298. return false;
  4299. }
  4300. return true;
  4301. }); // Unbind if all images are loaded.
  4302. if (!images[0]) {
  4303. Splide.off("moved." + name);
  4304. }
  4305. }
  4306. /**
  4307. * Start loading an image.
  4308. * Creating a clone of the image element since setting src attribute directly to it
  4309. * often occurs 'hitch', blocking some other processes of a browser.
  4310. *
  4311. * @param {Element} img - An image element.
  4312. * @param {Object} Slide - A Slide object.
  4313. */
  4314. function load(img, Slide) {
  4315. addClass(Slide.slide, STATUS_CLASSES.loading);
  4316. var spinner = create('span', {
  4317. "class": Splide.classes.spinner
  4318. });
  4319. append(img.parentElement, spinner);
  4320. img.onload = function () {
  4321. loaded(img, spinner, Slide, false);
  4322. };
  4323. img.onerror = function () {
  4324. loaded(img, spinner, Slide, true);
  4325. };
  4326. setAttribute(img, 'src', getAttribute(img, SRC_DATA_NAME));
  4327. }
  4328. /**
  4329. * Start loading a next image in images array.
  4330. */
  4331. function loadNext() {
  4332. if (nextIndex < images.length) {
  4333. var image = images[nextIndex];
  4334. load(image.img, image.Slide);
  4335. }
  4336. nextIndex++;
  4337. }
  4338. /**
  4339. * Called just after the image was loaded or loading was aborted by some error.
  4340. *
  4341. * @param {Element} img - An image element.
  4342. * @param {Element} spinner - A spinner element.
  4343. * @param {Object} Slide - A Slide object.
  4344. * @param {boolean} error - True if the image was loaded successfully or false on error.
  4345. */
  4346. function loaded(img, spinner, Slide, error) {
  4347. removeClass(Slide.slide, STATUS_CLASSES.loading);
  4348. if (!error) {
  4349. dom_remove(spinner);
  4350. applyStyle(img, {
  4351. display: ''
  4352. });
  4353. Splide.emit(name + ":loaded", img).emit('resize');
  4354. }
  4355. if (isSequential) {
  4356. loadNext();
  4357. }
  4358. }
  4359. return Lazyload;
  4360. });
  4361. // CONCATENATED MODULE: ./src/js/components/keyboard/index.js
  4362. /**
  4363. * The component for controlling slides via keyboard.
  4364. *
  4365. * @author Naotoshi Fujita
  4366. * @copyright Naotoshi Fujita. All rights reserved.
  4367. */
  4368. /**
  4369. * Map a key to a slide control.
  4370. *
  4371. * @type {Object}
  4372. */
  4373. var KEY_MAP = {
  4374. ltr: {
  4375. ArrowLeft: '<',
  4376. ArrowRight: '>',
  4377. // For IE.
  4378. Left: '<',
  4379. Right: '>'
  4380. },
  4381. rtl: {
  4382. ArrowLeft: '>',
  4383. ArrowRight: '<',
  4384. // For IE.
  4385. Left: '>',
  4386. Right: '<'
  4387. },
  4388. ttb: {
  4389. ArrowUp: '<',
  4390. ArrowDown: '>',
  4391. // For IE.
  4392. Up: '<',
  4393. Down: '>'
  4394. }
  4395. };
  4396. /**
  4397. * The component for controlling slides via keyboard.
  4398. *
  4399. * @param {Splide} Splide - A Splide instance.
  4400. *
  4401. * @return {Object} - The component object.
  4402. */
  4403. /* harmony default export */ var keyboard = (function (Splide) {
  4404. /**
  4405. * Hold the root element.
  4406. *
  4407. * @type {Element}
  4408. */
  4409. var root = Splide.root;
  4410. return {
  4411. /**
  4412. * Called when the component is mounted.
  4413. */
  4414. mount: function mount() {
  4415. var map = KEY_MAP[Splide.options.direction];
  4416. Splide.on('mounted updated', function () {
  4417. Splide.off('keydown', root);
  4418. if (Splide.options.keyboard) {
  4419. Splide.on('keydown', function (e) {
  4420. if (map[e.key]) {
  4421. Splide.go(map[e.key]);
  4422. }
  4423. }, root);
  4424. }
  4425. });
  4426. }
  4427. };
  4428. });
  4429. // CONCATENATED MODULE: ./src/js/constants/a11y.js
  4430. /**
  4431. * Export aria attribute names.
  4432. *
  4433. * @author Naotoshi Fujita
  4434. * @copyright Naotoshi Fujita. All rights reserved.
  4435. */
  4436. /**
  4437. * Attribute name for aria-current.
  4438. *
  4439. * @type {string}
  4440. */
  4441. var ARIA_CURRENRT = 'aria-current';
  4442. /**
  4443. * Attribute name for aria-control.
  4444. *
  4445. * @type {string}
  4446. */
  4447. var ARIA_CONTROLS = 'aria-controls';
  4448. /**
  4449. * Attribute name for aria-control.
  4450. *
  4451. * @type {string}
  4452. */
  4453. var ARIA_LABEL = 'aria-label';
  4454. /**
  4455. * Attribute name for aria-labelledby.
  4456. *
  4457. * @type {string}
  4458. */
  4459. var ARIA_LABELLEDBY = 'aria-labelledby';
  4460. /**
  4461. * Attribute name for aria-hidden.
  4462. *
  4463. * @type {string}
  4464. */
  4465. var ARIA_HIDDEN = 'aria-hidden';
  4466. /**
  4467. * Attribute name for tab-index.
  4468. *
  4469. * @type {string}
  4470. */
  4471. var TAB_INDEX = 'tabindex';
  4472. // CONCATENATED MODULE: ./src/js/components/a11y/index.js
  4473. /**
  4474. * The component for enhancing accessibility.
  4475. *
  4476. * @author Naotoshi Fujita
  4477. * @copyright Naotoshi Fujita. All rights reserved.
  4478. */
  4479. /**
  4480. * The component for enhancing accessibility.
  4481. *
  4482. * @param {Splide} Splide - A Splide instance.
  4483. * @param {Object} Components - An object containing components.
  4484. *
  4485. * @return {Object} - The component object.
  4486. */
  4487. /* harmony default export */ var a11y = (function (Splide, Components) {
  4488. /**
  4489. * Hold a i18n object.
  4490. *
  4491. * @type {Object}
  4492. */
  4493. var i18n = Splide.i18n;
  4494. /**
  4495. * Hold the Elements component.
  4496. *
  4497. * @type {Object}
  4498. */
  4499. var Elements = Components.Elements;
  4500. /**
  4501. * A11y component object.
  4502. *
  4503. * @type {Object}
  4504. */
  4505. var A11y = {
  4506. /**
  4507. * Required only when the accessibility option is true.
  4508. *
  4509. * @type {boolean}
  4510. */
  4511. required: Splide.options.accessibility,
  4512. /**
  4513. * Called when the component is mounted.
  4514. */
  4515. mount: function mount() {
  4516. Splide.on('visible', function (Slide) {
  4517. updateSlide(Slide.slide, true);
  4518. }).on('hidden', function (Slide) {
  4519. updateSlide(Slide.slide, false);
  4520. }).on('arrows:mounted', initArrows).on('arrows:updated', updateArrows).on('pagination:mounted', initPagination).on('pagination:updated', updatePagination);
  4521. if (Splide.options.isNavigation) {
  4522. Splide.on('navigation:mounted', initNavigation).on('active', function (Slide) {
  4523. updateNavigation(Slide, true);
  4524. }).on('inactive', function (Slide) {
  4525. updateNavigation(Slide, false);
  4526. });
  4527. }
  4528. initAutoplay();
  4529. },
  4530. /**
  4531. * Destroy.
  4532. */
  4533. destroy: function destroy() {
  4534. var arrows = Components.Arrows.arrows;
  4535. removeAttribute(Elements.slides.concat([arrows.prev, arrows.next, Elements.play, Elements.pause]), [ARIA_HIDDEN, TAB_INDEX, ARIA_CONTROLS, ARIA_LABEL, ARIA_CURRENRT, 'role']);
  4536. }
  4537. };
  4538. /**
  4539. * Update slide attributes when it gets visible or hidden.
  4540. *
  4541. * @param {Element} slide - A slide element.
  4542. * @param {Boolean} visible - True when the slide gets visible, or false when hidden.
  4543. */
  4544. function updateSlide(slide, visible) {
  4545. setAttribute(slide, ARIA_HIDDEN, !visible);
  4546. setAttribute(slide, TAB_INDEX, visible ? 0 : -1);
  4547. }
  4548. /**
  4549. * Initialize arrows if they are available.
  4550. * Append screen reader elements and add aria-controls attribute.
  4551. *
  4552. * @param {Element} prev - Previous arrow element.
  4553. * @param {Element} next - Next arrow element.
  4554. */
  4555. function initArrows(prev, next) {
  4556. var controls = Elements.track.id;
  4557. setAttribute(prev, ARIA_CONTROLS, controls);
  4558. setAttribute(next, ARIA_CONTROLS, controls);
  4559. }
  4560. /**
  4561. * Update arrow attributes.
  4562. *
  4563. * @param {Element} prev - Previous arrow element.
  4564. * @param {Element} next - Next arrow element.
  4565. * @param {number} prevIndex - Previous slide index or -1 when there is no precede slide.
  4566. * @param {number} nextIndex - Next slide index or -1 when there is no next slide.
  4567. */
  4568. function updateArrows(prev, next, prevIndex, nextIndex) {
  4569. var index = Splide.index;
  4570. var prevLabel = prevIndex > -1 && index < prevIndex ? i18n.last : i18n.prev;
  4571. var nextLabel = nextIndex > -1 && index > nextIndex ? i18n.first : i18n.next;
  4572. setAttribute(prev, ARIA_LABEL, prevLabel);
  4573. setAttribute(next, ARIA_LABEL, nextLabel);
  4574. }
  4575. /**
  4576. * Initialize pagination if it's available.
  4577. * Append a screen reader element and add aria-controls/label attribute to each item.
  4578. *
  4579. * @param {Object} data - Data object containing all items.
  4580. * @param {Object} activeItem - An initial active item.
  4581. */
  4582. function initPagination(data, activeItem) {
  4583. if (activeItem) {
  4584. setAttribute(activeItem.button, ARIA_CURRENRT, true);
  4585. }
  4586. data.items.forEach(function (item) {
  4587. var options = Splide.options;
  4588. var text = options.focus === false && options.perPage > 1 ? i18n.pageX : i18n.slideX;
  4589. var label = sprintf(text, item.page + 1);
  4590. var button = item.button;
  4591. var controls = item.Slides.map(function (Slide) {
  4592. return Slide.slide.id;
  4593. });
  4594. setAttribute(button, ARIA_CONTROLS, controls.join(' '));
  4595. setAttribute(button, ARIA_LABEL, label);
  4596. });
  4597. }
  4598. /**
  4599. * Update pagination attributes.
  4600. *
  4601. * @param {Object} data - Data object containing all items.
  4602. * @param {Element} prev - A previous active element.
  4603. * @param {Element} curr - A current active element.
  4604. */
  4605. function updatePagination(data, prev, curr) {
  4606. if (prev) {
  4607. removeAttribute(prev.button, ARIA_CURRENRT);
  4608. }
  4609. if (curr) {
  4610. setAttribute(curr.button, ARIA_CURRENRT, true);
  4611. }
  4612. }
  4613. /**
  4614. * Initialize autoplay buttons.
  4615. */
  4616. function initAutoplay() {
  4617. ['play', 'pause'].forEach(function (name) {
  4618. var elm = Elements[name];
  4619. if (elm) {
  4620. if (!isButton(elm)) {
  4621. setAttribute(elm, 'role', 'button');
  4622. }
  4623. setAttribute(elm, ARIA_CONTROLS, Elements.track.id);
  4624. setAttribute(elm, ARIA_LABEL, i18n[name]);
  4625. }
  4626. });
  4627. }
  4628. /**
  4629. * Initialize navigation slider.
  4630. * Add button role, aria-label, aria-controls to slide elements and append screen reader text to them.
  4631. *
  4632. * @param {Splide} main - A main Splide instance.
  4633. */
  4634. function initNavigation(main) {
  4635. Elements.each(function (_ref) {
  4636. var slide = _ref.slide,
  4637. realIndex = _ref.realIndex,
  4638. index = _ref.index;
  4639. if (!isButton(slide)) {
  4640. setAttribute(slide, 'role', 'button');
  4641. }
  4642. var slideIndex = realIndex > -1 ? realIndex : index;
  4643. var label = sprintf(i18n.slideX, slideIndex + 1);
  4644. var mainSlide = main.Components.Elements.getSlide(slideIndex);
  4645. setAttribute(slide, ARIA_LABEL, label);
  4646. if (mainSlide) {
  4647. setAttribute(slide, ARIA_CONTROLS, mainSlide.slide.id);
  4648. }
  4649. });
  4650. }
  4651. /**
  4652. * Update navigation attributes.
  4653. *
  4654. * @param {Object} Slide - A target Slide object.
  4655. * @param {boolean} active - True if the slide is active or false if inactive.
  4656. */
  4657. function updateNavigation(_ref2, active) {
  4658. var slide = _ref2.slide;
  4659. if (active) {
  4660. setAttribute(slide, ARIA_CURRENRT, true);
  4661. } else {
  4662. removeAttribute(slide, ARIA_CURRENRT);
  4663. }
  4664. }
  4665. /**
  4666. * Check if the given element is button or not.
  4667. *
  4668. * @param {Element} elm - An element to be checked.
  4669. *
  4670. * @return {boolean} - True if the given element is button.
  4671. */
  4672. function isButton(elm) {
  4673. return elm.tagName.toLowerCase() === 'button';
  4674. }
  4675. return A11y;
  4676. });
  4677. // CONCATENATED MODULE: ./src/js/components/sync/index.js
  4678. /**
  4679. * The component for synchronizing a slider with another.
  4680. *
  4681. * @author Naotoshi Fujita
  4682. * @copyright Naotoshi Fujita. All rights reserved.
  4683. */
  4684. /**
  4685. * The event name for sync.
  4686. *
  4687. * @type {string}
  4688. */
  4689. var SYNC_EVENT = 'move.sync';
  4690. /**
  4691. * The keys for triggering the navigation button.
  4692. *
  4693. * @type {String[]}
  4694. */
  4695. var TRIGGER_KEYS = [' ', 'Enter', 'Spacebar'];
  4696. /**
  4697. * The component for synchronizing a slider with another.
  4698. *
  4699. * @param {Splide} Splide - A Splide instance.
  4700. *
  4701. * @return {Object} - The component object.
  4702. */
  4703. /* harmony default export */ var sync = (function (Splide) {
  4704. /**
  4705. * Keep the sibling Splide instance.
  4706. *
  4707. * @type {Splide}
  4708. */
  4709. var sibling = Splide.sibling;
  4710. /**
  4711. * Whether the sibling slider is navigation or not.
  4712. *
  4713. * @type {Splide|boolean}
  4714. */
  4715. var isNavigation = sibling && sibling.options.isNavigation;
  4716. /**
  4717. * Layout component object.
  4718. *
  4719. * @type {Object}
  4720. */
  4721. var Sync = {
  4722. /**
  4723. * Required only when the sub slider is available.
  4724. *
  4725. * @type {boolean}
  4726. */
  4727. required: !!sibling,
  4728. /**
  4729. * Called when the component is mounted.
  4730. */
  4731. mount: function mount() {
  4732. syncMain();
  4733. syncSibling();
  4734. if (isNavigation) {
  4735. bind();
  4736. }
  4737. },
  4738. /**
  4739. * Called after all components are mounted.
  4740. */
  4741. mounted: function mounted() {
  4742. if (isNavigation) {
  4743. sibling.emit('navigation:mounted', Splide);
  4744. }
  4745. }
  4746. };
  4747. /**
  4748. * Listen the primary slider event to move secondary one.
  4749. * Must unbind a handler at first to avoid infinite loop.
  4750. */
  4751. function syncMain() {
  4752. Splide.on(SYNC_EVENT, function (newIndex, prevIndex, destIndex) {
  4753. sibling.off(SYNC_EVENT).go(sibling.is(LOOP) ? destIndex : newIndex, false);
  4754. syncSibling();
  4755. });
  4756. }
  4757. /**
  4758. * Listen the secondary slider event to move primary one.
  4759. * Must unbind a handler at first to avoid infinite loop.
  4760. */
  4761. function syncSibling() {
  4762. sibling.on(SYNC_EVENT, function (newIndex, prevIndex, destIndex) {
  4763. Splide.off(SYNC_EVENT).go(Splide.is(LOOP) ? destIndex : newIndex, false);
  4764. syncMain();
  4765. });
  4766. }
  4767. /**
  4768. * Listen some events on each slide.
  4769. */
  4770. function bind() {
  4771. sibling.Components.Elements.each(function (_ref) {
  4772. var slide = _ref.slide,
  4773. index = _ref.index;
  4774. /*
  4775. * Listen mouseup and touchend events to handle click.
  4776. */
  4777. Splide.on('mouseup touchend', function (e) {
  4778. // Ignore a middle or right click.
  4779. if (!e.button || e.button === 0) {
  4780. moveSibling(index);
  4781. }
  4782. }, slide);
  4783. /*
  4784. * Subscribe keyup to handle Enter and Space key.
  4785. * Note that Array.includes is not supported by IE.
  4786. */
  4787. Splide.on('keyup', function (e) {
  4788. if (TRIGGER_KEYS.indexOf(e.key) > -1) {
  4789. e.preventDefault();
  4790. moveSibling(index);
  4791. }
  4792. }, slide, {
  4793. passive: false
  4794. });
  4795. });
  4796. }
  4797. /**
  4798. * Move the sibling to the given index.
  4799. * Need to check "IDLE" status because slides can be moving by Drag component.
  4800. *
  4801. * @param {number} index - Target index.
  4802. */
  4803. function moveSibling(index) {
  4804. if (Splide.State.is(IDLE)) {
  4805. sibling.go(index);
  4806. }
  4807. }
  4808. return Sync;
  4809. });
  4810. // CONCATENATED MODULE: ./src/js/components/breakpoints/index.js
  4811. /**
  4812. * The component for updating options according to a current window width.
  4813. *
  4814. * @author Naotoshi Fujita
  4815. * @copyright Naotoshi Fujita. All rights reserved.
  4816. */
  4817. /**
  4818. * Interval time for throttle.
  4819. *
  4820. * @type {number}
  4821. */
  4822. var breakpoints_THROTTLE = 50;
  4823. /**
  4824. * The component for updating options according to a current window width.
  4825. *
  4826. * @param {Splide} Splide - A Splide instance.
  4827. *
  4828. * @return {Object} - The component object.
  4829. */
  4830. /* harmony default export */ var components_breakpoints = (function (Splide) {
  4831. /**
  4832. * Store breakpoints.
  4833. *
  4834. * @type {Object|boolean}
  4835. */
  4836. var breakpoints = Splide.options.breakpoints;
  4837. /**
  4838. * The check function whose frequency of call is reduced.
  4839. *
  4840. * @type {Function}
  4841. */
  4842. var throttledCheck = throttle(check, breakpoints_THROTTLE);
  4843. /**
  4844. * Keep initial options.
  4845. *
  4846. * @type {Object}
  4847. */
  4848. var initialOptions;
  4849. /**
  4850. * An array containing objects of point and MediaQueryList.
  4851. *
  4852. * @type {Object[]}
  4853. */
  4854. var map = [];
  4855. /**
  4856. * Hold the previous breakpoint.
  4857. *
  4858. * @type {number|undefined}
  4859. */
  4860. var prevPoint;
  4861. /**
  4862. * Breakpoints component object.
  4863. *
  4864. * @type {Object}
  4865. */
  4866. var Breakpoints = {
  4867. /**
  4868. * Required only when the breakpoints definition is provided and browser supports matchMedia.
  4869. *
  4870. * @type {boolean}
  4871. */
  4872. required: breakpoints && matchMedia,
  4873. /**
  4874. * Called when the component is mounted.
  4875. */
  4876. mount: function mount() {
  4877. map = Object.keys(breakpoints).sort(function (n, m) {
  4878. return parseInt(n) - parseInt(m);
  4879. }).map(function (point) {
  4880. return {
  4881. point: point,
  4882. mql: matchMedia("(max-width:" + point + "px)")
  4883. };
  4884. });
  4885. /*
  4886. * To keep monitoring resize event after destruction without "completely",
  4887. * use native addEventListener instead of Splide.on.
  4888. */
  4889. this.destroy(true);
  4890. addEventListener('resize', throttledCheck); // Keep initial options to apply them when no breakpoint matches.
  4891. initialOptions = Splide.options;
  4892. check();
  4893. },
  4894. /**
  4895. * Destroy.
  4896. *
  4897. * @param {boolean} completely - Whether to destroy Splide completely.
  4898. */
  4899. destroy: function destroy(completely) {
  4900. if (completely) {
  4901. removeEventListener('resize', throttledCheck);
  4902. }
  4903. }
  4904. };
  4905. /**
  4906. * Check the breakpoint.
  4907. */
  4908. function check() {
  4909. var point = getPoint();
  4910. if (point !== prevPoint) {
  4911. prevPoint = point;
  4912. var State = Splide.State;
  4913. var options = breakpoints[point] || initialOptions;
  4914. var destroy = options.destroy;
  4915. if (destroy) {
  4916. Splide.options = initialOptions;
  4917. Splide.destroy(destroy === 'completely');
  4918. } else {
  4919. if (State.is(DESTROYED)) {
  4920. State.set(CREATED);
  4921. Splide.mount();
  4922. } else {
  4923. Splide.options = options;
  4924. }
  4925. }
  4926. }
  4927. }
  4928. /**
  4929. * Return the breakpoint matching current window width.
  4930. * Note that Array.prototype.find is not supported by IE.
  4931. *
  4932. * @return {number|string} - A breakpoint as number or string. -1 if no point matches.
  4933. */
  4934. function getPoint() {
  4935. var item = map.filter(function (item) {
  4936. return item.mql.matches;
  4937. })[0];
  4938. return item ? item.point : -1;
  4939. }
  4940. return Breakpoints;
  4941. });
  4942. // CONCATENATED MODULE: ./src/js/components/index.js
  4943. /**
  4944. * Export components.
  4945. *
  4946. * @author Naotoshi Fujita
  4947. * @copyright Naotoshi Fujita. All rights reserved.
  4948. */
  4949. var COMPLETE = {
  4950. Options: components_options,
  4951. Breakpoints: components_breakpoints,
  4952. Elements: components_elements,
  4953. Controller: controller,
  4954. Track: components_track,
  4955. Clones: components_clones,
  4956. Layout: layout,
  4957. Drag: drag,
  4958. Click: click,
  4959. Autoplay: components_autoplay,
  4960. Cover: components_cover,
  4961. Arrows: components_arrows,
  4962. Pagination: pagination,
  4963. LazyLoad: lazyload,
  4964. Keyboard: keyboard,
  4965. Sync: sync,
  4966. A11y: a11y
  4967. };
  4968. var LIGHT = {
  4969. Options: components_options,
  4970. Elements: components_elements,
  4971. Controller: controller,
  4972. Track: components_track,
  4973. Clones: components_clones,
  4974. Layout: layout,
  4975. Drag: drag,
  4976. Arrows: components_arrows,
  4977. Pagination: pagination,
  4978. A11y: a11y
  4979. };
  4980. // CONCATENATED MODULE: ./build/module/module.js
  4981. function _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  4982. function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  4983. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  4984. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  4985. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  4986. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  4987. /**
  4988. * Export Splide class for import.
  4989. *
  4990. * @author Naotoshi Fujita
  4991. * @copyright Naotoshi Fujita. All rights reserved.
  4992. */
  4993. /**
  4994. * Export Splide class for import from other projects.
  4995. */
  4996. var module_Splide = /*#__PURE__*/function (_Core) {
  4997. _inheritsLoose(Splide, _Core);
  4998. var _super = _createSuper(Splide);
  4999. function Splide(root, options) {
  5000. return _Core.call(this, root, options, COMPLETE) || this;
  5001. }
  5002. return Splide;
  5003. }(splide_Splide);
  5004. /***/ })
  5005. /******/ ]);
  5006. });