splide.js 124 KB

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