splide.js 132 KB

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