splide.js 137 KB

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