splide.js 131 KB

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