splide.js 133 KB

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