splide.js 132 KB

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