splide.js 131 KB

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