splide.js 131 KB

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