splide.js 131 KB

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