splide.js 131 KB

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