splide.js 133 KB

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