splide.js 134 KB

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