splide.js 131 KB

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