splide.esm.js 132 KB

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