splide.js 131 KB

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