splide.js 132 KB

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