splide.js 133 KB

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