splide.js 132 KB

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