splide.js 135 KB

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