splide.js 124 KB

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