mixitup.js 344 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659
  1. /**!
  2. * MixItUp v3.3.0
  3. * A high-performance, dependency-free library for animated filtering, sorting and more
  4. * Build 0be05511-2264-4384-8e31-c75554304cd0
  5. *
  6. * @copyright Copyright 2014-2018 KunkaLabs Limited.
  7. * @author KunkaLabs Limited.
  8. * @link https://www.kunkalabs.com/mixitup/
  9. *
  10. * @license Commercial use requires a commercial license.
  11. * https://www.kunkalabs.com/mixitup/licenses/
  12. *
  13. * Non-commercial use permitted under same terms as CC BY-NC 3.0 license.
  14. * http://creativecommons.org/licenses/by-nc/3.0/
  15. */
  16. (function(window) {
  17. 'use strict';
  18. var mixitup = null,
  19. h = null;
  20. (function() {
  21. var VENDORS = ['webkit', 'moz', 'o', 'ms'],
  22. canary = window.document.createElement('div'),
  23. i = -1;
  24. // window.requestAnimationFrame
  25. for (i = 0; i < VENDORS.length && !window.requestAnimationFrame; i++) {
  26. window.requestAnimationFrame = window[VENDORS[i] + 'RequestAnimationFrame'];
  27. }
  28. // Element.nextElementSibling
  29. if (typeof canary.nextElementSibling === 'undefined') {
  30. Object.defineProperty(window.Element.prototype, 'nextElementSibling', {
  31. get: function() {
  32. var el = this.nextSibling;
  33. while (el) {
  34. if (el.nodeType === 1) {
  35. return el;
  36. }
  37. el = el.nextSibling;
  38. }
  39. return null;
  40. }
  41. });
  42. }
  43. // Element.matches
  44. (function(ElementPrototype) {
  45. ElementPrototype.matches =
  46. ElementPrototype.matches ||
  47. ElementPrototype.machesSelector ||
  48. ElementPrototype.mozMatchesSelector ||
  49. ElementPrototype.msMatchesSelector ||
  50. ElementPrototype.oMatchesSelector ||
  51. ElementPrototype.webkitMatchesSelector ||
  52. function (selector) {
  53. return Array.prototype.indexOf.call(this.parentElement.querySelectorAll(selector), this) > -1;
  54. };
  55. })(window.Element.prototype);
  56. // Object.keys
  57. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
  58. if (!Object.keys) {
  59. Object.keys = (function() {
  60. var hasOwnProperty = Object.prototype.hasOwnProperty,
  61. hasDontEnumBug = false,
  62. dontEnums = [],
  63. dontEnumsLength = -1;
  64. hasDontEnumBug = !({
  65. toString: null
  66. })
  67. .propertyIsEnumerable('toString');
  68. dontEnums = [
  69. 'toString',
  70. 'toLocaleString',
  71. 'valueOf',
  72. 'hasOwnProperty',
  73. 'isPrototypeOf',
  74. 'propertyIsEnumerable',
  75. 'constructor'
  76. ];
  77. dontEnumsLength = dontEnums.length;
  78. return function(obj) {
  79. var result = [],
  80. prop = '',
  81. i = -1;
  82. if (typeof obj !== 'object' && (typeof obj !== 'function' || obj === null)) {
  83. throw new TypeError('Object.keys called on non-object');
  84. }
  85. for (prop in obj) {
  86. if (hasOwnProperty.call(obj, prop)) {
  87. result.push(prop);
  88. }
  89. }
  90. if (hasDontEnumBug) {
  91. for (i = 0; i < dontEnumsLength; i++) {
  92. if (hasOwnProperty.call(obj, dontEnums[i])) {
  93. result.push(dontEnums[i]);
  94. }
  95. }
  96. }
  97. return result;
  98. };
  99. }());
  100. }
  101. // Array.isArray
  102. // https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray
  103. if (!Array.isArray) {
  104. Array.isArray = function(arg) {
  105. return Object.prototype.toString.call(arg) === '[object Array]';
  106. };
  107. }
  108. // Object.create
  109. // https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/create
  110. if (typeof Object.create !== 'function') {
  111. Object.create = (function(undefined) {
  112. var Temp = function() {};
  113. return function (prototype, propertiesObject) {
  114. if (prototype !== Object(prototype) && prototype !== null) {
  115. throw TypeError('Argument must be an object, or null');
  116. }
  117. Temp.prototype = prototype || {};
  118. var result = new Temp();
  119. Temp.prototype = null;
  120. if (propertiesObject !== undefined) {
  121. Object.defineProperties(result, propertiesObject);
  122. }
  123. if (prototype === null) {
  124. /* jshint ignore:start */
  125. result.__proto__ = null;
  126. /* jshint ignore:end */
  127. }
  128. return result;
  129. };
  130. })();
  131. }
  132. // String.prototyoe.trim
  133. if (!String.prototype.trim) {
  134. String.prototype.trim = function() {
  135. return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  136. };
  137. }
  138. // Array.prototype.indexOf
  139. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf
  140. if (!Array.prototype.indexOf) {
  141. Array.prototype.indexOf = function(searchElement) {
  142. var n, k, t, len;
  143. if (this === null) {
  144. throw new TypeError();
  145. }
  146. t = Object(this);
  147. len = t.length >>> 0;
  148. if (len === 0) {
  149. return -1;
  150. }
  151. n = 0;
  152. if (arguments.length > 1) {
  153. n = Number(arguments[1]);
  154. if (n !== n) {
  155. n = 0;
  156. } else if (n !== 0 && n !== Infinity && n !== -Infinity) {
  157. n = (n > 0 || -1) * Math.floor(Math.abs(n));
  158. }
  159. }
  160. if (n >= len) {
  161. return -1;
  162. }
  163. for (k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); k < len; k++) {
  164. if (k in t && t[k] === searchElement) {
  165. return k;
  166. }
  167. }
  168. return -1;
  169. };
  170. }
  171. // Function.prototype.bind
  172. // https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_objects/Function/bind
  173. if (!Function.prototype.bind) {
  174. Function.prototype.bind = function(oThis) {
  175. var aArgs, self, FNOP, fBound;
  176. if (typeof this !== 'function') {
  177. throw new TypeError();
  178. }
  179. aArgs = Array.prototype.slice.call(arguments, 1);
  180. self = this;
  181. FNOP = function() {};
  182. fBound = function() {
  183. return self.apply(this instanceof FNOP ? this : oThis, aArgs.concat(Array.prototype.slice.call(arguments)));
  184. };
  185. if (this.prototype) {
  186. FNOP.prototype = this.prototype;
  187. }
  188. fBound.prototype = new FNOP();
  189. return fBound;
  190. };
  191. }
  192. // Element.prototype.dispatchEvent
  193. if (!window.Element.prototype.dispatchEvent) {
  194. window.Element.prototype.dispatchEvent = function(event) {
  195. try {
  196. return this.fireEvent('on' + event.type, event);
  197. } catch (err) {}
  198. };
  199. }
  200. })();
  201. /**
  202. * The `mixitup()` "factory" function creates and returns individual instances
  203. * of MixItUp, known as "mixers", on which API methods can be called.
  204. *
  205. * When loading MixItUp via a script tag, the factory function is accessed
  206. * via the global variable `mixitup`. When using a module loading
  207. * system (e.g. ES2015, CommonJS, RequireJS), the factory function is
  208. * exported into your module when you require the MixItUp library.
  209. *
  210. * @example
  211. * mixitup(container [,config] [,foreignDoc])
  212. *
  213. * @example <caption>Example 1: Creating a mixer instance with an element reference</caption>
  214. * var containerEl = document.querySelector('.container');
  215. *
  216. * var mixer = mixitup(containerEl);
  217. *
  218. * @example <caption>Example 2: Creating a mixer instance with a selector string</caption>
  219. * var mixer = mixitup('.container');
  220. *
  221. * @example <caption>Example 3: Passing a configuration object</caption>
  222. * var mixer = mixitup(containerEl, {
  223. * animation: {
  224. * effects: 'fade scale(0.5)'
  225. * }
  226. * });
  227. *
  228. * @example <caption>Example 4: Passing an iframe reference</caption>
  229. * var mixer = mixitup(containerEl, config, foreignDocument);
  230. *
  231. * @global
  232. * @namespace
  233. * @public
  234. * @kind function
  235. * @since 3.0.0
  236. * @param {(Element|string)} container
  237. * A DOM element or selector string representing the container(s) on which to instantiate MixItUp.
  238. * @param {object} [config]
  239. * An optional "configuration object" used to customize the behavior of the MixItUp instance.
  240. * @param {object} [foreignDoc]
  241. * An optional reference to a `document`, which can be used to control a MixItUp instance in an iframe.
  242. * @return {mixitup.Mixer}
  243. * A "mixer" object holding the MixItUp instance.
  244. */
  245. mixitup = function(container, config, foreignDoc) {
  246. var el = null,
  247. returnCollection = false,
  248. instance = null,
  249. facade = null,
  250. doc = null,
  251. output = null,
  252. instances = [],
  253. id = '',
  254. elements = [],
  255. i = -1;
  256. doc = foreignDoc || window.document;
  257. if (returnCollection = arguments[3]) {
  258. // A non-documented 4th paramater enabling control of multiple instances
  259. returnCollection = typeof returnCollection === 'boolean';
  260. }
  261. if (typeof container === 'string') {
  262. elements = doc.querySelectorAll(container);
  263. } else if (container && typeof container === 'object' && h.isElement(container, doc)) {
  264. elements = [container];
  265. } else if (container && typeof container === 'object' && container.length) {
  266. // Although not documented, the container may also be an array-like list of
  267. // elements such as a NodeList or jQuery collection, is returnCollection is true
  268. elements = container;
  269. } else {
  270. throw new Error(mixitup.messages.errorFactoryInvalidContainer());
  271. }
  272. if (elements.length < 1) {
  273. throw new Error(mixitup.messages.errorFactoryContainerNotFound());
  274. }
  275. for (i = 0; el = elements[i]; i++) {
  276. if (i > 0 && !returnCollection) break;
  277. if (!el.id) {
  278. id = 'MixItUp' + h.randomHex();
  279. el.id = id;
  280. } else {
  281. id = el.id;
  282. }
  283. if (mixitup.instances[id] instanceof mixitup.Mixer) {
  284. instance = mixitup.instances[id];
  285. if (!config || (config && config.debug && config.debug.showWarnings !== false)) {
  286. console.warn(mixitup.messages.warningFactoryPreexistingInstance());
  287. }
  288. } else {
  289. instance = new mixitup.Mixer();
  290. instance.attach(el, doc, id, config);
  291. mixitup.instances[id] = instance;
  292. }
  293. facade = new mixitup.Facade(instance);
  294. if (config && config.debug && config.debug.enable) {
  295. instances.push(instance);
  296. } else {
  297. instances.push(facade);
  298. }
  299. }
  300. if (returnCollection) {
  301. output = new mixitup.Collection(instances);
  302. } else {
  303. // Return the first instance regardless
  304. output = instances[0];
  305. }
  306. return output;
  307. };
  308. /**
  309. * The `.use()` static method is used to extend the functionality of mixitup with compatible
  310. * extensions and libraries in an environment with modular scoping e.g. ES2015, CommonJS, or RequireJS.
  311. *
  312. * You need only call the `.use()` function once per project, per extension, as module loaders
  313. * will cache a single reference to MixItUp inclusive of all changes made.
  314. *
  315. * @example
  316. * mixitup.use(extension)
  317. *
  318. * @example <caption>Example 1: Extending MixItUp with the Pagination Extension</caption>
  319. *
  320. * import mixitup from 'mixitup';
  321. * import mixitupPagination from 'mixitup-pagination';
  322. *
  323. * mixitup.use(mixitupPagination);
  324. *
  325. * // All mixers created by the factory function in all modules will now
  326. * // have pagination functionality
  327. *
  328. * var mixer = mixitup('.container');
  329. *
  330. * @public
  331. * @name use
  332. * @memberof mixitup
  333. * @kind function
  334. * @static
  335. * @since 3.0.0
  336. * @param {*} extension A reference to the extension or library to be used.
  337. * @return {void}
  338. */
  339. mixitup.use = function(extension) {
  340. mixitup.Base.prototype.callActions.call(mixitup, 'beforeUse', arguments);
  341. // Call the extension's factory function, passing
  342. // the mixitup factory as a paramater
  343. if (typeof extension === 'function' && extension.TYPE === 'mixitup-extension') {
  344. // Mixitup extension
  345. if (typeof mixitup.extensions[extension.NAME] === 'undefined') {
  346. extension(mixitup);
  347. mixitup.extensions[extension.NAME] = extension;
  348. }
  349. } else if (extension.fn && extension.fn.jquery) {
  350. // jQuery
  351. mixitup.libraries.$ = extension;
  352. }
  353. mixitup.Base.prototype.callActions.call(mixitup, 'afterUse', arguments);
  354. };
  355. mixitup.instances = {};
  356. mixitup.extensions = {};
  357. mixitup.libraries = {};
  358. /**
  359. * @private
  360. */
  361. h = {
  362. /**
  363. * @private
  364. * @param {HTMLElement} el
  365. * @param {string} cls
  366. * @return {boolean}
  367. */
  368. hasClass: function(el, cls) {
  369. return !!el.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
  370. },
  371. /**
  372. * @private
  373. * @param {HTMLElement} el
  374. * @param {string} cls
  375. * @return {void}
  376. */
  377. addClass: function(el, cls) {
  378. if (!this.hasClass(el, cls)) el.className += el.className ? ' ' + cls : cls;
  379. },
  380. /**
  381. * @private
  382. * @param {HTMLElement} el
  383. * @param {string} cls
  384. * @return {void}
  385. */
  386. removeClass: function(el, cls) {
  387. if (this.hasClass(el, cls)) {
  388. var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
  389. el.className = el.className.replace(reg, ' ').trim();
  390. }
  391. },
  392. /**
  393. * Merges the properties of the source object onto the
  394. * target object. Alters the target object.
  395. *
  396. * @private
  397. * @param {object} destination
  398. * @param {object} source
  399. * @param {boolean} [deep=false]
  400. * @param {boolean} [handleErrors=false]
  401. * @return {void}
  402. */
  403. extend: function(destination, source, deep, handleErrors) {
  404. var sourceKeys = [],
  405. key = '',
  406. i = -1;
  407. deep = deep || false;
  408. handleErrors = handleErrors || false;
  409. try {
  410. if (Array.isArray(source)) {
  411. for (i = 0; i < source.length; i++) {
  412. sourceKeys.push(i);
  413. }
  414. } else if (source) {
  415. sourceKeys = Object.keys(source);
  416. }
  417. for (i = 0; i < sourceKeys.length; i++) {
  418. key = sourceKeys[i];
  419. if (!deep || typeof source[key] !== 'object' || this.isElement(source[key])) {
  420. // All non-object properties, or all properties if shallow extend
  421. destination[key] = source[key];
  422. } else if (Array.isArray(source[key])) {
  423. // Arrays
  424. if (!destination[key]) {
  425. destination[key] = [];
  426. }
  427. this.extend(destination[key], source[key], deep, handleErrors);
  428. } else {
  429. // Objects
  430. if (!destination[key]) {
  431. destination[key] = {};
  432. }
  433. this.extend(destination[key], source[key], deep, handleErrors);
  434. }
  435. }
  436. } catch(err) {
  437. if (handleErrors) {
  438. this.handleExtendError(err, destination);
  439. } else {
  440. throw err;
  441. }
  442. }
  443. return destination;
  444. },
  445. /**
  446. * @private
  447. * @param {Error} err
  448. * @param {object} destination
  449. * @return {void}
  450. */
  451. handleExtendError: function(err, destination) {
  452. var re = /property "?(\w*)"?[,:] object/i,
  453. matches = null,
  454. erroneous = '',
  455. message = '',
  456. suggestion = '',
  457. probableMatch = '',
  458. key = '',
  459. mostMatchingChars = -1,
  460. i = -1;
  461. if (err instanceof TypeError && (matches = re.exec(err.message))) {
  462. erroneous = matches[1];
  463. for (key in destination) {
  464. i = 0;
  465. while (i < erroneous.length && erroneous.charAt(i) === key.charAt(i)) {
  466. i++;
  467. }
  468. if (i > mostMatchingChars) {
  469. mostMatchingChars = i;
  470. probableMatch = key;
  471. }
  472. }
  473. if (mostMatchingChars > 1) {
  474. suggestion = mixitup.messages.errorConfigInvalidPropertySuggestion({
  475. probableMatch: probableMatch
  476. });
  477. }
  478. message = mixitup.messages.errorConfigInvalidProperty({
  479. erroneous: erroneous,
  480. suggestion: suggestion
  481. });
  482. throw new TypeError(message);
  483. }
  484. throw err;
  485. },
  486. /**
  487. * @private
  488. * @param {string} str
  489. * @return {function}
  490. */
  491. template: function(str) {
  492. var re = /\${([\w]*)}/g,
  493. dynamics = {},
  494. matches = null;
  495. while ((matches = re.exec(str))) {
  496. dynamics[matches[1]] = new RegExp('\\${' + matches[1] + '}', 'g');
  497. }
  498. return function(data) {
  499. var key = '',
  500. output = str;
  501. data = data || {};
  502. for (key in dynamics) {
  503. output = output.replace(dynamics[key], typeof data[key] !== 'undefined' ? data[key] : '');
  504. }
  505. return output;
  506. };
  507. },
  508. /**
  509. * @private
  510. * @param {HTMLElement} el
  511. * @param {string} type
  512. * @param {function} fn
  513. * @param {boolean} useCapture
  514. * @return {void}
  515. */
  516. on: function(el, type, fn, useCapture) {
  517. if (!el) return;
  518. if (el.addEventListener) {
  519. el.addEventListener(type, fn, useCapture);
  520. } else if (el.attachEvent) {
  521. el['e' + type + fn] = fn;
  522. el[type + fn] = function() {
  523. el['e' + type + fn](window.event);
  524. };
  525. el.attachEvent('on' + type, el[type + fn]);
  526. }
  527. },
  528. /**
  529. * @private
  530. * @param {HTMLElement} el
  531. * @param {string} type
  532. * @param {function} fn
  533. * @return {void}
  534. */
  535. off: function(el, type, fn) {
  536. if (!el) return;
  537. if (el.removeEventListener) {
  538. el.removeEventListener(type, fn, false);
  539. } else if (el.detachEvent) {
  540. el.detachEvent('on' + type, el[type + fn]);
  541. el[type + fn] = null;
  542. }
  543. },
  544. /**
  545. * @private
  546. * @param {string} eventType
  547. * @param {object} detail
  548. * @param {Document} [doc]
  549. * @return {CustomEvent}
  550. */
  551. getCustomEvent: function(eventType, detail, doc) {
  552. var event = null;
  553. doc = doc || window.document;
  554. if (typeof window.CustomEvent === 'function') {
  555. event = new window.CustomEvent(eventType, {
  556. detail: detail,
  557. bubbles: true,
  558. cancelable: true
  559. });
  560. } else if (typeof doc.createEvent === 'function') {
  561. event = doc.createEvent('CustomEvent');
  562. event.initCustomEvent(eventType, true, true, detail);
  563. } else {
  564. event = doc.createEventObject(),
  565. event.type = eventType;
  566. event.returnValue = false;
  567. event.cancelBubble = false;
  568. event.detail = detail;
  569. }
  570. return event;
  571. },
  572. /**
  573. * @private
  574. * @param {Event} e
  575. * @return {Event}
  576. */
  577. getOriginalEvent: function(e) {
  578. if (e.touches && e.touches.length) {
  579. return e.touches[0];
  580. } else if (e.changedTouches && e.changedTouches.length) {
  581. return e.changedTouches[0];
  582. } else {
  583. return e;
  584. }
  585. },
  586. /**
  587. * @private
  588. * @param {HTMLElement} el
  589. * @param {string} selector
  590. * @return {Number}
  591. */
  592. index: function(el, selector) {
  593. var i = 0;
  594. while ((el = el.previousElementSibling) !== null) {
  595. if (!selector || el.matches(selector)) {
  596. ++i;
  597. }
  598. }
  599. return i;
  600. },
  601. /**
  602. * Converts a dash or snake-case string to camel case.
  603. *
  604. * @private
  605. * @param {string} str
  606. * @param {boolean} [isPascal]
  607. * @return {string}
  608. */
  609. camelCase: function(str) {
  610. return str.toLowerCase().replace(/([_-][a-z])/g, function($1) {
  611. return $1.toUpperCase().replace(/[_-]/, '');
  612. });
  613. },
  614. /**
  615. * Converts a dash or snake-case string to pascal case.
  616. *
  617. * @private
  618. * @param {string} str
  619. * @param {boolean} [isPascal]
  620. * @return {string}
  621. */
  622. pascalCase: function(str) {
  623. return (str = this.camelCase(str)).charAt(0).toUpperCase() + str.slice(1);
  624. },
  625. /**
  626. * Converts a camel or pascal-case string to dash case.
  627. *
  628. * @private
  629. * @param {string} str
  630. * @return {string}
  631. */
  632. dashCase: function(str) {
  633. return str.replace(/([A-Z])/g, '-$1').replace(/^-/, '').toLowerCase();
  634. },
  635. /**
  636. * @private
  637. * @param {HTMLElement} el
  638. * @param {HTMLHtmlElement} [doc]
  639. * @return {boolean}
  640. */
  641. isElement: function(el, doc) {
  642. doc = doc || window.document;
  643. if (
  644. window.HTMLElement &&
  645. el instanceof window.HTMLElement
  646. ) {
  647. return true;
  648. } else if (
  649. doc.defaultView &&
  650. doc.defaultView.HTMLElement &&
  651. el instanceof doc.defaultView.HTMLElement
  652. ) {
  653. return true;
  654. } else {
  655. return (
  656. el !== null &&
  657. el.nodeType === 1 &&
  658. typeof el.nodeName === 'string'
  659. );
  660. }
  661. },
  662. /**
  663. * @private
  664. * @param {string} htmlString
  665. * @param {HTMLHtmlElement} [doc]
  666. * @return {DocumentFragment}
  667. */
  668. createElement: function(htmlString, doc) {
  669. var frag = null,
  670. temp = null;
  671. doc = doc || window.document;
  672. frag = doc.createDocumentFragment();
  673. temp = doc.createElement('div');
  674. temp.innerHTML = htmlString.trim();
  675. while (temp.firstChild) {
  676. frag.appendChild(temp.firstChild);
  677. }
  678. return frag;
  679. },
  680. /**
  681. * @private
  682. * @param {Node} node
  683. * @return {void}
  684. */
  685. removeWhitespace: function(node) {
  686. var deleting;
  687. while (node && node.nodeName === '#text') {
  688. deleting = node;
  689. node = node.previousSibling;
  690. deleting.parentElement && deleting.parentElement.removeChild(deleting);
  691. }
  692. },
  693. /**
  694. * @private
  695. * @param {Array<*>} a
  696. * @param {Array<*>} b
  697. * @return {boolean}
  698. */
  699. isEqualArray: function(a, b) {
  700. var i = a.length;
  701. if (i !== b.length) return false;
  702. while (i--) {
  703. if (a[i] !== b[i]) return false;
  704. }
  705. return true;
  706. },
  707. /**
  708. * @private
  709. * @param {object} a
  710. * @param {object} b
  711. * @return {boolean}
  712. */
  713. deepEquals: function(a, b) {
  714. var key;
  715. if (typeof a === 'object' && a && typeof b === 'object' && b) {
  716. if (Object.keys(a).length !== Object.keys(b).length) return false;
  717. for (key in a) {
  718. if (!b.hasOwnProperty(key) || !this.deepEquals(a[key], b[key])) return false;
  719. }
  720. } else if (a !== b) {
  721. return false;
  722. }
  723. return true;
  724. },
  725. /**
  726. * @private
  727. * @param {Array<*>} oldArray
  728. * @return {Array<*>}
  729. */
  730. arrayShuffle: function(oldArray) {
  731. var newArray = oldArray.slice(),
  732. len = newArray.length,
  733. i = len,
  734. p = -1,
  735. t = [];
  736. while (i--) {
  737. p = ~~(Math.random() * len);
  738. t = newArray[i];
  739. newArray[i] = newArray[p];
  740. newArray[p] = t;
  741. }
  742. return newArray;
  743. },
  744. /**
  745. * @private
  746. * @param {object} list
  747. */
  748. arrayFromList: function(list) {
  749. var output, i;
  750. try {
  751. return Array.prototype.slice.call(list);
  752. } catch(err) {
  753. output = [];
  754. for (i = 0; i < list.length; i++) {
  755. output.push(list[i]);
  756. }
  757. return output;
  758. }
  759. },
  760. /**
  761. * @private
  762. * @param {function} func
  763. * @param {Number} wait
  764. * @param {boolean} immediate
  765. * @return {function}
  766. */
  767. debounce: function(func, wait, immediate) {
  768. var timeout;
  769. return function() {
  770. var self = this,
  771. args = arguments,
  772. callNow = immediate && !timeout,
  773. later = null;
  774. later = function() {
  775. timeout = null;
  776. if (!immediate) {
  777. func.apply(self, args);
  778. }
  779. };
  780. clearTimeout(timeout);
  781. timeout = setTimeout(later, wait);
  782. if (callNow) func.apply(self, args);
  783. };
  784. },
  785. /**
  786. * @private
  787. * @param {HTMLElement} element
  788. * @return {object}
  789. */
  790. position: function(element) {
  791. var xPosition = 0,
  792. yPosition = 0,
  793. offsetParent = element;
  794. while (element) {
  795. xPosition -= element.scrollLeft;
  796. yPosition -= element.scrollTop;
  797. if (element === offsetParent) {
  798. xPosition += element.offsetLeft;
  799. yPosition += element.offsetTop;
  800. offsetParent = element.offsetParent;
  801. }
  802. element = element.parentElement;
  803. }
  804. return {
  805. x: xPosition,
  806. y: yPosition
  807. };
  808. },
  809. /**
  810. * @private
  811. * @param {object} node1
  812. * @param {object} node2
  813. * @return {Number}
  814. */
  815. getHypotenuse: function(node1, node2) {
  816. var distanceX = node1.x - node2.x,
  817. distanceY = node1.y - node2.y;
  818. distanceX = distanceX < 0 ? distanceX * -1 : distanceX,
  819. distanceY = distanceY < 0 ? distanceY * -1 : distanceY;
  820. return Math.sqrt(Math.pow(distanceX, 2) + Math.pow(distanceY, 2));
  821. },
  822. /**
  823. * Calcuates the area of intersection between two rectangles and expresses it as
  824. * a ratio in comparison to the area of the first rectangle.
  825. *
  826. * @private
  827. * @param {Rect} box1
  828. * @param {Rect} box2
  829. * @return {number}
  830. */
  831. getIntersectionRatio: function(box1, box2) {
  832. var controlArea = box1.width * box1.height,
  833. intersectionX = -1,
  834. intersectionY = -1,
  835. intersectionArea = -1,
  836. ratio = -1;
  837. intersectionX =
  838. Math.max(0, Math.min(box1.left + box1.width, box2.left + box2.width) - Math.max(box1.left, box2.left));
  839. intersectionY =
  840. Math.max(0, Math.min(box1.top + box1.height, box2.top + box2.height) - Math.max(box1.top, box2.top));
  841. intersectionArea = intersectionY * intersectionX;
  842. ratio = intersectionArea / controlArea;
  843. return ratio;
  844. },
  845. /**
  846. * @private
  847. * @param {object} el
  848. * @param {string} selector
  849. * @param {boolean} [includeSelf]
  850. * @param {HTMLHtmlElement} [doc]
  851. * @return {Element|null}
  852. */
  853. closestParent: function(el, selector, includeSelf, doc) {
  854. var parent = el.parentNode;
  855. doc = doc || window.document;
  856. if (includeSelf && el.matches(selector)) {
  857. return el;
  858. }
  859. while (parent && parent != doc.body) {
  860. if (parent.matches && parent.matches(selector)) {
  861. return parent;
  862. } else if (parent.parentNode) {
  863. parent = parent.parentNode;
  864. } else {
  865. return null;
  866. }
  867. }
  868. return null;
  869. },
  870. /**
  871. * @private
  872. * @param {HTMLElement} el
  873. * @param {string} selector
  874. * @param {HTMLHtmlElement} [doc]
  875. * @return {NodeList}
  876. */
  877. children: function(el, selector, doc) {
  878. var children = [],
  879. tempId = '';
  880. doc = doc || window.doc;
  881. if (el) {
  882. if (!el.id) {
  883. tempId = 'Temp' + this.randomHexKey();
  884. el.id = tempId;
  885. }
  886. children = doc.querySelectorAll('#' + el.id + ' > ' + selector);
  887. if (tempId) {
  888. el.removeAttribute('id');
  889. }
  890. }
  891. return children;
  892. },
  893. /**
  894. * Creates a clone of a provided array, with any empty strings removed.
  895. *
  896. * @private
  897. * @param {Array<*>} originalArray
  898. * @return {Array<*>}
  899. */
  900. clean: function(originalArray) {
  901. var cleanArray = [],
  902. i = -1;
  903. for (i = 0; i < originalArray.length; i++) {
  904. if (originalArray[i] !== '') {
  905. cleanArray.push(originalArray[i]);
  906. }
  907. }
  908. return cleanArray;
  909. },
  910. /**
  911. * Abstracts an ES6 promise into a q-like deferred interface for storage and deferred resolution.
  912. *
  913. * @private
  914. * @param {object} libraries
  915. * @return {h.Deferred}
  916. */
  917. defer: function(libraries) {
  918. var deferred = null,
  919. promiseWrapper = null,
  920. $ = null;
  921. promiseWrapper = new this.Deferred();
  922. if (mixitup.features.has.promises) {
  923. // ES6 native promise or polyfill
  924. promiseWrapper.promise = new Promise(function(resolve, reject) {
  925. promiseWrapper.resolve = resolve;
  926. promiseWrapper.reject = reject;
  927. });
  928. } else if (($ = (window.jQuery || libraries.$)) && typeof $.Deferred === 'function') {
  929. // jQuery
  930. deferred = $.Deferred();
  931. promiseWrapper.promise = deferred.promise();
  932. promiseWrapper.resolve = deferred.resolve;
  933. promiseWrapper.reject = deferred.reject;
  934. } else if (window.console) {
  935. // No implementation
  936. console.warn(mixitup.messages.warningNoPromiseImplementation());
  937. }
  938. return promiseWrapper;
  939. },
  940. /**
  941. * @private
  942. * @param {Array<Promise>} tasks
  943. * @param {object} libraries
  944. * @return {Promise<Array>}
  945. */
  946. all: function(tasks, libraries) {
  947. var $ = null;
  948. if (mixitup.features.has.promises) {
  949. return Promise.all(tasks);
  950. } else if (($ = (window.jQuery || libraries.$)) && typeof $.when === 'function') {
  951. return $.when.apply($, tasks)
  952. .done(function() {
  953. // jQuery when returns spread arguments rather than an array or resolutions
  954. return arguments;
  955. });
  956. }
  957. // No implementation
  958. if (window.console) {
  959. console.warn(mixitup.messages.warningNoPromiseImplementation());
  960. }
  961. return [];
  962. },
  963. /**
  964. * @private
  965. * @param {HTMLElement} el
  966. * @param {string} property
  967. * @param {Array<string>} vendors
  968. * @return {string}
  969. */
  970. getPrefix: function(el, property, vendors) {
  971. var i = -1,
  972. prefix = '';
  973. if (h.dashCase(property) in el.style) return '';
  974. for (i = 0; prefix = vendors[i]; i++) {
  975. if (prefix + property in el.style) {
  976. return prefix.toLowerCase();
  977. }
  978. }
  979. return 'unsupported';
  980. },
  981. /**
  982. * @private
  983. * @return {string}
  984. */
  985. randomHex: function() {
  986. return ('00000' + (Math.random() * 16777216 << 0).toString(16)).substr(-6).toUpperCase();
  987. },
  988. /**
  989. * @private
  990. * @param {HTMLDocument} [doc]
  991. * @return {object}
  992. */
  993. getDocumentState: function(doc) {
  994. doc = typeof doc.body === 'object' ? doc : window.document;
  995. return {
  996. scrollTop: window.pageYOffset,
  997. scrollLeft: window.pageXOffset,
  998. docHeight: doc.documentElement.scrollHeight,
  999. docWidth: doc.documentElement.scrollWidth,
  1000. viewportHeight: doc.documentElement.clientHeight,
  1001. viewportWidth: doc.documentElement.clientWidth
  1002. };
  1003. },
  1004. /**
  1005. * @private
  1006. * @param {object} obj
  1007. * @param {function} fn
  1008. * @return {function}
  1009. */
  1010. bind: function(obj, fn) {
  1011. return function() {
  1012. return fn.apply(obj, arguments);
  1013. };
  1014. },
  1015. /**
  1016. * @private
  1017. * @param {HTMLElement} el
  1018. * @return {boolean}
  1019. */
  1020. isVisible: function(el) {
  1021. var styles = null;
  1022. if (el.offsetParent) return true;
  1023. styles = window.getComputedStyle(el);
  1024. if (
  1025. styles.position === 'fixed' &&
  1026. styles.visibility !== 'hidden' &&
  1027. styles.opacity !== '0'
  1028. ) {
  1029. // Fixed elements report no offsetParent,
  1030. // but may still be invisible
  1031. return true;
  1032. }
  1033. return false;
  1034. },
  1035. /**
  1036. * @private
  1037. * @param {object} obj
  1038. */
  1039. seal: function(obj) {
  1040. if (typeof Object.seal === 'function') {
  1041. Object.seal(obj);
  1042. }
  1043. },
  1044. /**
  1045. * @private
  1046. * @param {object} obj
  1047. */
  1048. freeze: function(obj) {
  1049. if (typeof Object.freeze === 'function') {
  1050. Object.freeze(obj);
  1051. }
  1052. },
  1053. /**
  1054. * @private
  1055. * @param {string} control
  1056. * @param {string} specimen
  1057. * @return {boolean}
  1058. */
  1059. compareVersions: function(control, specimen) {
  1060. var controlParts = control.split('.'),
  1061. specimenParts = specimen.split('.'),
  1062. controlPart = -1,
  1063. specimenPart = -1,
  1064. i = -1;
  1065. for (i = 0; i < controlParts.length; i++) {
  1066. controlPart = parseInt(controlParts[i].replace(/[^\d.]/g, ''));
  1067. specimenPart = parseInt(specimenParts[i].replace(/[^\d.]/g, '') || 0);
  1068. if (specimenPart < controlPart) {
  1069. return false;
  1070. } else if (specimenPart > controlPart) {
  1071. return true;
  1072. }
  1073. }
  1074. return true;
  1075. },
  1076. /**
  1077. * @private
  1078. * @constructor
  1079. */
  1080. Deferred: function() {
  1081. this.promise = null;
  1082. this.resolve = null;
  1083. this.reject = null;
  1084. this.id = h.randomHex();
  1085. },
  1086. /**
  1087. * @private
  1088. * @param {object} obj
  1089. * @return {boolean}
  1090. */
  1091. isEmptyObject: function(obj) {
  1092. var key = '';
  1093. if (typeof Object.keys === 'function') {
  1094. return Object.keys(obj).length === 0;
  1095. }
  1096. for (key in obj) {
  1097. if (obj.hasOwnProperty(key)) {
  1098. return false;
  1099. }
  1100. }
  1101. return true;
  1102. },
  1103. /**
  1104. * @param {mixitup.Config.ClassNames} classNames
  1105. * @param {string} elementName
  1106. * @param {string} [modifier]
  1107. * @return {string}
  1108. */
  1109. getClassname: function(classNames, elementName, modifier) {
  1110. var classname = '';
  1111. classname += classNames.block;
  1112. if (classname.length) {
  1113. classname += classNames.delineatorElement;
  1114. }
  1115. classname += classNames['element' + this.pascalCase(elementName)];
  1116. if (!modifier) return classname;
  1117. if (classname.length) {
  1118. classname += classNames.delineatorModifier;
  1119. }
  1120. classname += modifier;
  1121. return classname;
  1122. },
  1123. /**
  1124. * Returns the value of a property on a given object via its string key.
  1125. *
  1126. * @param {object} obj
  1127. * @param {string} stringKey
  1128. * @return {*} value
  1129. */
  1130. getProperty: function(obj, stringKey) {
  1131. var parts = stringKey.split('.'),
  1132. returnCurrent = null,
  1133. current = '',
  1134. i = 0;
  1135. if (!stringKey) {
  1136. return obj;
  1137. }
  1138. returnCurrent = function(obj) {
  1139. if (!obj) {
  1140. return null;
  1141. } else {
  1142. return obj[current];
  1143. }
  1144. };
  1145. while (i < parts.length) {
  1146. current = parts[i];
  1147. obj = returnCurrent(obj);
  1148. i++;
  1149. }
  1150. if (typeof obj !== 'undefined') {
  1151. return obj;
  1152. } else {
  1153. return null;
  1154. }
  1155. }
  1156. };
  1157. mixitup.h = h;
  1158. /**
  1159. * The Base class adds instance methods to all other extensible MixItUp classes,
  1160. * enabling the calling of any registered hooks.
  1161. *
  1162. * @constructor
  1163. * @namespace
  1164. * @memberof mixitup
  1165. * @private
  1166. * @since 3.0.0
  1167. */
  1168. mixitup.Base = function() {};
  1169. mixitup.Base.prototype = {
  1170. constructor: mixitup.Base,
  1171. /**
  1172. * Calls any registered hooks for the provided action.
  1173. *
  1174. * @memberof mixitup.Base
  1175. * @private
  1176. * @instance
  1177. * @since 2.0.0
  1178. * @param {string} actionName
  1179. * @param {Array<*>} args
  1180. * @return {void}
  1181. */
  1182. callActions: function(actionName, args) {
  1183. var self = this,
  1184. hooks = self.constructor.actions[actionName],
  1185. extensionName = '';
  1186. if (!hooks || h.isEmptyObject(hooks)) return;
  1187. for (extensionName in hooks) {
  1188. hooks[extensionName].apply(self, args);
  1189. }
  1190. },
  1191. /**
  1192. * Calls any registered hooks for the provided filter.
  1193. *
  1194. * @memberof mixitup.Base
  1195. * @private
  1196. * @instance
  1197. * @since 2.0.0
  1198. * @param {string} filterName
  1199. * @param {*} input
  1200. * @param {Array<*>} args
  1201. * @return {*}
  1202. */
  1203. callFilters: function(filterName, input, args) {
  1204. var self = this,
  1205. hooks = self.constructor.filters[filterName],
  1206. output = input,
  1207. extensionName = '';
  1208. if (!hooks || h.isEmptyObject(hooks)) return output;
  1209. args = args || [];
  1210. for (extensionName in hooks) {
  1211. args = h.arrayFromList(args);
  1212. args.unshift(output);
  1213. output = hooks[extensionName].apply(self, args);
  1214. }
  1215. return output;
  1216. }
  1217. };
  1218. /**
  1219. * The BaseStatic class holds a set of static methods which are then added to all other
  1220. * extensible MixItUp classes as a means of integrating extensions via the addition of new
  1221. * methods and/or actions and hooks.
  1222. *
  1223. * @constructor
  1224. * @namespace
  1225. * @memberof mixitup
  1226. * @private
  1227. * @since 3.0.0
  1228. */
  1229. mixitup.BaseStatic = function() {
  1230. this.actions = {};
  1231. this.filters = {};
  1232. /**
  1233. * Performs a shallow extend on the class's prototype, adding one or more new members to
  1234. * the class in a single operation.
  1235. *
  1236. * @memberof mixitup.BaseStatic
  1237. * @public
  1238. * @static
  1239. * @since 2.1.0
  1240. * @param {object} extension
  1241. * @return {void}
  1242. */
  1243. this.extend = function(extension) {
  1244. h.extend(this.prototype, extension);
  1245. };
  1246. /**
  1247. * Registers a function to be called on the action hook of the provided name.
  1248. *
  1249. * @memberof mixitup.BaseStatic
  1250. * @public
  1251. * @static
  1252. * @since 2.1.0
  1253. * @param {string} hookName
  1254. * @param {string} extensionName
  1255. * @param {function} func
  1256. * @return {void}
  1257. */
  1258. this.registerAction = function(hookName, extensionName, func) {
  1259. (this.actions[hookName] = this.actions[hookName] || {})[extensionName] = func;
  1260. };
  1261. /**
  1262. * Registers a function to be called on the filter of the provided name.
  1263. *
  1264. * @memberof mixitup.BaseStatic
  1265. * @public
  1266. * @static
  1267. * @since 2.1.0
  1268. * @param {string} hookName
  1269. * @param {string} extensionName
  1270. * @param {function} func
  1271. * @return {void}
  1272. */
  1273. this.registerFilter = function(hookName, extensionName, func) {
  1274. (this.filters[hookName] = this.filters[hookName] || {})[extensionName] = func;
  1275. };
  1276. };
  1277. /**
  1278. * The `mixitup.Features` class performs all feature and CSS prefix detection
  1279. * neccessary for MixItUp to function correctly, as well as storing various
  1280. * string and array constants. All feature decection is on evaluation of the
  1281. * library and stored in a singleton instance for use by other internal classes.
  1282. *
  1283. * @constructor
  1284. * @namespace
  1285. * @memberof mixitup
  1286. * @private
  1287. * @since 3.0.0
  1288. */
  1289. mixitup.Features = function() {
  1290. mixitup.Base.call(this);
  1291. this.callActions('beforeConstruct');
  1292. this.boxSizingPrefix = '';
  1293. this.transformPrefix = '';
  1294. this.transitionPrefix = '';
  1295. this.boxSizingPrefix = '';
  1296. this.transformProp = '';
  1297. this.transformRule = '';
  1298. this.transitionProp = '';
  1299. this.perspectiveProp = '';
  1300. this.perspectiveOriginProp = '';
  1301. this.has = new mixitup.Has();
  1302. this.canary = null;
  1303. this.BOX_SIZING_PROP = 'boxSizing';
  1304. this.TRANSITION_PROP = 'transition';
  1305. this.TRANSFORM_PROP = 'transform';
  1306. this.PERSPECTIVE_PROP = 'perspective';
  1307. this.PERSPECTIVE_ORIGIN_PROP = 'perspectiveOrigin';
  1308. this.VENDORS = ['Webkit', 'moz', 'O', 'ms'];
  1309. this.TWEENABLE = [
  1310. 'opacity',
  1311. 'width', 'height',
  1312. 'marginRight', 'marginBottom',
  1313. 'x', 'y',
  1314. 'scale',
  1315. 'translateX', 'translateY', 'translateZ',
  1316. 'rotateX', 'rotateY', 'rotateZ'
  1317. ];
  1318. this.callActions('afterConstruct');
  1319. };
  1320. mixitup.BaseStatic.call(mixitup.Features);
  1321. mixitup.Features.prototype = Object.create(mixitup.Base.prototype);
  1322. h.extend(mixitup.Features.prototype,
  1323. /** @lends mixitup.Features */
  1324. {
  1325. constructor: mixitup.Features,
  1326. /**
  1327. * @private
  1328. * @return {void}
  1329. */
  1330. init: function() {
  1331. var self = this;
  1332. self.callActions('beforeInit', arguments);
  1333. self.canary = document.createElement('div');
  1334. self.setPrefixes();
  1335. self.runTests();
  1336. self.callActions('beforeInit', arguments);
  1337. },
  1338. /**
  1339. * @private
  1340. * @return {void}
  1341. */
  1342. runTests: function() {
  1343. var self = this;
  1344. self.callActions('beforeRunTests', arguments);
  1345. self.has.promises = typeof window.Promise === 'function';
  1346. self.has.transitions = self.transitionPrefix !== 'unsupported';
  1347. self.callActions('afterRunTests', arguments);
  1348. h.freeze(self.has);
  1349. },
  1350. /**
  1351. * @private
  1352. * @return {void}
  1353. */
  1354. setPrefixes: function() {
  1355. var self = this;
  1356. self.callActions('beforeSetPrefixes', arguments);
  1357. self.transitionPrefix = h.getPrefix(self.canary, 'Transition', self.VENDORS);
  1358. self.transformPrefix = h.getPrefix(self.canary, 'Transform', self.VENDORS);
  1359. self.boxSizingPrefix = h.getPrefix(self.canary, 'BoxSizing', self.VENDORS);
  1360. self.boxSizingProp = self.boxSizingPrefix ?
  1361. self.boxSizingPrefix + h.pascalCase(self.BOX_SIZING_PROP) : self.BOX_SIZING_PROP;
  1362. self.transitionProp = self.transitionPrefix ?
  1363. self.transitionPrefix + h.pascalCase(self.TRANSITION_PROP) : self.TRANSITION_PROP;
  1364. self.transformProp = self.transformPrefix ?
  1365. self.transformPrefix + h.pascalCase(self.TRANSFORM_PROP) : self.TRANSFORM_PROP;
  1366. self.transformRule = self.transformPrefix ?
  1367. '-' + self.transformPrefix + '-' + self.TRANSFORM_PROP : self.TRANSFORM_PROP;
  1368. self.perspectiveProp = self.transformPrefix ?
  1369. self.transformPrefix + h.pascalCase(self.PERSPECTIVE_PROP) : self.PERSPECTIVE_PROP;
  1370. self.perspectiveOriginProp = self.transformPrefix ?
  1371. self.transformPrefix + h.pascalCase(self.PERSPECTIVE_ORIGIN_PROP) :
  1372. self.PERSPECTIVE_ORIGIN_PROP;
  1373. self.callActions('afterSetPrefixes', arguments);
  1374. }
  1375. });
  1376. /**
  1377. * @constructor
  1378. * @memberof mixitup
  1379. * @private
  1380. * @since 3.0.0
  1381. */
  1382. mixitup.Has = function() {
  1383. this.transitions = false;
  1384. this.promises = false;
  1385. h.seal(this);
  1386. };
  1387. // Assign a singleton instance to `mixitup.features` and initialise:
  1388. mixitup.features = new mixitup.Features();
  1389. mixitup.features.init();
  1390. /**
  1391. * A group of properties defining the mixer's animation and effects settings.
  1392. *
  1393. * @constructor
  1394. * @memberof mixitup.Config
  1395. * @name animation
  1396. * @namespace
  1397. * @public
  1398. * @since 2.0.0
  1399. */
  1400. mixitup.ConfigAnimation = function() {
  1401. mixitup.Base.call(this);
  1402. this.callActions('beforeConstruct');
  1403. /**
  1404. * A boolean dictating whether or not animation should be enabled for the MixItUp instance.
  1405. * If `false`, all operations will occur instantly and syncronously, although callback
  1406. * functions and any returned promises will still be fulfilled.
  1407. *
  1408. * @example <caption>Example: Create a mixer with all animations disabled</caption>
  1409. * var mixer = mixitup(containerEl, {
  1410. * animation: {
  1411. * enable: false
  1412. * }
  1413. * });
  1414. *
  1415. * @name enable
  1416. * @memberof mixitup.Config.animation
  1417. * @instance
  1418. * @type {boolean}
  1419. * @default true
  1420. */
  1421. this.enable = true;
  1422. /**
  1423. * A string of one or more space-seperated properties to which transitions will be
  1424. * applied for all filtering animations.
  1425. *
  1426. * Properties can be listed any order or combination, although they will be applied in a specific
  1427. * predefined order to produce consistent results.
  1428. *
  1429. * To learn more about available effects, experiment with our <a href="https://www.kunkalabs.com/mixitup/">
  1430. * sandbox demo</a> and try out the "Export config" button in the Animation options drop down.
  1431. *
  1432. * @example <caption>Example: Apply "fade" and "translateZ" effects to all animations</caption>
  1433. * // As targets are filtered in and out, they will fade between
  1434. * // opacity 1 and 0 and transform between translateZ(-100px) and
  1435. * // translateZ(0).
  1436. *
  1437. * var mixer = mixitup(containerEl, {
  1438. * animation: {
  1439. * effects: 'fade translateZ(-100px)'
  1440. * }
  1441. * });
  1442. *
  1443. * @name effects
  1444. * @memberof mixitup.Config.animation
  1445. * @instance
  1446. * @type {string}
  1447. * @default 'fade scale'
  1448. */
  1449. this.effects = 'fade scale';
  1450. /**
  1451. * A string of one or more space-seperated effects to be applied only to filter-in
  1452. * animations, overriding `config.animation.effects` if set.
  1453. *
  1454. * @example <caption>Example: Apply downwards vertical translate to targets being filtered in</caption>
  1455. *
  1456. * var mixer = mixitup(containerEl, {
  1457. * animation: {
  1458. * effectsIn: 'fade translateY(-100%)'
  1459. * }
  1460. * });
  1461. *
  1462. * @name effectsIn
  1463. * @memberof mixitup.Config.animation
  1464. * @instance
  1465. * @type {string}
  1466. * @default ''
  1467. */
  1468. this.effectsIn = '';
  1469. /**
  1470. * A string of one or more space-seperated effects to be applied only to filter-out
  1471. * animations, overriding `config.animation.effects` if set.
  1472. *
  1473. * @example <caption>Example: Apply upwards vertical translate to targets being filtered out</caption>
  1474. *
  1475. * var mixer = mixitup(containerEl, {
  1476. * animation: {
  1477. * effectsOut: 'fade translateY(-100%)'
  1478. * }
  1479. * });
  1480. *
  1481. * @name effectsOut
  1482. * @memberof mixitup.Config.animation
  1483. * @instance
  1484. * @type {string}
  1485. * @default ''
  1486. */
  1487. this.effectsOut = '';
  1488. /**
  1489. * An integer dictating the duration of all MixItUp animations in milliseconds, not
  1490. * including any additional delay apllied via the `'stagger'` effect.
  1491. *
  1492. * @example <caption>Example: Apply an animation duration of 200ms to all mixitup animations</caption>
  1493. *
  1494. * var mixer = mixitup(containerEl, {
  1495. * animation: {
  1496. * duration: 200
  1497. * }
  1498. * });
  1499. *
  1500. * @name duration
  1501. * @memberof mixitup.Config.animation
  1502. * @instance
  1503. * @type {number}
  1504. * @default 600
  1505. */
  1506. this.duration = 600;
  1507. /**
  1508. * A valid CSS3 transition-timing function or shorthand. For a full list of accepted
  1509. * values, visit <a href="http://easings.net" target="_blank">easings.net</a>.
  1510. *
  1511. * @example <caption>Example 1: Apply "ease-in-out" easing to all animations</caption>
  1512. *
  1513. * var mixer = mixitup(containerEl, {
  1514. * animation: {
  1515. * easing: 'ease-in-out'
  1516. * }
  1517. * });
  1518. *
  1519. * @example <caption>Example 2: Apply a custom "cubic-bezier" easing function to all animations</caption>
  1520. * var mixer = mixitup(containerEl, {
  1521. * animation: {
  1522. * easing: 'cubic-bezier(0.645, 0.045, 0.355, 1)'
  1523. * }
  1524. * });
  1525. *
  1526. * @name easing
  1527. * @memberof mixitup.Config.animation
  1528. * @instance
  1529. * @type {string}
  1530. * @default 'ease'
  1531. */
  1532. this.easing = 'ease';
  1533. /**
  1534. * A boolean dictating whether or not to apply perspective to the MixItUp container
  1535. * during animations. By default, perspective is always applied and creates the
  1536. * illusion of three-dimensional space for effects such as `translateZ`, `rotateX`,
  1537. * and `rotateY`.
  1538. *
  1539. * You may wish to disable this and define your own perspective settings via CSS.
  1540. *
  1541. * @example <caption>Example: Prevent perspective from being applied to any 3D transforms</caption>
  1542. * var mixer = mixitup(containerEl, {
  1543. * animation: {
  1544. * applyPerspective: false
  1545. * }
  1546. * });
  1547. *
  1548. * @name applyPerspective
  1549. * @memberof mixitup.Config.animation
  1550. * @instance
  1551. * @type {bolean}
  1552. * @default true
  1553. */
  1554. this.applyPerspective = true;
  1555. /**
  1556. * The perspective distance value to be applied to the container during animations,
  1557. * affecting any 3D-transform-based effects.
  1558. *
  1559. * @example <caption>Example: Set a perspective distance of 2000px</caption>
  1560. * var mixer = mixitup(containerEl, {
  1561. * animation: {
  1562. * effects: 'rotateY(-25deg)',
  1563. * perspectiveDistance: '2000px'
  1564. * }
  1565. * });
  1566. *
  1567. * @name perspectiveDistance
  1568. * @memberof mixitup.Config.animation
  1569. * @instance
  1570. * @type {string}
  1571. * @default '3000px'
  1572. */
  1573. this.perspectiveDistance = '3000px';
  1574. /**
  1575. * The perspective-origin value to be applied to the container during animations,
  1576. * affecting any 3D-transform-based effects.
  1577. *
  1578. * @example <caption>Example: Set a perspective origin in the top-right of the container</caption>
  1579. * var mixer = mixitup(containerEl, {
  1580. * animation: {
  1581. * effects: 'transateZ(-200px)',
  1582. * perspectiveOrigin: '100% 0'
  1583. * }
  1584. * });
  1585. *
  1586. * @name perspectiveOrigin
  1587. * @memberof mixitup.Config.animation
  1588. * @instance
  1589. * @type {string}
  1590. * @default '50% 50%'
  1591. */
  1592. this.perspectiveOrigin = '50% 50%';
  1593. /**
  1594. * A boolean dictating whether or not to enable the queuing of operations.
  1595. *
  1596. * If `true` (default), and a control is clicked or an API call is made while another
  1597. * operation is progress, the operation will go into the queue and will be automatically exectuted
  1598. * when the previous operaitons is finished.
  1599. *
  1600. * If `false`, any requested operations will be ignored, and the `onMixBusy` callback and `mixBusy`
  1601. * event will be fired. If `debug.showWarnings` is enabled, a console warning will also occur.
  1602. *
  1603. * @example <caption>Example: Disable queuing</caption>
  1604. * var mixer = mixitup(containerEl, {
  1605. * animation: {
  1606. * queue: false
  1607. * }
  1608. * });
  1609. *
  1610. * @name queue
  1611. * @memberof mixitup.Config.animation
  1612. * @instance
  1613. * @type {boolean}
  1614. * @default true
  1615. */
  1616. this.queue = true;
  1617. /**
  1618. * An integer dictacting the maximum number of operations allowed in the queue at
  1619. * any time, when queuing is enabled.
  1620. *
  1621. * @example <caption>Example: Allow a maximum of 5 operations in the queue at any time</caption>
  1622. * var mixer = mixitup(containerEl, {
  1623. * animation: {
  1624. * queueLimit: 5
  1625. * }
  1626. * });
  1627. *
  1628. * @name queueLimit
  1629. * @memberof mixitup.Config.animation
  1630. * @instance
  1631. * @type {number}
  1632. * @default 3
  1633. */
  1634. this.queueLimit = 3;
  1635. /**
  1636. * A boolean dictating whether or not to transition the height and width of the
  1637. * container as elements are filtered in and out. If disabled, the container height
  1638. * will change abruptly.
  1639. *
  1640. * It may be desirable to disable this on mobile devices as the CSS `height` and
  1641. * `width` properties do not receive GPU-acceleration and can therefore cause stuttering.
  1642. *
  1643. * @example <caption>Example 1: Disable the transitioning of the container height and/or width</caption>
  1644. * var mixer = mixitup(containerEl, {
  1645. * animation: {
  1646. * animateResizeContainer: false
  1647. * }
  1648. * });
  1649. *
  1650. * @example <caption>Example 2: Disable the transitioning of the container height and/or width for mobile devices only</caption>
  1651. * var mixer = mixitup(containerEl, {
  1652. * animation: {
  1653. * animateResizeContainer: myFeatureTests.isMobile ? false : true
  1654. * }
  1655. * });
  1656. *
  1657. * @name animateResizeContainer
  1658. * @memberof mixitup.Config.animation
  1659. * @instance
  1660. * @type {boolean}
  1661. * @default true
  1662. */
  1663. this.animateResizeContainer = true;
  1664. /**
  1665. * A boolean dictating whether or not to transition the height and width of target
  1666. * elements as they change throughout the course of an animation.
  1667. *
  1668. * This is often a must for flex-box grid layouts where the size of target elements may change
  1669. * depending on final their position in relation to their siblings, or for `.changeLayout()`
  1670. * operations where the size of targets change between layouts.
  1671. *
  1672. * NB: This feature requires additional calculations and manipulation to non-hardware-accelerated
  1673. * properties which may adversely affect performance on slower devices, and is therefore
  1674. * disabled by default.
  1675. *
  1676. * @example <caption>Example: Enable the transitioning of target widths and heights</caption>
  1677. * var mixer = mixitup(containerEl, {
  1678. * animation: {
  1679. * animateResizeTargets: true
  1680. * }
  1681. * });
  1682. *
  1683. * @name animateResizeTargets
  1684. * @memberof mixitup.Config.animation
  1685. * @instance
  1686. * @type {boolean}
  1687. * @default false
  1688. */
  1689. this.animateResizeTargets = false;
  1690. /**
  1691. * A custom function used to manipulate the order in which the stagger delay is
  1692. * incremented when using the ‘stagger’ effect.
  1693. *
  1694. * When using the 'stagger' effect, the delay applied to each target element is incremented
  1695. * based on its index. You may create a custom function to manipulate the order in which the
  1696. * delay is incremented and create engaging non-linear stagger effects.
  1697. *
  1698. * The function receives the index of the target element as a parameter, and must
  1699. * return an integer which serves as the multiplier for the stagger delay.
  1700. *
  1701. * @example <caption>Example 1: Stagger target elements by column in a 3-column grid</caption>
  1702. * var mixer = mixitup(containerEl, {
  1703. * animation: {
  1704. * effects: 'fade stagger(100ms)',
  1705. * staggerSequence: function(i) {
  1706. * return i % 3;
  1707. * }
  1708. * }
  1709. * });
  1710. *
  1711. * @example <caption>Example 2: Using an algorithm to produce a more complex sequence</caption>
  1712. * var mixer = mixitup(containerEl, {
  1713. * animation: {
  1714. * effects: 'fade stagger(100ms)',
  1715. * staggerSequence: function(i) {
  1716. * return (2*i) - (5*((i/3) - ((1/3) * (i%3))));
  1717. * }
  1718. * }
  1719. * });
  1720. *
  1721. * @name staggerSequence
  1722. * @memberof mixitup.Config.animation
  1723. * @instance
  1724. * @type {function}
  1725. * @default null
  1726. */
  1727. this.staggerSequence = null;
  1728. /**
  1729. * A boolean dictating whether or not to reverse the direction of `translate`
  1730. * and `rotate` transforms for elements being filtered out.
  1731. *
  1732. * It can be used to create carousel-like animations where elements enter and exit
  1733. * from opposite directions. If enabled, the effect `translateX(-100%)` for elements
  1734. * being filtered in would become `translateX(100%)` for targets being filtered out.
  1735. *
  1736. * This functionality can also be achieved by providing seperate effects
  1737. * strings for `config.animation.effectsIn` and `config.animation.effectsOut`.
  1738. *
  1739. * @example <caption>Example: Reverse the desired direction on any translate/rotate effect for targets being filtered out</caption>
  1740. * // Elements being filtered in will be translated from '100%' to '0' while
  1741. * // elements being filtered out will be translated from 0 to '-100%'
  1742. *
  1743. * var mixer = mixitup(containerEl, {
  1744. * animation: {
  1745. * effects: 'fade translateX(100%)',
  1746. * reverseOut: true,
  1747. * nudge: false // Disable nudging to create a carousel-like effect
  1748. * }
  1749. * });
  1750. *
  1751. * @name reverseOut
  1752. * @memberof mixitup.Config.animation
  1753. * @instance
  1754. * @type {boolean}
  1755. * @default false
  1756. */
  1757. this.reverseOut = false;
  1758. /**
  1759. * A boolean dictating whether or not to "nudge" the animation path of targets
  1760. * when they are being filtered in and out simulatenously.
  1761. *
  1762. * This has been the default behavior of MixItUp since version 1, but it
  1763. * may be desirable to disable this effect when filtering directly from
  1764. * one exclusive set of targets to a different exclusive set of targets,
  1765. * to create a carousel-like effect, or a generally more subtle animation.
  1766. *
  1767. * @example <caption>Example: Disable the "nudging" of targets being filtered in and out simulatenously</caption>
  1768. *
  1769. * var mixer = mixitup(containerEl, {
  1770. * animation: {
  1771. * nudge: false
  1772. * }
  1773. * });
  1774. *
  1775. * @name nudge
  1776. * @memberof mixitup.Config.animation
  1777. * @instance
  1778. * @type {boolean}
  1779. * @default true
  1780. */
  1781. this.nudge = true;
  1782. /**
  1783. * A boolean dictating whether or not to clamp the height of the container while MixItUp's
  1784. * geometry tests are carried out before an operation.
  1785. *
  1786. * To prevent scroll-bar flicker, clamping is turned on by default. But in the case where the
  1787. * height of the container might affect its vertical positioning in the viewport
  1788. * (e.g. a vertically-centered container), this should be turned off to ensure accurate
  1789. * test results and a smooth animation.
  1790. *
  1791. * @example <caption>Example: Disable container height-clamping</caption>
  1792. *
  1793. * var mixer = mixitup(containerEl, {
  1794. * animation: {
  1795. * clampHeight: false
  1796. * }
  1797. * });
  1798. *
  1799. * @name clampHeight
  1800. * @memberof mixitup.Config.animation
  1801. * @instance
  1802. * @type {boolean}
  1803. * @default true
  1804. */
  1805. this.clampHeight = true;
  1806. /**
  1807. * A boolean dictating whether or not to clamp the width of the container while MixItUp's
  1808. * geometry tests are carried out before an operation.
  1809. *
  1810. * To prevent scroll-bar flicker, clamping is turned on by default. But in the case where the
  1811. * width of the container might affect its horitzontal positioning in the viewport
  1812. * (e.g. a horizontall-centered container), this should be turned off to ensure accurate
  1813. * test results and a smooth animation.
  1814. *
  1815. * @example <caption>Example: Disable container width-clamping</caption>
  1816. *
  1817. * var mixer = mixitup(containerEl, {
  1818. * animation: {
  1819. * clampWidth: false
  1820. * }
  1821. * });
  1822. *
  1823. * @name clampWidth
  1824. * @memberof mixitup.Config.animation
  1825. * @instance
  1826. * @type {boolean}
  1827. * @default true
  1828. */
  1829. this.clampWidth = true;
  1830. this.callActions('afterConstruct');
  1831. h.seal(this);
  1832. };
  1833. mixitup.BaseStatic.call(mixitup.ConfigAnimation);
  1834. mixitup.ConfigAnimation.prototype = Object.create(mixitup.Base.prototype);
  1835. mixitup.ConfigAnimation.prototype.constructor = mixitup.ConfigAnimation;
  1836. /**
  1837. * A group of properties relating to the behavior of the Mixer.
  1838. *
  1839. * @constructor
  1840. * @memberof mixitup.Config
  1841. * @name behavior
  1842. * @namespace
  1843. * @public
  1844. * @since 3.1.12
  1845. */
  1846. mixitup.ConfigBehavior = function() {
  1847. mixitup.Base.call(this);
  1848. this.callActions('beforeConstruct');
  1849. /**
  1850. * A boolean dictating whether to allow "live" sorting of the mixer.
  1851. *
  1852. * Because of the expensive nature of sorting, MixItUp makes use of several
  1853. * internal optimizations to skip redundant sorting operations, such as when
  1854. * the newly requested sort command is the same as the active one. The caveat
  1855. * to this optimization is that "live" edits to the value of a target's sorting
  1856. * attribute will be ignored when requesting a re-sort by the same attribute.
  1857. *
  1858. * By setting to `behavior.liveSort` to `true`, the mixer will always re-sort
  1859. * regardless of whether or not the sorting attribute and order have changed.
  1860. *
  1861. * @example <caption>Example: Enabling `liveSort` to allow for re-sorting</caption>
  1862. *
  1863. * var mixer = mixitup(containerEl, {
  1864. * behavior: {
  1865. * liveSort: true
  1866. * },
  1867. * load: {
  1868. * sort: 'edited:desc'
  1869. * }
  1870. * });
  1871. *
  1872. * var target = containerEl.children[3];
  1873. *
  1874. * console.log(target.getAttribute('data-edited')); // '2015-04-24'
  1875. *
  1876. * target.setAttribute('data-edited', '2017-08-10'); // Update the target's edited date
  1877. *
  1878. * mixer.sort('edited:desc')
  1879. * .then(function(state) {
  1880. * // The target is now at the top of the list
  1881. *
  1882. * console.log(state.targets[0] === target); // true
  1883. * });
  1884. *
  1885. * @name liveSort
  1886. * @memberof mixitup.Config.behavior
  1887. * @instance
  1888. * @type {boolean}
  1889. * @default false
  1890. */
  1891. this.liveSort = false;
  1892. this.callActions('afterConstruct');
  1893. h.seal(this);
  1894. };
  1895. mixitup.BaseStatic.call(mixitup.ConfigBehavior);
  1896. mixitup.ConfigBehavior.prototype = Object.create(mixitup.Base.prototype);
  1897. mixitup.ConfigBehavior.prototype.constructor = mixitup.ConfigBehavior;
  1898. /**
  1899. * A group of optional callback functions to be invoked at various
  1900. * points within the lifecycle of a mixer operation.
  1901. *
  1902. * Each function is analogous to an event of the same name triggered from the
  1903. * container element, and is invoked immediately after it.
  1904. *
  1905. * All callback functions receive the current `state` object as their first
  1906. * argument, as well as other more specific arguments described below.
  1907. *
  1908. * @constructor
  1909. * @memberof mixitup.Config
  1910. * @name callbacks
  1911. * @namespace
  1912. * @public
  1913. * @since 2.0.0
  1914. */
  1915. mixitup.ConfigCallbacks = function() {
  1916. mixitup.Base.call(this);
  1917. this.callActions('beforeConstruct');
  1918. /**
  1919. * A callback function invoked immediately after any MixItUp operation is requested
  1920. * and before animations have begun.
  1921. *
  1922. * A second `futureState` argument is passed to the function which represents the final
  1923. * state of the mixer once the requested operation has completed.
  1924. *
  1925. * @example <caption>Example: Adding an `onMixStart` callback function</caption>
  1926. * var mixer = mixitup(containerEl, {
  1927. * callbacks: {
  1928. * onMixStart: function(state, futureState) {
  1929. * console.log('Starting operation...');
  1930. * }
  1931. * }
  1932. * });
  1933. *
  1934. * @name onMixStart
  1935. * @memberof mixitup.Config.callbacks
  1936. * @instance
  1937. * @type {function}
  1938. * @default null
  1939. */
  1940. this.onMixStart = null;
  1941. /**
  1942. * A callback function invoked when a MixItUp operation is requested while another
  1943. * operation is in progress, and the animation queue is full, or queueing
  1944. * is disabled.
  1945. *
  1946. * @example <caption>Example: Adding an `onMixBusy` callback function</caption>
  1947. * var mixer = mixitup(containerEl, {
  1948. * callbacks: {
  1949. * onMixBusy: function(state) {
  1950. * console.log('Mixer busy');
  1951. * }
  1952. * }
  1953. * });
  1954. *
  1955. * @name onMixBusy
  1956. * @memberof mixitup.Config.callbacks
  1957. * @instance
  1958. * @type {function}
  1959. * @default null
  1960. */
  1961. this.onMixBusy = null;
  1962. /**
  1963. * A callback function invoked after any MixItUp operation has completed, and the
  1964. * state has been updated.
  1965. *
  1966. * @example <caption>Example: Adding an `onMixEnd` callback function</caption>
  1967. * var mixer = mixitup(containerEl, {
  1968. * callbacks: {
  1969. * onMixEnd: function(state) {
  1970. * console.log('Operation complete');
  1971. * }
  1972. * }
  1973. * });
  1974. *
  1975. * @name onMixEnd
  1976. * @memberof mixitup.Config.callbacks
  1977. * @instance
  1978. * @type {function}
  1979. * @default null
  1980. */
  1981. this.onMixEnd = null;
  1982. /**
  1983. * A callback function invoked whenever an operation "fails", i.e. no targets
  1984. * could be found matching the requested filter.
  1985. *
  1986. * @example <caption>Example: Adding an `onMixFail` callback function</caption>
  1987. * var mixer = mixitup(containerEl, {
  1988. * callbacks: {
  1989. * onMixFail: function(state) {
  1990. * console.log('No items could be found matching the requested filter');
  1991. * }
  1992. * }
  1993. * });
  1994. *
  1995. * @name onMixFail
  1996. * @memberof mixitup.Config.callbacks
  1997. * @instance
  1998. * @type {function}
  1999. * @default null
  2000. */
  2001. this.onMixFail = null;
  2002. /**
  2003. * A callback function invoked whenever a MixItUp control is clicked, and before its
  2004. * respective operation is requested.
  2005. *
  2006. * The clicked element is assigned to the `this` keyword within the function. The original
  2007. * click event is passed to the function as the second argument, which can be useful if
  2008. * using `<a>` tags as controls where the default behavior needs to be prevented.
  2009. *
  2010. * Returning `false` from the callback will prevent the control click from triggering
  2011. * an operation.
  2012. *
  2013. * @example <caption>Example 1: Adding an `onMixClick` callback function</caption>
  2014. * var mixer = mixitup(containerEl, {
  2015. * callbacks: {
  2016. * onMixClick: function(state, originalEvent) {
  2017. * console.log('The control "' + this.innerText + '" was clicked');
  2018. * }
  2019. * }
  2020. * });
  2021. *
  2022. * @example <caption>Example 2: Using `onMixClick` to manipulate the original click event</caption>
  2023. * var mixer = mixitup(containerEl, {
  2024. * callbacks: {
  2025. * onMixClick: function(state, originalEvent) {
  2026. * // Prevent original click event from bubbling up:
  2027. * originalEvent.stopPropagation();
  2028. *
  2029. * // Prevent default behavior of clicked element:
  2030. * originalEvent.preventDefault();
  2031. * }
  2032. * }
  2033. * });
  2034. *
  2035. * @example <caption>Example 3: Using `onMixClick` to conditionally cancel operations</caption>
  2036. * var mixer = mixitup(containerEl, {
  2037. * callbacks: {
  2038. * onMixClick: function(state, originalEvent) {
  2039. * // Perform some conditional check:
  2040. *
  2041. * if (myApp.isLoading) {
  2042. * // By returning false, we can prevent the control click from triggering an operation.
  2043. *
  2044. * return false;
  2045. * }
  2046. * }
  2047. * }
  2048. * });
  2049. *
  2050. * @name onMixClick
  2051. * @memberof mixitup.Config.callbacks
  2052. * @instance
  2053. * @type {function}
  2054. * @default null
  2055. */
  2056. this.onMixClick = null;
  2057. this.callActions('afterConstruct');
  2058. h.seal(this);
  2059. };
  2060. mixitup.BaseStatic.call(mixitup.ConfigCallbacks);
  2061. mixitup.ConfigCallbacks.prototype = Object.create(mixitup.Base.prototype);
  2062. mixitup.ConfigCallbacks.prototype.constructor = mixitup.ConfigCallbacks;
  2063. /**
  2064. * A group of properties relating to clickable control elements.
  2065. *
  2066. * @constructor
  2067. * @memberof mixitup.Config
  2068. * @name controls
  2069. * @namespace
  2070. * @public
  2071. * @since 2.0.0
  2072. */
  2073. mixitup.ConfigControls = function() {
  2074. mixitup.Base.call(this);
  2075. this.callActions('beforeConstruct');
  2076. /**
  2077. * A boolean dictating whether or not controls should be enabled for the mixer instance.
  2078. *
  2079. * If `true` (default behavior), MixItUp will search the DOM for any clickable elements with
  2080. * `data-filter`, `data-sort` or `data-toggle` attributes, and bind them for click events.
  2081. *
  2082. * If `false`, no click handlers will be bound, and all functionality must therefore be performed
  2083. * via the mixer's API methods.
  2084. *
  2085. * If you do not intend to use the default controls, setting this property to `false` will
  2086. * marginally improve the startup time of your mixer instance, and will also prevent any other active
  2087. * mixer instances in the DOM which are bound to controls from controlling the instance.
  2088. *
  2089. * @example <caption>Example: Disabling controls</caption>
  2090. * var mixer = mixitup(containerEl, {
  2091. * controls: {
  2092. * enable: false
  2093. * }
  2094. * });
  2095. *
  2096. * // With the default controls disabled, we can only control
  2097. * // the mixer via its API methods, e.g.:
  2098. *
  2099. * mixer.filter('.cat-1');
  2100. *
  2101. * @name enable
  2102. * @memberof mixitup.Config.controls
  2103. * @instance
  2104. * @type {boolean}
  2105. * @default true
  2106. */
  2107. this.enable = true;
  2108. /**
  2109. * A boolean dictating whether or not to use event delegation when binding click events
  2110. * to the default controls.
  2111. *
  2112. * If `false` (default behavior), each control button in the DOM will be found and
  2113. * individually bound when a mixer is instantiated, with their corresponding actions
  2114. * cached for performance.
  2115. *
  2116. * If `true`, a single click handler will be applied to the `window` (or container element - see
  2117. * `config.controls.scope`), and any click events triggered by elements with `data-filter`,
  2118. * `data-sort` or `data-toggle` attributes present will be handled as they propagate upwards.
  2119. *
  2120. * If you require a user interface where control buttons may be added, removed, or changed during the
  2121. * lifetime of a mixer, `controls.live` should be set to `true`. There is a marginal but unavoidable
  2122. * performance deficit when using live controls, as the value of each control button must be read
  2123. * from the DOM in real time once the click event has propagated.
  2124. *
  2125. * @example <caption>Example: Setting live controls</caption>
  2126. * var mixer = mixitup(containerEl, {
  2127. * controls: {
  2128. * live: true
  2129. * }
  2130. * });
  2131. *
  2132. * // Control buttons can now be added, remove and changed without breaking
  2133. * // the mixer's UI
  2134. *
  2135. * @name live
  2136. * @memberof mixitup.Config.controls
  2137. * @instance
  2138. * @type {boolean}
  2139. * @default true
  2140. */
  2141. this.live = false;
  2142. /**
  2143. * A string dictating the "scope" to use when binding or querying the default controls. The available
  2144. * values are `'global'` or `'local'`.
  2145. *
  2146. * When set to `'global'` (default behavior), MixItUp will query the entire document for control buttons
  2147. * to bind, or delegate click events from (see `config.controls.live`).
  2148. *
  2149. * When set to `'local'`, MixItUp will only query (or bind click events to) its own container element.
  2150. * This may be desireable if you require multiple active mixer instances within the same document, with
  2151. * controls that would otherwise intefere with each other if scoped globally.
  2152. *
  2153. * Conversely, if you wish to control multiple instances with a single UI, you would create one
  2154. * set of controls and keep the controls scope of each mixer set to `global`.
  2155. *
  2156. * @example <caption>Example: Setting 'local' scoped controls</caption>
  2157. * var mixerOne = mixitup(containerOne, {
  2158. * controls: {
  2159. * scope: 'local'
  2160. * }
  2161. * });
  2162. *
  2163. * var mixerTwo = mixitup(containerTwo, {
  2164. * controls: {
  2165. * scope: 'local'
  2166. * }
  2167. * });
  2168. *
  2169. * // Both mixers can now exist within the same document with
  2170. * // isolated controls placed within their container elements.
  2171. *
  2172. * @name scope
  2173. * @memberof mixitup.Config.controls
  2174. * @instance
  2175. * @type {string}
  2176. * @default 'global'
  2177. */
  2178. this.scope = 'global'; // enum: ['local' ,'global']
  2179. /**
  2180. * A string dictating the type of logic to apply when concatenating the filter selectors of
  2181. * active toggle buttons (i.e. any clickable element with a `data-toggle` attribute).
  2182. *
  2183. * If set to `'or'` (default behavior), selectors will be concatenated together as
  2184. * a comma-seperated list. For example:
  2185. *
  2186. * `'.cat-1, .cat-2'` (shows any elements matching `'.cat-1'` OR `'.cat-2'`)
  2187. *
  2188. * If set to `'and'`, selectors will be directly concatenated together. For example:
  2189. *
  2190. * `'.cat-1.cat-2'` (shows any elements which match both `'.cat-1'` AND `'.cat-2'`)
  2191. *
  2192. * @example <caption>Example: Setting "and" toggle logic</caption>
  2193. * var mixer = mixitup(containerEl, {
  2194. * controls: {
  2195. * toggleLogic: 'and'
  2196. * }
  2197. * });
  2198. *
  2199. * @name toggleLogic
  2200. * @memberof mixitup.Config.controls
  2201. * @instance
  2202. * @type {string}
  2203. * @default 'or'
  2204. */
  2205. this.toggleLogic = 'or'; // enum: ['or', 'and']
  2206. /**
  2207. * A string dictating the filter behavior when all toggles are inactive.
  2208. *
  2209. * When set to `'all'` (default behavior), *all* targets will be shown by default
  2210. * when no toggles are active, or at the moment all active toggles are toggled off.
  2211. *
  2212. * When set to `'none'`, no targets will be shown by default when no toggles are
  2213. * active, or at the moment all active toggles are toggled off.
  2214. *
  2215. * @example <caption>Example 1: Setting the default toggle behavior to `'all'`</caption>
  2216. * var mixer = mixitup(containerEl, {
  2217. * controls: {
  2218. * toggleDefault: 'all'
  2219. * }
  2220. * });
  2221. *
  2222. * mixer.toggleOn('.cat-2')
  2223. * .then(function() {
  2224. * // Deactivate all active toggles
  2225. *
  2226. * return mixer.toggleOff('.cat-2')
  2227. * })
  2228. * .then(function(state) {
  2229. * console.log(state.activeFilter.selector); // 'all'
  2230. * console.log(state.totalShow); // 12
  2231. * });
  2232. *
  2233. * @example <caption>Example 2: Setting the default toggle behavior to `'none'`</caption>
  2234. * var mixer = mixitup(containerEl, {
  2235. * controls: {
  2236. * toggleDefault: 'none'
  2237. * }
  2238. * });
  2239. *
  2240. * mixer.toggleOn('.cat-2')
  2241. * .then(function() {
  2242. * // Deactivate all active toggles
  2243. *
  2244. * return mixer.toggleOff('.cat-2')
  2245. * })
  2246. * .then(function(state) {
  2247. * console.log(state.activeFilter.selector); // 'none'
  2248. * console.log(state.totalShow); // 0
  2249. * });
  2250. *
  2251. * @name toggleDefault
  2252. * @memberof mixitup.Config.controls
  2253. * @instance
  2254. * @type {string}
  2255. * @default 'all'
  2256. */
  2257. this.toggleDefault = 'all'; // enum: ['all', 'none']
  2258. this.callActions('afterConstruct');
  2259. h.seal(this);
  2260. };
  2261. mixitup.BaseStatic.call(mixitup.ConfigControls);
  2262. mixitup.ConfigControls.prototype = Object.create(mixitup.Base.prototype);
  2263. mixitup.ConfigControls.prototype.constructor = mixitup.ConfigControls;
  2264. /**
  2265. * A group of properties defining the output and structure of class names programmatically
  2266. * added to controls and containers to reflect the state of the mixer.
  2267. *
  2268. * Most commonly, class names are added to controls by MixItUp to indicate that
  2269. * the control is active so that it can be styled accordingly - `'mixitup-control-active'` by default.
  2270. *
  2271. * Using a "BEM" like structure, each classname is broken into the three parts:
  2272. * a block namespace (`'mixitup'`), an element name (e.g. `'control'`), and an optional modifier
  2273. * name (e.g. `'active'`) reflecting the state of the element.
  2274. *
  2275. * By default, each part of the classname is concatenated together using single hyphens as
  2276. * delineators, but this can be easily customised to match the naming convention and style of
  2277. * your project.
  2278. *
  2279. * @constructor
  2280. * @memberof mixitup.Config
  2281. * @name classNames
  2282. * @namespace
  2283. * @public
  2284. * @since 3.0.0
  2285. */
  2286. mixitup.ConfigClassNames = function() {
  2287. mixitup.Base.call(this);
  2288. this.callActions('beforeConstruct');
  2289. /**
  2290. * The "block" portion, or top-level namespace added to the start of any class names created by MixItUp.
  2291. *
  2292. * @example <caption>Example 1: changing the `config.classNames.block` value</caption>
  2293. * var mixer = mixitup(containerEl, {
  2294. * classNames: {
  2295. * block: 'portfolio'
  2296. * }
  2297. * });
  2298. *
  2299. * // Active control output: "portfolio-control-active"
  2300. *
  2301. * @example <caption>Example 2: Removing `config.classNames.block`</caption>
  2302. * var mixer = mixitup(containerEl, {
  2303. * classNames: {
  2304. * block: ''
  2305. * }
  2306. * });
  2307. *
  2308. * // Active control output: "control-active"
  2309. *
  2310. * @name block
  2311. * @memberof mixitup.Config.classNames
  2312. * @instance
  2313. * @type {string}
  2314. * @default 'mixitup'
  2315. */
  2316. this.block = 'mixitup';
  2317. /**
  2318. * The "element" portion of the class name added to container.
  2319. *
  2320. * @name elementContainer
  2321. * @memberof mixitup.Config.classNames
  2322. * @instance
  2323. * @type {string}
  2324. * @default 'container'
  2325. */
  2326. this.elementContainer = 'container';
  2327. /**
  2328. * The "element" portion of the class name added to filter controls.
  2329. *
  2330. * By default, all filter, sort, multimix and toggle controls take the same element value of `'control'`, but
  2331. * each type's element value can be individually overwritten to match the unique classNames of your controls as needed.
  2332. *
  2333. * @example <caption>Example 1: changing the `config.classNames.elementFilter` value</caption>
  2334. * var mixer = mixitup(containerEl, {
  2335. * classNames: {
  2336. * elementFilter: 'filter'
  2337. * }
  2338. * });
  2339. *
  2340. * // Active filter output: "mixitup-filter-active"
  2341. *
  2342. * @example <caption>Example 2: changing the `config.classNames.block` and `config.classNames.elementFilter` values</caption>
  2343. * var mixer = mixitup(containerEl, {
  2344. * classNames: {
  2345. * block: 'portfolio',
  2346. * elementFilter: 'filter'
  2347. * }
  2348. * });
  2349. *
  2350. * // Active filter output: "portfolio-filter-active"
  2351. *
  2352. * @name elementFilter
  2353. * @memberof mixitup.Config.classNames
  2354. * @instance
  2355. * @type {string}
  2356. * @default 'control'
  2357. */
  2358. this.elementFilter = 'control';
  2359. /**
  2360. * The "element" portion of the class name added to sort controls.
  2361. *
  2362. * By default, all filter, sort, multimix and toggle controls take the same element value of `'control'`, but
  2363. * each type's element value can be individually overwritten to match the unique classNames of your controls as needed.
  2364. *
  2365. * @example <caption>Example 1: changing the `config.classNames.elementSort` value</caption>
  2366. * var mixer = mixitup(containerEl, {
  2367. * classNames: {
  2368. * elementSort: 'sort'
  2369. * }
  2370. * });
  2371. *
  2372. * // Active sort output: "mixitup-sort-active"
  2373. *
  2374. * @example <caption>Example 2: changing the `config.classNames.block` and `config.classNames.elementSort` values</caption>
  2375. * var mixer = mixitup(containerEl, {
  2376. * classNames: {
  2377. * block: 'portfolio',
  2378. * elementSort: 'sort'
  2379. * }
  2380. * });
  2381. *
  2382. * // Active sort output: "portfolio-sort-active"
  2383. *
  2384. * @name elementSort
  2385. * @memberof mixitup.Config.classNames
  2386. * @instance
  2387. * @type {string}
  2388. * @default 'control'
  2389. */
  2390. this.elementSort = 'control';
  2391. /**
  2392. * The "element" portion of the class name added to multimix controls.
  2393. *
  2394. * By default, all filter, sort, multimix and toggle controls take the same element value of `'control'`, but
  2395. * each type's element value can be individually overwritten to match the unique classNames of your controls as needed.
  2396. *
  2397. * @example <caption>Example 1: changing the `config.classNames.elementMultimix` value</caption>
  2398. * var mixer = mixitup(containerEl, {
  2399. * classNames: {
  2400. * elementMultimix: 'multimix'
  2401. * }
  2402. * });
  2403. *
  2404. * // Active multimix output: "mixitup-multimix-active"
  2405. *
  2406. * @example <caption>Example 2: changing the `config.classNames.block` and `config.classNames.elementMultimix` values</caption>
  2407. * var mixer = mixitup(containerEl, {
  2408. * classNames: {
  2409. * block: 'portfolio',
  2410. * elementSort: 'multimix'
  2411. * }
  2412. * });
  2413. *
  2414. * // Active multimix output: "portfolio-multimix-active"
  2415. *
  2416. * @name elementMultimix
  2417. * @memberof mixitup.Config.classNames
  2418. * @instance
  2419. * @type {string}
  2420. * @default 'control'
  2421. */
  2422. this.elementMultimix = 'control';
  2423. /**
  2424. * The "element" portion of the class name added to toggle controls.
  2425. *
  2426. * By default, all filter, sort, multimix and toggle controls take the same element value of `'control'`, but
  2427. * each type's element value can be individually overwritten to match the unique classNames of your controls as needed.
  2428. *
  2429. * @example <caption>Example 1: changing the `config.classNames.elementToggle` value</caption>
  2430. * var mixer = mixitup(containerEl, {
  2431. * classNames: {
  2432. * elementToggle: 'toggle'
  2433. * }
  2434. * });
  2435. *
  2436. * // Active toggle output: "mixitup-toggle-active"
  2437. *
  2438. * @example <caption>Example 2: changing the `config.classNames.block` and `config.classNames.elementToggle` values</caption>
  2439. * var mixer = mixitup(containerEl, {
  2440. * classNames: {
  2441. * block: 'portfolio',
  2442. * elementToggle: 'toggle'
  2443. * }
  2444. * });
  2445. *
  2446. * // Active toggle output: "portfolio-toggle-active"
  2447. *
  2448. * @name elementToggle
  2449. * @memberof mixitup.Config.classNames
  2450. * @instance
  2451. * @type {string}
  2452. * @default 'control'
  2453. */
  2454. this.elementToggle = 'control';
  2455. /**
  2456. * The "modifier" portion of the class name added to active controls.
  2457. * @name modifierActive
  2458. * @memberof mixitup.Config.classNames
  2459. * @instance
  2460. * @type {string}
  2461. * @default 'active'
  2462. */
  2463. this.modifierActive = 'active';
  2464. /**
  2465. * The "modifier" portion of the class name added to disabled controls.
  2466. *
  2467. * @name modifierDisabled
  2468. * @memberof mixitup.Config.classNames
  2469. * @instance
  2470. * @type {string}
  2471. * @default 'disabled'
  2472. */
  2473. this.modifierDisabled = 'disabled';
  2474. /**
  2475. * The "modifier" portion of the class name added to the container when in a "failed" state.
  2476. *
  2477. * @name modifierFailed
  2478. * @memberof mixitup.Config.classNames
  2479. * @instance
  2480. * @type {string}
  2481. * @default 'failed'
  2482. */
  2483. this.modifierFailed = 'failed';
  2484. /**
  2485. * The delineator used between the "block" and "element" portions of any class name added by MixItUp.
  2486. *
  2487. * If the block portion is ommited by setting it to an empty string, no delineator will be added.
  2488. *
  2489. * @example <caption>Example: changing the delineator to match BEM convention</caption>
  2490. * var mixer = mixitup(containerEl, {
  2491. * classNames: {
  2492. * delineatorElement: '__'
  2493. * }
  2494. * });
  2495. *
  2496. * // example active control output: "mixitup__control-active"
  2497. *
  2498. * @name delineatorElement
  2499. * @memberof mixitup.Config.classNames
  2500. * @instance
  2501. * @type {string}
  2502. * @default '-'
  2503. */
  2504. this.delineatorElement = '-';
  2505. /**
  2506. * The delineator used between the "element" and "modifier" portions of any class name added by MixItUp.
  2507. *
  2508. * If the element portion is ommited by setting it to an empty string, no delineator will be added.
  2509. *
  2510. * @example <caption>Example: changing both delineators to match BEM convention</caption>
  2511. * var mixer = mixitup(containerEl, {
  2512. * classNames: {
  2513. * delineatorElement: '__'
  2514. * delineatorModifier: '--'
  2515. * }
  2516. * });
  2517. *
  2518. * // Active control output: "mixitup__control--active"
  2519. *
  2520. * @name delineatorModifier
  2521. * @memberof mixitup.Config.classNames
  2522. * @instance
  2523. * @type {string}
  2524. * @default '-'
  2525. */
  2526. this.delineatorModifier = '-';
  2527. this.callActions('afterConstruct');
  2528. h.seal(this);
  2529. };
  2530. mixitup.BaseStatic.call(mixitup.ConfigClassNames);
  2531. mixitup.ConfigClassNames.prototype = Object.create(mixitup.Base.prototype);
  2532. mixitup.ConfigClassNames.prototype.constructor = mixitup.ConfigClassNames;
  2533. /**
  2534. * A group of properties relating to MixItUp's dataset API.
  2535. *
  2536. * @constructor
  2537. * @memberof mixitup.Config
  2538. * @name data
  2539. * @namespace
  2540. * @public
  2541. * @since 3.0.0
  2542. */
  2543. mixitup.ConfigData = function() {
  2544. mixitup.Base.call(this);
  2545. this.callActions('beforeConstruct');
  2546. /**
  2547. * A string specifying the name of the key containing your data model's unique
  2548. * identifier (UID). To use the dataset API, a UID key must be specified and
  2549. * be present and unique on all objects in the dataset you provide to MixItUp.
  2550. *
  2551. * For example, if your dataset is made up of MongoDB documents, the UID
  2552. * key would be `'id'` or `'_id'`.
  2553. *
  2554. * @example <caption>Example: Setting the UID to `'id'`</caption>
  2555. * var mixer = mixitup(containerEl, {
  2556. * data: {
  2557. * uidKey: 'id'
  2558. * }
  2559. * });
  2560. *
  2561. * @name uidKey
  2562. * @memberof mixitup.Config.data
  2563. * @instance
  2564. * @type {string}
  2565. * @default ''
  2566. */
  2567. this.uidKey = '';
  2568. /**
  2569. * A boolean dictating whether or not MixItUp should "dirty check" each object in
  2570. * your dataset for changes whenever `.dataset()` is called, and re-render any targets
  2571. * for which a change is found.
  2572. *
  2573. * Depending on the complexity of your data model, dirty checking can be expensive
  2574. * and is therefore disabled by default.
  2575. *
  2576. * NB: For changes to be detected, a new immutable instance of the edited model must be
  2577. * provided to mixitup, rather than manipulating properties on the existing instance.
  2578. * If your changes are a result of a DB write and read, you will most likely be calling
  2579. * `.dataset()` with a clean set of objects each time, so this will not be an issue.
  2580. *
  2581. * @example <caption>Example: Enabling dirty checking</caption>
  2582. *
  2583. * var myDataset = [
  2584. * {
  2585. * id: 0,
  2586. * title: "Blog Post Title 0"
  2587. * ...
  2588. * },
  2589. * {
  2590. * id: 1,
  2591. * title: "Blog Post Title 1"
  2592. * ...
  2593. * }
  2594. * ];
  2595. *
  2596. * // Instantiate a mixer with a pre-loaded dataset, and a target renderer
  2597. * // function defined
  2598. *
  2599. * var mixer = mixitup(containerEl, {
  2600. * data: {
  2601. * uidKey: 'id',
  2602. * dirtyCheck: true
  2603. * },
  2604. * load: {
  2605. * dataset: myDataset
  2606. * },
  2607. * render: {
  2608. * target: function() { ... }
  2609. * }
  2610. * });
  2611. *
  2612. * // For illustration, we will clone and edit the second object in the dataset.
  2613. * // NB: this would typically be done server-side in response to a DB update,
  2614. * and then re-queried via an API.
  2615. *
  2616. * myDataset[1] = Object.assign({}, myDataset[1]);
  2617. *
  2618. * myDataset[1].title = 'Blog Post Title 11';
  2619. *
  2620. * mixer.dataset(myDataset)
  2621. * .then(function() {
  2622. * // the target with ID "1", will be re-rendered reflecting its new title
  2623. * });
  2624. *
  2625. * @name dirtyCheck
  2626. * @memberof mixitup.Config.data
  2627. * @instance
  2628. * @type {boolean}
  2629. * @default false
  2630. */
  2631. this.dirtyCheck = false;
  2632. this.callActions('afterConstruct');
  2633. h.seal(this);
  2634. };
  2635. mixitup.BaseStatic.call(mixitup.ConfigData);
  2636. mixitup.ConfigData.prototype = Object.create(mixitup.Base.prototype);
  2637. mixitup.ConfigData.prototype.constructor = mixitup.ConfigData;
  2638. /**
  2639. * A group of properties allowing the toggling of various debug features.
  2640. *
  2641. * @constructor
  2642. * @memberof mixitup.Config
  2643. * @name debug
  2644. * @namespace
  2645. * @public
  2646. * @since 3.0.0
  2647. */
  2648. mixitup.ConfigDebug = function() {
  2649. mixitup.Base.call(this);
  2650. this.callActions('beforeConstruct');
  2651. /**
  2652. * A boolean dictating whether or not the mixer instance returned by the
  2653. * `mixitup()` factory function should expose private properties and methods.
  2654. *
  2655. * By default, mixer instances only expose their public API, but enabling
  2656. * debug mode will give you access to various mixer internals which may aid
  2657. * in debugging, or the authoring of extensions.
  2658. *
  2659. * @example <caption>Example: Enabling debug mode</caption>
  2660. *
  2661. * var mixer = mixitup(containerEl, {
  2662. * debug: {
  2663. * enable: true
  2664. * }
  2665. * });
  2666. *
  2667. * // Private properties and methods will now be visible on the mixer instance:
  2668. *
  2669. * console.log(mixer);
  2670. *
  2671. * @name enable
  2672. * @memberof mixitup.Config.debug
  2673. * @instance
  2674. * @type {boolean}
  2675. * @default false
  2676. */
  2677. this.enable = false;
  2678. /**
  2679. * A boolean dictating whether or not warnings should be shown when various
  2680. * common gotchas occur.
  2681. *
  2682. * Warnings are intended to provide insights during development when something
  2683. * occurs that is not a fatal, but may indicate an issue with your integration,
  2684. * and are therefore turned on by default. However, you may wish to disable
  2685. * them in production.
  2686. *
  2687. * @example <caption>Example 1: Disabling warnings</caption>
  2688. *
  2689. * var mixer = mixitup(containerEl, {
  2690. * debug: {
  2691. * showWarnings: false
  2692. * }
  2693. * });
  2694. *
  2695. * @example <caption>Example 2: Disabling warnings based on environment</caption>
  2696. *
  2697. * var showWarnings = myAppConfig.environment === 'development' ? true : false;
  2698. *
  2699. * var mixer = mixitup(containerEl, {
  2700. * debug: {
  2701. * showWarnings: showWarnings
  2702. * }
  2703. * });
  2704. *
  2705. * @name showWarnings
  2706. * @memberof mixitup.Config.debug
  2707. * @instance
  2708. * @type {boolean}
  2709. * @default true
  2710. */
  2711. this.showWarnings = true;
  2712. /**
  2713. * Used for server-side testing only.
  2714. *
  2715. * @private
  2716. * @name fauxAsync
  2717. * @memberof mixitup.Config.debug
  2718. * @instance
  2719. * @type {boolean}
  2720. * @default false
  2721. */
  2722. this.fauxAsync = false;
  2723. this.callActions('afterConstruct');
  2724. h.seal(this);
  2725. };
  2726. mixitup.BaseStatic.call(mixitup.ConfigDebug);
  2727. mixitup.ConfigDebug.prototype = Object.create(mixitup.Base.prototype);
  2728. mixitup.ConfigDebug.prototype.constructor = mixitup.ConfigDebug;
  2729. /**
  2730. * A group of properties relating to the layout of the container.
  2731. *
  2732. * @constructor
  2733. * @memberof mixitup.Config
  2734. * @name layout
  2735. * @namespace
  2736. * @public
  2737. * @since 3.0.0
  2738. */
  2739. mixitup.ConfigLayout = function() {
  2740. mixitup.Base.call(this);
  2741. this.callActions('beforeConstruct');
  2742. /**
  2743. * A boolean dictating whether or not mixitup should query all descendants
  2744. * of the container for targets, or only immediate children.
  2745. *
  2746. * By default, mixitup will query all descendants matching the
  2747. * `selectors.target` selector when indexing targets upon instantiation.
  2748. * This allows for targets to be nested inside a sub-container which is
  2749. * useful when ring-fencing targets from locally scoped controls in your
  2750. * markup (see `controls.scope`).
  2751. *
  2752. * However, if you are building a more complex UI requiring the nesting
  2753. * of mixers within mixers, you will most likely want to limit targets to
  2754. * immediate children of the container by setting this property to `false`.
  2755. *
  2756. * @example <caption>Example: Restricting targets to immediate children</caption>
  2757. *
  2758. * var mixer = mixitup(containerEl, {
  2759. * layout: {
  2760. * allowNestedTargets: false
  2761. * }
  2762. * });
  2763. *
  2764. * @name allowNestedTargets
  2765. * @memberof mixitup.Config.layout
  2766. * @instance
  2767. * @type {boolean}
  2768. * @default true
  2769. */
  2770. this.allowNestedTargets = true;
  2771. /**
  2772. * A string specifying an optional class name to apply to the container when in
  2773. * its default state.
  2774. *
  2775. * By changing this class name or adding a class name to the container via the
  2776. * `.changeLayout()` API method, the CSS layout of the container can be changed,
  2777. * and MixItUp will attemp to gracefully animate the container and its targets
  2778. * between states.
  2779. *
  2780. * @example <caption>Example 1: Specifying a container class name</caption>
  2781. *
  2782. * var mixer = mixitup(containerEl, {
  2783. * layout: {
  2784. * containerClassName: 'grid'
  2785. * }
  2786. * });
  2787. *
  2788. * @example <caption>Example 2: Changing the default class name with `.changeLayout()`</caption>
  2789. *
  2790. * var mixer = mixitup(containerEl, {
  2791. * layout: {
  2792. * containerClassName: 'grid'
  2793. * }
  2794. * });
  2795. *
  2796. * mixer.changeLayout('list')
  2797. * .then(function(state) {
  2798. * console.log(state.activeContainerClass); // "list"
  2799. * });
  2800. *
  2801. * @name containerClassName
  2802. * @memberof mixitup.Config.layout
  2803. * @instance
  2804. * @type {string}
  2805. * @default ''
  2806. */
  2807. this.containerClassName = '';
  2808. /**
  2809. * A reference to a non-target sibling element after which to insert targets
  2810. * when there are no targets in the container.
  2811. *
  2812. * @example <caption>Example: Setting a `siblingBefore` reference element</caption>
  2813. *
  2814. * var addButton = containerEl.querySelector('button');
  2815. *
  2816. * var mixer = mixitup(containerEl, {
  2817. * layout: {
  2818. * siblingBefore: addButton
  2819. * }
  2820. * });
  2821. *
  2822. * @name siblingBefore
  2823. * @memberof mixitup.Config.layout
  2824. * @instance
  2825. * @type {HTMLElement}
  2826. * @default null
  2827. */
  2828. this.siblingBefore = null;
  2829. /**
  2830. * A reference to a non-target sibling element before which to insert targets
  2831. * when there are no targets in the container.
  2832. *
  2833. * @example <caption>Example: Setting an `siblingAfter` reference element</caption>
  2834. *
  2835. * var gap = containerEl.querySelector('.gap');
  2836. *
  2837. * var mixer = mixitup(containerEl, {
  2838. * layout: {
  2839. * siblingAfter: gap
  2840. * }
  2841. * });
  2842. *
  2843. * @name siblingAfter
  2844. * @memberof mixitup.Config.layout
  2845. * @instance
  2846. * @type {HTMLElement}
  2847. * @default null
  2848. */
  2849. this.siblingAfter = null;
  2850. this.callActions('afterConstruct');
  2851. h.seal(this);
  2852. };
  2853. mixitup.BaseStatic.call(mixitup.ConfigLayout);
  2854. mixitup.ConfigLayout.prototype = Object.create(mixitup.Base.prototype);
  2855. mixitup.ConfigLayout.prototype.constructor = mixitup.ConfigLayout;
  2856. /**
  2857. * A group of properties defining the initial state of the mixer on load (instantiation).
  2858. *
  2859. * @constructor
  2860. * @memberof mixitup.Config
  2861. * @name load
  2862. * @namespace
  2863. * @public
  2864. * @since 2.0.0
  2865. */
  2866. mixitup.ConfigLoad = function() {
  2867. mixitup.Base.call(this);
  2868. this.callActions('beforeConstruct');
  2869. /**
  2870. * A string defining any filtering to be statically applied to the mixer on load.
  2871. * As per the `.filter()` API, this can be any valid selector string, or the
  2872. * values `'all'` or `'none'`.
  2873. *
  2874. * @example <caption>Example 1: Defining an initial filter selector to be applied on load</caption>
  2875. *
  2876. * // The mixer will show only those targets matching '.category-a' on load.
  2877. *
  2878. * var mixer = mixitup(containerEl, {
  2879. * load: {
  2880. * filter: '.category-a'
  2881. * }
  2882. * });
  2883. *
  2884. * @example <caption>Example 2: Hiding all targets on load</caption>
  2885. *
  2886. * // The mixer will show hide all targets on load.
  2887. *
  2888. * var mixer = mixitup(containerEl, {
  2889. * load: {
  2890. * filter: 'none'
  2891. * }
  2892. * });
  2893. *
  2894. * @name filter
  2895. * @memberof mixitup.Config.load
  2896. * @instance
  2897. * @type {string}
  2898. * @default 'all'
  2899. */
  2900. this.filter = 'all';
  2901. /**
  2902. * A string defining any sorting to be statically applied to the mixer on load.
  2903. * As per the `.sort()` API, this should be a valid "sort string" made up of
  2904. * an attribute to sort by (or `'default'`) followed by an optional sorting
  2905. * order, or the value `'random'`;
  2906. *
  2907. * @example <caption>Example: Defining sorting to be applied on load</caption>
  2908. *
  2909. * // The mixer will sort the container by the value of the `data-published-date`
  2910. * // attribute, in descending order.
  2911. *
  2912. * var mixer = mixitup(containerEl, {
  2913. * load: {
  2914. * sort: 'published-date:desc'
  2915. * }
  2916. * });
  2917. *
  2918. * @name sort
  2919. * @memberof mixitup.Config.load
  2920. * @instance
  2921. * @type {string}
  2922. * @default 'default:asc'
  2923. */
  2924. this.sort = 'default:asc';
  2925. /**
  2926. * An array of objects representing the underlying data of any pre-rendered targets,
  2927. * when using the `.dataset()` API.
  2928. *
  2929. * NB: If targets are pre-rendered when the mixer is instantiated, this must be set.
  2930. *
  2931. * @example <caption>Example: Defining the initial underyling dataset</caption>
  2932. *
  2933. * var myDataset = [
  2934. * {
  2935. * id: 0,
  2936. * title: "Blog Post Title 0",
  2937. * ...
  2938. * },
  2939. * {
  2940. * id: 1,
  2941. * title: "Blog Post Title 1",
  2942. * ...
  2943. * }
  2944. * ];
  2945. *
  2946. * var mixer = mixitup(containerEl, {
  2947. * data: {
  2948. * uidKey: 'id'
  2949. * },
  2950. * load: {
  2951. * dataset: myDataset
  2952. * }
  2953. * });
  2954. *
  2955. * @name dataset
  2956. * @memberof mixitup.Config.load
  2957. * @instance
  2958. * @type {Array.<object>}
  2959. * @default null
  2960. */
  2961. this.dataset = null;
  2962. this.callActions('afterConstruct');
  2963. h.seal(this);
  2964. };
  2965. mixitup.BaseStatic.call(mixitup.ConfigLoad);
  2966. mixitup.ConfigLoad.prototype = Object.create(mixitup.Base.prototype);
  2967. mixitup.ConfigLoad.prototype.constructor = mixitup.ConfigLoad;
  2968. /**
  2969. * A group of properties defining the selectors used to query elements within a mixitup container.
  2970. *
  2971. * @constructor
  2972. * @memberof mixitup.Config
  2973. * @name selectors
  2974. * @namespace
  2975. * @public
  2976. * @since 3.0.0
  2977. */
  2978. mixitup.ConfigSelectors = function() {
  2979. mixitup.Base.call(this);
  2980. this.callActions('beforeConstruct');
  2981. /**
  2982. * A selector string used to query and index target elements within the container.
  2983. *
  2984. * By default, the class selector `'.mix'` is used, but this can be changed to an
  2985. * attribute or element selector to match the style of your project.
  2986. *
  2987. * @example <caption>Example 1: Changing the target selector</caption>
  2988. *
  2989. * var mixer = mixitup(containerEl, {
  2990. * selectors: {
  2991. * target: '.portfolio-item'
  2992. * }
  2993. * });
  2994. *
  2995. * @example <caption>Example 2: Using an attribute selector as a target selector</caption>
  2996. *
  2997. * // The mixer will search for any children with the attribute `data-ref="mix"`
  2998. *
  2999. * var mixer = mixitup(containerEl, {
  3000. * selectors: {
  3001. * target: '[data-ref="mix"]'
  3002. * }
  3003. * });
  3004. *
  3005. * @name target
  3006. * @memberof mixitup.Config.selectors
  3007. * @instance
  3008. * @type {string}
  3009. * @default '.mix'
  3010. */
  3011. this.target = '.mix';
  3012. /**
  3013. * A optional selector string used to add further specificity to the querying of control elements,
  3014. * in addition to their mandatory data attribute (e.g. `data-filter`, `data-toggle`, `data-sort`).
  3015. *
  3016. * This can be used if other elements in your document must contain the above attributes
  3017. * (e.g. for use in third-party scripts), and would otherwise interfere with MixItUp. Adding
  3018. * an additional `control` selector of your choice allows MixItUp to restrict event handling
  3019. * to only those elements matching the defined selector.
  3020. *
  3021. * @name control
  3022. * @memberof mixitup.Config.selectors
  3023. * @instance
  3024. * @type {string}
  3025. * @default ''
  3026. *
  3027. * @example <caption>Example 1: Adding a `selectors.control` selector</caption>
  3028. *
  3029. * var mixer = mixitup(containerEl, {
  3030. * selectors: {
  3031. * control: '.mixitup-control'
  3032. * }
  3033. * });
  3034. *
  3035. * // Will not be handled:
  3036. * // <button data-filter=".category-a"></button>
  3037. *
  3038. * // Will be handled:
  3039. * // <button class="mixitup-control" data-filter=".category-a"></button>
  3040. */
  3041. this.control = '';
  3042. this.callActions('afterConstruct');
  3043. h.seal(this);
  3044. };
  3045. mixitup.BaseStatic.call(mixitup.ConfigSelectors);
  3046. mixitup.ConfigSelectors.prototype = Object.create(mixitup.Base.prototype);
  3047. mixitup.ConfigSelectors.prototype.constructor = mixitup.ConfigSelectors;
  3048. /**
  3049. * A group of optional render functions for creating and updating elements.
  3050. *
  3051. * All render functions receive a data object, and should return a valid HTML string.
  3052. *
  3053. * @constructor
  3054. * @memberof mixitup.Config
  3055. * @name render
  3056. * @namespace
  3057. * @public
  3058. * @since 3.0.0
  3059. */
  3060. mixitup.ConfigRender = function() {
  3061. mixitup.Base.call(this);
  3062. this.callActions('beforeConstruct');
  3063. /**
  3064. * A function returning an HTML string representing a target element, or a reference to a
  3065. * single DOM element.
  3066. *
  3067. * The function is invoked as part of the `.dataset()` API, whenever a new item is added
  3068. * to the dataset, or an item in the dataset changes (if `dataset.dirtyCheck` is enabled).
  3069. *
  3070. * The function receives the relevant dataset item as its first parameter.
  3071. *
  3072. * @example <caption>Example 1: Using string concatenation</caption>
  3073. *
  3074. * var mixer = mixitup(containerEl, {
  3075. * render: {
  3076. * target: function(item) {
  3077. * return (
  3078. * '&lt;div class="mix"&gt;' +
  3079. * '&lt;h2&gt;' + item.title + '&lt;/h2&gt;' +
  3080. * '&lt;/div&gt;'
  3081. * );
  3082. * }
  3083. * }
  3084. * });
  3085. *
  3086. * @example <caption>Example 2: Using an ES2015 template literal</caption>
  3087. *
  3088. * var mixer = mixitup(containerEl, {
  3089. * render: {
  3090. * target: function(item) {
  3091. * return (
  3092. * `&lt;div class="mix"&gt;
  3093. * &lt;h2&gt;${item.title}&lt;/h2&gt;
  3094. * &lt;/div&gt;`
  3095. * );
  3096. * }
  3097. * }
  3098. * });
  3099. *
  3100. * @example <caption>Example 3: Using a Handlebars template</caption>
  3101. *
  3102. * var targetTemplate = Handlebars.compile('&lt;div class="mix"&gt;&lt;h2&gt;{{title}}&lt;/h2&gt;&lt;/div&gt;');
  3103. *
  3104. * var mixer = mixitup(containerEl, {
  3105. * render: {
  3106. * target: targetTemplate
  3107. * }
  3108. * });
  3109. *
  3110. * @example <caption>Example 4: Returning a DOM element</caption>
  3111. *
  3112. * var mixer = mixitup(containerEl, {
  3113. * render: {
  3114. * target: function(item) {
  3115. * // Create a single element using your framework's built-in renderer
  3116. *
  3117. * var el = ...
  3118. *
  3119. * return el;
  3120. * }
  3121. * }
  3122. * });
  3123. *
  3124. * @name target
  3125. * @memberof mixitup.Config.render
  3126. * @instance
  3127. * @type {function}
  3128. * @default 'null'
  3129. */
  3130. this.target = null;
  3131. this.callActions('afterConstruct');
  3132. h.seal(this);
  3133. };
  3134. mixitup.BaseStatic.call(mixitup.ConfigRender);
  3135. mixitup.ConfigRender.prototype = Object.create(mixitup.Base.prototype);
  3136. mixitup.ConfigRender.prototype.constructor = mixitup.ConfigRender;
  3137. /**
  3138. * @constructor
  3139. * @memberof mixitup
  3140. * @private
  3141. * @since 3.0.0
  3142. */
  3143. mixitup.ConfigTemplates = function() {
  3144. mixitup.Base.call(this);
  3145. this.callActions('beforeConstruct');
  3146. this.callActions('afterConstruct');
  3147. h.seal(this);
  3148. };
  3149. mixitup.BaseStatic.call(mixitup.ConfigTemplates);
  3150. mixitup.ConfigTemplates.prototype = Object.create(mixitup.Base.prototype);
  3151. mixitup.ConfigTemplates.prototype.constructor = mixitup.ConfigTemplates;
  3152. /**
  3153. * `mixitup.Config` is an interface used for customising the functionality of a
  3154. * mixer instance. It is organised into several semantically distinct sub-objects,
  3155. * each one pertaining to a particular aspect of MixItUp functionality.
  3156. *
  3157. * An object literal containing any or all of the available properies,
  3158. * known as the "configuration object", can be passed as the second parameter to
  3159. * the `mixitup` factory function when creating a mixer instance to customise its
  3160. * functionality as needed.
  3161. *
  3162. * If no configuration object is passed, the mixer instance will take on the default
  3163. * configuration values detailed below.
  3164. *
  3165. * @example <caption>Example 1: Creating and passing the configuration object</caption>
  3166. * // Create a configuration object with desired values
  3167. *
  3168. * var config = {
  3169. * animation: {
  3170. * enable: false
  3171. * },
  3172. * selectors: {
  3173. * target: '.item'
  3174. * }
  3175. * };
  3176. *
  3177. * // Pass the configuration object to the mixitup factory function
  3178. *
  3179. * var mixer = mixitup(containerEl, config);
  3180. *
  3181. * @example <caption>Example 2: Passing the configuration object inline</caption>
  3182. * // Typically, the configuration object is passed inline for brevity.
  3183. *
  3184. * var mixer = mixitup(containerEl, {
  3185. * controls: {
  3186. * live: true,
  3187. * toggleLogic: 'and'
  3188. * }
  3189. * });
  3190. *
  3191. *
  3192. * @constructor
  3193. * @memberof mixitup
  3194. * @namespace
  3195. * @public
  3196. * @since 2.0.0
  3197. */
  3198. mixitup.Config = function() {
  3199. mixitup.Base.call(this);
  3200. this.callActions('beforeConstruct');
  3201. this.animation = new mixitup.ConfigAnimation();
  3202. this.behavior = new mixitup.ConfigBehavior();
  3203. this.callbacks = new mixitup.ConfigCallbacks();
  3204. this.controls = new mixitup.ConfigControls();
  3205. this.classNames = new mixitup.ConfigClassNames();
  3206. this.data = new mixitup.ConfigData();
  3207. this.debug = new mixitup.ConfigDebug();
  3208. this.layout = new mixitup.ConfigLayout();
  3209. this.load = new mixitup.ConfigLoad();
  3210. this.selectors = new mixitup.ConfigSelectors();
  3211. this.render = new mixitup.ConfigRender();
  3212. this.templates = new mixitup.ConfigTemplates();
  3213. this.callActions('afterConstruct');
  3214. h.seal(this);
  3215. };
  3216. mixitup.BaseStatic.call(mixitup.Config);
  3217. mixitup.Config.prototype = Object.create(mixitup.Base.prototype);
  3218. mixitup.Config.prototype.constructor = mixitup.Config;
  3219. /**
  3220. * @constructor
  3221. * @memberof mixitup
  3222. * @private
  3223. * @since 3.0.0
  3224. */
  3225. mixitup.MixerDom = function() {
  3226. mixitup.Base.call(this);
  3227. this.callActions('beforeConstruct');
  3228. this.document = null;
  3229. this.body = null;
  3230. this.container = null;
  3231. this.parent = null;
  3232. this.targets = [];
  3233. this.callActions('afterConstruct');
  3234. h.seal(this);
  3235. };
  3236. mixitup.BaseStatic.call(mixitup.MixerDom);
  3237. mixitup.MixerDom.prototype = Object.create(mixitup.Base.prototype);
  3238. mixitup.MixerDom.prototype.constructor = mixitup.MixerDom;
  3239. /**
  3240. * @constructor
  3241. * @memberof mixitup
  3242. * @private
  3243. * @since 3.0.0
  3244. */
  3245. mixitup.UiClassNames = function() {
  3246. mixitup.Base.call(this);
  3247. this.callActions('beforeConstruct');
  3248. this.base = '';
  3249. this.active = '';
  3250. this.disabled = '';
  3251. this.callActions('afterConstruct');
  3252. h.seal(this);
  3253. };
  3254. mixitup.BaseStatic.call(mixitup.UiClassNames);
  3255. mixitup.UiClassNames.prototype = Object.create(mixitup.Base.prototype);
  3256. mixitup.UiClassNames.prototype.constructor = mixitup.UiClassNames;
  3257. /**
  3258. * An object into which all arbitrary arguments sent to '.dataset()' are mapped.
  3259. *
  3260. * @constructor
  3261. * @memberof mixitup
  3262. * @private
  3263. * @since 3.0.0
  3264. */
  3265. mixitup.CommandDataset = function() {
  3266. mixitup.Base.call(this);
  3267. this.callActions('beforeConstruct');
  3268. this.dataset = null;
  3269. this.callActions('afterConstruct');
  3270. h.seal(this);
  3271. };
  3272. mixitup.BaseStatic.call(mixitup.CommandDataset);
  3273. mixitup.CommandDataset.prototype = Object.create(mixitup.Base.prototype);
  3274. mixitup.CommandDataset.prototype.constructor = mixitup.CommandDataset;
  3275. /**
  3276. * An object into which all arbitrary arguments sent to '.multimix()' are mapped.
  3277. *
  3278. * @constructor
  3279. * @memberof mixitup
  3280. * @private
  3281. * @since 3.0.0
  3282. */
  3283. mixitup.CommandMultimix = function() {
  3284. mixitup.Base.call(this);
  3285. this.callActions('beforeConstruct');
  3286. this.filter = null;
  3287. this.sort = null;
  3288. this.insert = null;
  3289. this.remove = null;
  3290. this.changeLayout = null;
  3291. this.callActions('afterConstruct');
  3292. h.seal(this);
  3293. };
  3294. mixitup.BaseStatic.call(mixitup.CommandMultimix);
  3295. mixitup.CommandMultimix.prototype = Object.create(mixitup.Base.prototype);
  3296. mixitup.CommandMultimix.prototype.constructor = mixitup.CommandMultimix;
  3297. /**
  3298. * An object into which all arbitrary arguments sent to '.filter()' are mapped.
  3299. *
  3300. * @constructor
  3301. * @memberof mixitup
  3302. * @private
  3303. * @since 3.0.0
  3304. */
  3305. mixitup.CommandFilter = function() {
  3306. mixitup.Base.call(this);
  3307. this.callActions('beforeConstruct');
  3308. this.selector = '';
  3309. this.collection = null;
  3310. this.action = 'show'; // enum: ['show', 'hide']
  3311. this.callActions('afterConstruct');
  3312. h.seal(this);
  3313. };
  3314. mixitup.BaseStatic.call(mixitup.CommandFilter);
  3315. mixitup.CommandFilter.prototype = Object.create(mixitup.Base.prototype);
  3316. mixitup.CommandFilter.prototype.constructor = mixitup.CommandFilter;
  3317. /**
  3318. * An object into which all arbitrary arguments sent to '.sort()' are mapped.
  3319. *
  3320. * @constructor
  3321. * @memberof mixitup
  3322. * @private
  3323. * @since 3.0.0
  3324. */
  3325. mixitup.CommandSort = function() {
  3326. mixitup.Base.call(this);
  3327. this.callActions('beforeConstruct');
  3328. this.sortString = '';
  3329. this.attribute = '';
  3330. this.order = 'asc';
  3331. this.collection = null;
  3332. this.next = null;
  3333. this.callActions('afterConstruct');
  3334. h.seal(this);
  3335. };
  3336. mixitup.BaseStatic.call(mixitup.CommandSort);
  3337. mixitup.CommandSort.prototype = Object.create(mixitup.Base.prototype);
  3338. mixitup.CommandSort.prototype.constructor = mixitup.CommandSort;
  3339. /**
  3340. * An object into which all arbitrary arguments sent to '.insert()' are mapped.
  3341. *
  3342. * @constructor
  3343. * @memberof mixitup
  3344. * @private
  3345. * @since 3.0.0
  3346. */
  3347. mixitup.CommandInsert = function() {
  3348. mixitup.Base.call(this);
  3349. this.callActions('beforeConstruct');
  3350. this.index = 0;
  3351. this.collection = [];
  3352. this.position = 'before'; // enum: ['before', 'after']
  3353. this.sibling = null;
  3354. this.callActions('afterConstruct');
  3355. h.seal(this);
  3356. };
  3357. mixitup.BaseStatic.call(mixitup.CommandInsert);
  3358. mixitup.CommandInsert.prototype = Object.create(mixitup.Base.prototype);
  3359. mixitup.CommandInsert.prototype.constructor = mixitup.CommandInsert;
  3360. /**
  3361. * An object into which all arbitrary arguments sent to '.remove()' are mapped.
  3362. *
  3363. * @constructor
  3364. * @memberof mixitup
  3365. * @private
  3366. * @since 3.0.0
  3367. */
  3368. mixitup.CommandRemove = function() {
  3369. mixitup.Base.call(this);
  3370. this.callActions('beforeConstruct');
  3371. this.targets = [];
  3372. this.collection = [];
  3373. this.callActions('afterConstruct');
  3374. h.seal(this);
  3375. };
  3376. mixitup.BaseStatic.call(mixitup.CommandRemove);
  3377. mixitup.CommandRemove.prototype = Object.create(mixitup.Base.prototype);
  3378. mixitup.CommandRemove.prototype.constructor = mixitup.CommandRemove;
  3379. /**
  3380. * An object into which all arbitrary arguments sent to '.changeLayout()' are mapped.
  3381. *
  3382. * @constructor
  3383. * @memberof mixitup
  3384. * @private
  3385. * @since 3.0.0
  3386. */
  3387. mixitup.CommandChangeLayout = function() {
  3388. mixitup.Base.call(this);
  3389. this.callActions('beforeConstruct');
  3390. this.containerClassName = '';
  3391. this.callActions('afterConstruct');
  3392. h.seal(this);
  3393. };
  3394. mixitup.BaseStatic.call(mixitup.CommandChangeLayout);
  3395. mixitup.CommandChangeLayout.prototype = Object.create(mixitup.Base.prototype);
  3396. mixitup.CommandChangeLayout.prototype.constructor = mixitup.CommandChangeLayout;
  3397. /**
  3398. * @constructor
  3399. * @memberof mixitup
  3400. * @private
  3401. * @since 3.0.0
  3402. * @param {string} type
  3403. * @param {string} selector
  3404. * @param {boolean} [live]
  3405. * @param {string} [parent]
  3406. * An optional string representing the name of the mixer.dom property containing a reference to a parent element.
  3407. */
  3408. mixitup.ControlDefinition = function(type, selector, live, parent) {
  3409. mixitup.Base.call(this);
  3410. this.callActions('beforeConstruct');
  3411. this.type = type;
  3412. this.selector = selector;
  3413. this.live = live || false;
  3414. this.parent = parent || '';
  3415. this.callActions('afterConstruct');
  3416. h.freeze(this);
  3417. h.seal(this);
  3418. };
  3419. mixitup.BaseStatic.call(mixitup.ControlDefinition);
  3420. mixitup.ControlDefinition.prototype = Object.create(mixitup.Base.prototype);
  3421. mixitup.ControlDefinition.prototype.constructor = mixitup.ControlDefinition;
  3422. mixitup.controlDefinitions = [];
  3423. mixitup.controlDefinitions.push(new mixitup.ControlDefinition('multimix', '[data-filter][data-sort]'));
  3424. mixitup.controlDefinitions.push(new mixitup.ControlDefinition('filter', '[data-filter]'));
  3425. mixitup.controlDefinitions.push(new mixitup.ControlDefinition('sort', '[data-sort]'));
  3426. mixitup.controlDefinitions.push(new mixitup.ControlDefinition('toggle', '[data-toggle]'));
  3427. /**
  3428. * @constructor
  3429. * @memberof mixitup
  3430. * @private
  3431. * @since 3.0.0
  3432. */
  3433. mixitup.Control = function() {
  3434. mixitup.Base.call(this);
  3435. this.callActions('beforeConstruct');
  3436. this.el = null;
  3437. this.selector = '';
  3438. this.bound = [];
  3439. this.pending = -1;
  3440. this.type = '';
  3441. this.status = 'inactive'; // enum: ['inactive', 'active', 'disabled', 'live']
  3442. this.filter = '';
  3443. this.sort = '';
  3444. this.canDisable = false;
  3445. this.handler = null;
  3446. this.classNames = new mixitup.UiClassNames();
  3447. this.callActions('afterConstruct');
  3448. h.seal(this);
  3449. };
  3450. mixitup.BaseStatic.call(mixitup.Control);
  3451. mixitup.Control.prototype = Object.create(mixitup.Base.prototype);
  3452. h.extend(mixitup.Control.prototype,
  3453. /** @lends mixitup.Control */
  3454. {
  3455. constructor: mixitup.Control,
  3456. /**
  3457. * @private
  3458. * @param {HTMLElement} el
  3459. * @param {string} type
  3460. * @param {string} selector
  3461. */
  3462. init: function(el, type, selector) {
  3463. var self = this;
  3464. this.callActions('beforeInit', arguments);
  3465. self.el = el;
  3466. self.type = type;
  3467. self.selector = selector;
  3468. if (self.selector) {
  3469. self.status = 'live';
  3470. } else {
  3471. self.canDisable = typeof self.el.disable === 'boolean';
  3472. switch (self.type) {
  3473. case 'filter':
  3474. self.filter = self.el.getAttribute('data-filter');
  3475. break;
  3476. case 'toggle':
  3477. self.filter = self.el.getAttribute('data-toggle');
  3478. break;
  3479. case 'sort':
  3480. self.sort = self.el.getAttribute('data-sort');
  3481. break;
  3482. case 'multimix':
  3483. self.filter = self.el.getAttribute('data-filter');
  3484. self.sort = self.el.getAttribute('data-sort');
  3485. break;
  3486. }
  3487. }
  3488. self.bindClick();
  3489. mixitup.controls.push(self);
  3490. this.callActions('afterInit', arguments);
  3491. },
  3492. /**
  3493. * @private
  3494. * @param {mixitup.Mixer} mixer
  3495. * @return {boolean}
  3496. */
  3497. isBound: function(mixer) {
  3498. var self = this,
  3499. isBound = false;
  3500. this.callActions('beforeIsBound', arguments);
  3501. isBound = self.bound.indexOf(mixer) > -1;
  3502. return self.callFilters('afterIsBound', isBound, arguments);
  3503. },
  3504. /**
  3505. * @private
  3506. * @param {mixitup.Mixer} mixer
  3507. * @return {void}
  3508. */
  3509. addBinding: function(mixer) {
  3510. var self = this;
  3511. this.callActions('beforeAddBinding', arguments);
  3512. if (!self.isBound()) {
  3513. self.bound.push(mixer);
  3514. }
  3515. this.callActions('afterAddBinding', arguments);
  3516. },
  3517. /**
  3518. * @private
  3519. * @param {mixitup.Mixer} mixer
  3520. * @return {void}
  3521. */
  3522. removeBinding: function(mixer) {
  3523. var self = this,
  3524. removeIndex = -1;
  3525. this.callActions('beforeRemoveBinding', arguments);
  3526. if ((removeIndex = self.bound.indexOf(mixer)) > -1) {
  3527. self.bound.splice(removeIndex, 1);
  3528. }
  3529. if (self.bound.length < 1) {
  3530. // No bindings exist, unbind event click handlers
  3531. self.unbindClick();
  3532. // Remove from `mixitup.controls` list
  3533. removeIndex = mixitup.controls.indexOf(self);
  3534. mixitup.controls.splice(removeIndex, 1);
  3535. if (self.status === 'active') {
  3536. self.renderStatus(self.el, 'inactive');
  3537. }
  3538. }
  3539. this.callActions('afterRemoveBinding', arguments);
  3540. },
  3541. /**
  3542. * @private
  3543. * @return {void}
  3544. */
  3545. bindClick: function() {
  3546. var self = this;
  3547. this.callActions('beforeBindClick', arguments);
  3548. self.handler = function(e) {
  3549. self.handleClick(e);
  3550. };
  3551. h.on(self.el, 'click', self.handler);
  3552. this.callActions('afterBindClick', arguments);
  3553. },
  3554. /**
  3555. * @private
  3556. * @return {void}
  3557. */
  3558. unbindClick: function() {
  3559. var self = this;
  3560. this.callActions('beforeUnbindClick', arguments);
  3561. h.off(self.el, 'click', self.handler);
  3562. self.handler = null;
  3563. this.callActions('afterUnbindClick', arguments);
  3564. },
  3565. /**
  3566. * @private
  3567. * @param {MouseEvent} e
  3568. * @return {void}
  3569. */
  3570. handleClick: function(e) {
  3571. var self = this,
  3572. button = null,
  3573. mixer = null,
  3574. isActive = false,
  3575. returnValue = void(0),
  3576. command = {},
  3577. clone = null,
  3578. commands = [],
  3579. i = -1;
  3580. this.callActions('beforeHandleClick', arguments);
  3581. this.pending = 0;
  3582. mixer = self.bound[0];
  3583. if (!self.selector) {
  3584. button = self.el;
  3585. } else {
  3586. button = h.closestParent(e.target, mixer.config.selectors.control + self.selector, true, mixer.dom.document);
  3587. }
  3588. if (!button) {
  3589. self.callActions('afterHandleClick', arguments);
  3590. return;
  3591. }
  3592. switch (self.type) {
  3593. case 'filter':
  3594. command.filter = self.filter || button.getAttribute('data-filter');
  3595. break;
  3596. case 'sort':
  3597. command.sort = self.sort || button.getAttribute('data-sort');
  3598. break;
  3599. case 'multimix':
  3600. command.filter = self.filter || button.getAttribute('data-filter');
  3601. command.sort = self.sort || button.getAttribute('data-sort');
  3602. break;
  3603. case 'toggle':
  3604. command.filter = self.filter || button.getAttribute('data-toggle');
  3605. if (self.status === 'live') {
  3606. isActive = h.hasClass(button, self.classNames.active);
  3607. } else {
  3608. isActive = self.status === 'active';
  3609. }
  3610. break;
  3611. }
  3612. for (i = 0; i < self.bound.length; i++) {
  3613. // Create a clone of the command for each bound mixer instance
  3614. clone = new mixitup.CommandMultimix();
  3615. h.extend(clone, command);
  3616. commands.push(clone);
  3617. }
  3618. commands = self.callFilters('commandsHandleClick', commands, arguments);
  3619. self.pending = self.bound.length;
  3620. for (i = 0; mixer = self.bound[i]; i++) {
  3621. command = commands[i];
  3622. if (!command) {
  3623. // An extension may set a command null to indicate that the click should not be handled
  3624. continue;
  3625. }
  3626. if (!mixer.lastClicked) {
  3627. mixer.lastClicked = button;
  3628. }
  3629. mixitup.events.fire('mixClick', mixer.dom.container, {
  3630. state: mixer.state,
  3631. instance: mixer,
  3632. originalEvent: e,
  3633. control: mixer.lastClicked
  3634. }, mixer.dom.document);
  3635. if (typeof mixer.config.callbacks.onMixClick === 'function') {
  3636. returnValue = mixer.config.callbacks.onMixClick.call(mixer.lastClicked, mixer.state, e, mixer);
  3637. if (returnValue === false) {
  3638. // User has returned `false` from the callback, so do not handle click
  3639. continue;
  3640. }
  3641. }
  3642. if (self.type === 'toggle') {
  3643. isActive ? mixer.toggleOff(command.filter) : mixer.toggleOn(command.filter);
  3644. } else {
  3645. mixer.multimix(command);
  3646. }
  3647. }
  3648. this.callActions('afterHandleClick', arguments);
  3649. },
  3650. /**
  3651. * @param {object} command
  3652. * @param {Array<string>} toggleArray
  3653. * @return {void}
  3654. */
  3655. update: function(command, toggleArray) {
  3656. var self = this,
  3657. actions = new mixitup.CommandMultimix();
  3658. self.callActions('beforeUpdate', arguments);
  3659. self.pending--;
  3660. self.pending = Math.max(0, self.pending);
  3661. if (self.pending > 0) return;
  3662. if (self.status === 'live') {
  3663. // Live control (status unknown)
  3664. self.updateLive(command, toggleArray);
  3665. } else {
  3666. // Static control
  3667. actions.sort = self.sort;
  3668. actions.filter = self.filter;
  3669. self.callFilters('actionsUpdate', actions, arguments);
  3670. self.parseStatusChange(self.el, command, actions, toggleArray);
  3671. }
  3672. self.callActions('afterUpdate', arguments);
  3673. },
  3674. /**
  3675. * @param {mixitup.CommandMultimix} command
  3676. * @param {Array<string>} toggleArray
  3677. * @return {void}
  3678. */
  3679. updateLive: function(command, toggleArray) {
  3680. var self = this,
  3681. controlButtons = null,
  3682. actions = null,
  3683. button = null,
  3684. i = -1;
  3685. self.callActions('beforeUpdateLive', arguments);
  3686. if (!self.el) return;
  3687. controlButtons = self.el.querySelectorAll(self.selector);
  3688. for (i = 0; button = controlButtons[i]; i++) {
  3689. actions = new mixitup.CommandMultimix();
  3690. switch (self.type) {
  3691. case 'filter':
  3692. actions.filter = button.getAttribute('data-filter');
  3693. break;
  3694. case 'sort':
  3695. actions.sort = button.getAttribute('data-sort');
  3696. break;
  3697. case 'multimix':
  3698. actions.filter = button.getAttribute('data-filter');
  3699. actions.sort = button.getAttribute('data-sort');
  3700. break;
  3701. case 'toggle':
  3702. actions.filter = button.getAttribute('data-toggle');
  3703. break;
  3704. }
  3705. actions = self.callFilters('actionsUpdateLive', actions, arguments);
  3706. self.parseStatusChange(button, command, actions, toggleArray);
  3707. }
  3708. self.callActions('afterUpdateLive', arguments);
  3709. },
  3710. /**
  3711. * @param {HTMLElement} button
  3712. * @param {mixitup.CommandMultimix} command
  3713. * @param {mixitup.CommandMultimix} actions
  3714. * @param {Array<string>} toggleArray
  3715. * @return {void}
  3716. */
  3717. parseStatusChange: function(button, command, actions, toggleArray) {
  3718. var self = this,
  3719. alias = '',
  3720. toggle = '',
  3721. i = -1;
  3722. self.callActions('beforeParseStatusChange', arguments);
  3723. switch (self.type) {
  3724. case 'filter':
  3725. if (command.filter === actions.filter) {
  3726. self.renderStatus(button, 'active');
  3727. } else {
  3728. self.renderStatus(button, 'inactive');
  3729. }
  3730. break;
  3731. case 'multimix':
  3732. if (command.sort === actions.sort && command.filter === actions.filter) {
  3733. self.renderStatus(button, 'active');
  3734. } else {
  3735. self.renderStatus(button, 'inactive');
  3736. }
  3737. break;
  3738. case 'sort':
  3739. if (command.sort.match(/:asc/g)) {
  3740. alias = command.sort.replace(/:asc/g, '');
  3741. }
  3742. if (command.sort === actions.sort || alias === actions.sort) {
  3743. self.renderStatus(button, 'active');
  3744. } else {
  3745. self.renderStatus(button, 'inactive');
  3746. }
  3747. break;
  3748. case 'toggle':
  3749. if (toggleArray.length < 1) self.renderStatus(button, 'inactive');
  3750. if (command.filter === actions.filter) {
  3751. self.renderStatus(button, 'active');
  3752. }
  3753. for (i = 0; i < toggleArray.length; i++) {
  3754. toggle = toggleArray[i];
  3755. if (toggle === actions.filter) {
  3756. // Button matches one active toggle
  3757. self.renderStatus(button, 'active');
  3758. break;
  3759. }
  3760. self.renderStatus(button, 'inactive');
  3761. }
  3762. break;
  3763. }
  3764. self.callActions('afterParseStatusChange', arguments);
  3765. },
  3766. /**
  3767. * @param {HTMLElement} button
  3768. * @param {string} status
  3769. * @return {void}
  3770. */
  3771. renderStatus: function(button, status) {
  3772. var self = this;
  3773. self.callActions('beforeRenderStatus', arguments);
  3774. switch (status) {
  3775. case 'active':
  3776. h.addClass(button, self.classNames.active);
  3777. h.removeClass(button, self.classNames.disabled);
  3778. if (self.canDisable) self.el.disabled = false;
  3779. break;
  3780. case 'inactive':
  3781. h.removeClass(button, self.classNames.active);
  3782. h.removeClass(button, self.classNames.disabled);
  3783. if (self.canDisable) self.el.disabled = false;
  3784. break;
  3785. case 'disabled':
  3786. if (self.canDisable) self.el.disabled = true;
  3787. h.addClass(button, self.classNames.disabled);
  3788. h.removeClass(button, self.classNames.active);
  3789. break;
  3790. }
  3791. if (self.status !== 'live') {
  3792. // Update the control's status propery if not live
  3793. self.status = status;
  3794. }
  3795. self.callActions('afterRenderStatus', arguments);
  3796. }
  3797. });
  3798. mixitup.controls = [];
  3799. /**
  3800. * @constructor
  3801. * @memberof mixitup
  3802. * @private
  3803. * @since 3.0.0
  3804. */
  3805. mixitup.StyleData = function() {
  3806. mixitup.Base.call(this);
  3807. this.callActions('beforeConstruct');
  3808. this.x = 0;
  3809. this.y = 0;
  3810. this.top = 0;
  3811. this.right = 0;
  3812. this.bottom = 0;
  3813. this.left = 0;
  3814. this.width = 0;
  3815. this.height = 0;
  3816. this.marginRight = 0;
  3817. this.marginBottom = 0;
  3818. this.opacity = 0;
  3819. this.scale = new mixitup.TransformData();
  3820. this.translateX = new mixitup.TransformData();
  3821. this.translateY = new mixitup.TransformData();
  3822. this.translateZ = new mixitup.TransformData();
  3823. this.rotateX = new mixitup.TransformData();
  3824. this.rotateY = new mixitup.TransformData();
  3825. this.rotateZ = new mixitup.TransformData();
  3826. this.callActions('afterConstruct');
  3827. h.seal(this);
  3828. };
  3829. mixitup.BaseStatic.call(mixitup.StyleData);
  3830. mixitup.StyleData.prototype = Object.create(mixitup.Base.prototype);
  3831. mixitup.StyleData.prototype.constructor = mixitup.StyleData;
  3832. /**
  3833. * @constructor
  3834. * @memberof mixitup
  3835. * @private
  3836. * @since 3.0.0
  3837. */
  3838. mixitup.TransformData = function() {
  3839. mixitup.Base.call(this);
  3840. this.callActions('beforeConstruct');
  3841. this.value = 0;
  3842. this.unit = '';
  3843. this.callActions('afterConstruct');
  3844. h.seal(this);
  3845. };
  3846. mixitup.BaseStatic.call(mixitup.TransformData);
  3847. mixitup.TransformData.prototype = Object.create(mixitup.Base.prototype);
  3848. mixitup.TransformData.prototype.constructor = mixitup.TransformData;
  3849. /**
  3850. * @constructor
  3851. * @memberof mixitup
  3852. * @private
  3853. * @since 3.0.0
  3854. */
  3855. mixitup.TransformDefaults = function() {
  3856. mixitup.StyleData.apply(this);
  3857. this.callActions('beforeConstruct');
  3858. this.scale.value = 0.01;
  3859. this.scale.unit = '';
  3860. this.translateX.value = 20;
  3861. this.translateX.unit = 'px';
  3862. this.translateY.value = 20;
  3863. this.translateY.unit = 'px';
  3864. this.translateZ.value = 20;
  3865. this.translateZ.unit = 'px';
  3866. this.rotateX.value = 90;
  3867. this.rotateX.unit = 'deg';
  3868. this.rotateY.value = 90;
  3869. this.rotateY.unit = 'deg';
  3870. this.rotateX.value = 90;
  3871. this.rotateX.unit = 'deg';
  3872. this.rotateZ.value = 180;
  3873. this.rotateZ.unit = 'deg';
  3874. this.callActions('afterConstruct');
  3875. h.seal(this);
  3876. };
  3877. mixitup.BaseStatic.call(mixitup.TransformDefaults);
  3878. mixitup.TransformDefaults.prototype = Object.create(mixitup.StyleData.prototype);
  3879. mixitup.TransformDefaults.prototype.constructor = mixitup.TransformDefaults;
  3880. /**
  3881. * @private
  3882. * @static
  3883. * @since 3.0.0
  3884. * @type {mixitup.TransformDefaults}
  3885. */
  3886. mixitup.transformDefaults = new mixitup.TransformDefaults();
  3887. /**
  3888. * @constructor
  3889. * @memberof mixitup
  3890. * @private
  3891. * @since 3.0.0
  3892. */
  3893. mixitup.EventDetail = function() {
  3894. this.state = null;
  3895. this.futureState = null;
  3896. this.instance = null;
  3897. this.originalEvent = null;
  3898. };
  3899. /**
  3900. * The `mixitup.Events` class contains all custom events dispatched by MixItUp at various
  3901. * points within the lifecycle of a mixer operation.
  3902. *
  3903. * Each event is analogous to the callback function of the same name defined in
  3904. * the `callbacks` configuration object, and is triggered immediately before it.
  3905. *
  3906. * Events are always triggered from the container element on which MixItUp is instantiated
  3907. * upon.
  3908. *
  3909. * As with any event, registered event handlers receive the event object as a parameter
  3910. * which includes a `detail` property containting references to the current `state`,
  3911. * the `mixer` instance, and other event-specific properties described below.
  3912. *
  3913. * @constructor
  3914. * @namespace
  3915. * @memberof mixitup
  3916. * @public
  3917. * @since 3.0.0
  3918. */
  3919. mixitup.Events = function() {
  3920. mixitup.Base.call(this);
  3921. this.callActions('beforeConstruct');
  3922. /**
  3923. * A custom event triggered immediately after any MixItUp operation is requested
  3924. * and before animations have begun.
  3925. *
  3926. * The `mixStart` event also exposes a `futureState` property via the
  3927. * `event.detail` object, which represents the final state of the mixer once
  3928. * the requested operation has completed.
  3929. *
  3930. * @name mixStart
  3931. * @memberof mixitup.Events
  3932. * @static
  3933. * @type {CustomEvent}
  3934. */
  3935. this.mixStart = null;
  3936. /**
  3937. * A custom event triggered when a MixItUp operation is requested while another
  3938. * operation is in progress, and the animation queue is full, or queueing
  3939. * is disabled.
  3940. *
  3941. * @name mixBusy
  3942. * @memberof mixitup.Events
  3943. * @static
  3944. * @type {CustomEvent}
  3945. */
  3946. this.mixBusy = null;
  3947. /**
  3948. * A custom event triggered after any MixItUp operation has completed, and the
  3949. * state has been updated.
  3950. *
  3951. * @name mixEnd
  3952. * @memberof mixitup.Events
  3953. * @static
  3954. * @type {CustomEvent}
  3955. */
  3956. this.mixEnd = null;
  3957. /**
  3958. * A custom event triggered whenever a filter operation "fails", i.e. no targets
  3959. * could be found matching the requested filter.
  3960. *
  3961. * @name mixFail
  3962. * @memberof mixitup.Events
  3963. * @static
  3964. * @type {CustomEvent}
  3965. */
  3966. this.mixFail = null;
  3967. /**
  3968. * A custom event triggered whenever a MixItUp control is clicked, and before its
  3969. * respective operation is requested.
  3970. *
  3971. * This event also exposes an `originalEvent` property via the `event.detail`
  3972. * object, which holds a reference to the original click event.
  3973. *
  3974. * @name mixClick
  3975. * @memberof mixitup.Events
  3976. * @static
  3977. * @type {CustomEvent}
  3978. */
  3979. this.mixClick = null;
  3980. this.callActions('afterConstruct');
  3981. h.seal(this);
  3982. };
  3983. mixitup.BaseStatic.call(mixitup.Events);
  3984. mixitup.Events.prototype = Object.create(mixitup.Base.prototype);
  3985. mixitup.Events.prototype.constructor = mixitup.Events;
  3986. /**
  3987. * @private
  3988. * @param {string} eventType
  3989. * @param {Element} el
  3990. * @param {object} detail
  3991. * @param {Document} [doc]
  3992. */
  3993. mixitup.Events.prototype.fire = function(eventType, el, detail, doc) {
  3994. var self = this,
  3995. event = null,
  3996. eventDetail = new mixitup.EventDetail();
  3997. self.callActions('beforeFire', arguments);
  3998. if (typeof self[eventType] === 'undefined') {
  3999. throw new Error('Event type "' + eventType + '" not found.');
  4000. }
  4001. eventDetail.state = new mixitup.State();
  4002. h.extend(eventDetail.state, detail.state);
  4003. if (detail.futureState) {
  4004. eventDetail.futureState = new mixitup.State();
  4005. h.extend(eventDetail.futureState, detail.futureState);
  4006. }
  4007. eventDetail.instance = detail.instance;
  4008. if (detail.originalEvent) {
  4009. eventDetail.originalEvent = detail.originalEvent;
  4010. }
  4011. event = h.getCustomEvent(eventType, eventDetail, doc);
  4012. self.callFilters('eventFire', event, arguments);
  4013. el.dispatchEvent(event);
  4014. };
  4015. // Asign a singleton instance to `mixitup.events`:
  4016. mixitup.events = new mixitup.Events();
  4017. /**
  4018. * @constructor
  4019. * @memberof mixitup
  4020. * @private
  4021. * @since 3.0.0
  4022. */
  4023. mixitup.QueueItem = function() {
  4024. mixitup.Base.call(this);
  4025. this.callActions('beforeConstruct');
  4026. this.args = [];
  4027. this.instruction = null;
  4028. this.triggerElement = null;
  4029. this.deferred = null;
  4030. this.isToggling = false;
  4031. this.callActions('afterConstruct');
  4032. h.seal(this);
  4033. };
  4034. mixitup.BaseStatic.call(mixitup.QueueItem);
  4035. mixitup.QueueItem.prototype = Object.create(mixitup.Base.prototype);
  4036. mixitup.QueueItem.prototype.constructor = mixitup.QueueItem;
  4037. /**
  4038. * The `mixitup.Mixer` class is used to hold discreet, user-configured
  4039. * instances of MixItUp on a provided container element.
  4040. *
  4041. * Mixer instances are returned whenever the `mixitup()` factory function is called,
  4042. * which expose a range of methods enabling API-based filtering, sorting,
  4043. * insertion, removal and more.
  4044. *
  4045. * @constructor
  4046. * @namespace
  4047. * @memberof mixitup
  4048. * @public
  4049. * @since 3.0.0
  4050. */
  4051. mixitup.Mixer = function() {
  4052. mixitup.Base.call(this);
  4053. this.callActions('beforeConstruct');
  4054. this.config = new mixitup.Config();
  4055. this.id = '';
  4056. this.isBusy = false;
  4057. this.isToggling = false;
  4058. this.incPadding = true;
  4059. this.controls = [];
  4060. this.targets = [];
  4061. this.origOrder = [];
  4062. this.cache = {};
  4063. this.toggleArray = [];
  4064. this.targetsMoved = 0;
  4065. this.targetsImmovable = 0;
  4066. this.targetsBound = 0;
  4067. this.targetsDone = 0;
  4068. this.staggerDuration = 0;
  4069. this.effectsIn = null;
  4070. this.effectsOut = null;
  4071. this.transformIn = [];
  4072. this.transformOut = [];
  4073. this.queue = [];
  4074. this.state = null;
  4075. this.lastOperation = null;
  4076. this.lastClicked = null;
  4077. this.userCallback = null;
  4078. this.userDeferred = null;
  4079. this.dom = new mixitup.MixerDom();
  4080. this.callActions('afterConstruct');
  4081. h.seal(this);
  4082. };
  4083. mixitup.BaseStatic.call(mixitup.Mixer);
  4084. mixitup.Mixer.prototype = Object.create(mixitup.Base.prototype);
  4085. h.extend(mixitup.Mixer.prototype,
  4086. /** @lends mixitup.Mixer */
  4087. {
  4088. constructor: mixitup.Mixer,
  4089. /**
  4090. * @private
  4091. * @instance
  4092. * @since 3.0.0
  4093. * @param {HTMLElement} container
  4094. * @param {HTMLElement} document
  4095. * @param {string} id
  4096. * @param {object} [config]
  4097. */
  4098. attach: function(container, document, id, config) {
  4099. var self = this,
  4100. target = null,
  4101. i = -1;
  4102. self.callActions('beforeAttach', arguments);
  4103. self.id = id;
  4104. if (config) {
  4105. h.extend(self.config, config, true, true);
  4106. }
  4107. self.sanitizeConfig();
  4108. self.cacheDom(container, document);
  4109. if (self.config.layout.containerClassName) {
  4110. h.addClass(self.dom.container, self.config.layout.containerClassName);
  4111. }
  4112. if (!mixitup.features.has.transitions) {
  4113. self.config.animation.enable = false;
  4114. }
  4115. if (typeof window.console === 'undefined') {
  4116. self.config.debug.showWarnings = false;
  4117. }
  4118. if (self.config.data.uidKey) {
  4119. // If the dataset API is in use, force disable controls
  4120. self.config.controls.enable = false;
  4121. }
  4122. self.indexTargets();
  4123. self.state = self.getInitialState();
  4124. for (i = 0; target = self.lastOperation.toHide[i]; i++) {
  4125. target.hide();
  4126. }
  4127. if (self.config.controls.enable) {
  4128. self.initControls();
  4129. self.buildToggleArray(null, self.state);
  4130. self.updateControls({
  4131. filter: self.state.activeFilter,
  4132. sort: self.state.activeSort
  4133. });
  4134. }
  4135. self.parseEffects();
  4136. self.callActions('afterAttach', arguments);
  4137. },
  4138. /**
  4139. * @private
  4140. * @instance
  4141. * @since 3.0.0
  4142. * @return {void}
  4143. */
  4144. sanitizeConfig: function() {
  4145. var self = this;
  4146. self.callActions('beforeSanitizeConfig', arguments);
  4147. // Sanitize enum/string config options
  4148. self.config.controls.scope = self.config.controls.scope.toLowerCase().trim();
  4149. self.config.controls.toggleLogic = self.config.controls.toggleLogic.toLowerCase().trim();
  4150. self.config.controls.toggleDefault = self.config.controls.toggleDefault.toLowerCase().trim();
  4151. self.config.animation.effects = self.config.animation.effects.trim();
  4152. self.callActions('afterSanitizeConfig', arguments);
  4153. },
  4154. /**
  4155. * @private
  4156. * @instance
  4157. * @since 3.0.0
  4158. * @return {mixitup.State}
  4159. */
  4160. getInitialState: function() {
  4161. var self = this,
  4162. state = new mixitup.State(),
  4163. operation = new mixitup.Operation();
  4164. self.callActions('beforeGetInitialState', arguments);
  4165. // Map initial values into a mock state object in order to construct an operation
  4166. state.activeContainerClassName = self.config.layout.containerClassName;
  4167. if (self.config.load.dataset) {
  4168. // Dataset API
  4169. if (!self.config.data.uidKey || typeof self.config.data.uidKey !== 'string') {
  4170. throw new TypeError(mixitup.messages.errorConfigDataUidKeyNotSet());
  4171. }
  4172. operation.startDataset = operation.newDataset = state.activeDataset = self.config.load.dataset.slice();
  4173. operation.startContainerClassName = operation.newContainerClassName = state.activeContainerClassName;
  4174. operation.show = self.targets.slice();
  4175. state = self.callFilters('stateGetInitialState', state, arguments);
  4176. } else {
  4177. // DOM API
  4178. state.activeFilter = self.parseFilterArgs([self.config.load.filter]).command;
  4179. state.activeSort = self.parseSortArgs([self.config.load.sort]).command;
  4180. state.totalTargets = self.targets.length;
  4181. state = self.callFilters('stateGetInitialState', state, arguments);
  4182. if (
  4183. state.activeSort.collection || state.activeSort.attribute ||
  4184. state.activeSort.order === 'random' || state.activeSort.order === 'desc'
  4185. ) {
  4186. // Sorting on load
  4187. operation.newSort = state.activeSort;
  4188. self.sortOperation(operation);
  4189. self.printSort(false, operation);
  4190. self.targets = operation.newOrder;
  4191. } else {
  4192. operation.startOrder = operation.newOrder = self.targets;
  4193. }
  4194. operation.startFilter = operation.newFilter = state.activeFilter;
  4195. operation.startSort = operation.newSort = state.activeSort;
  4196. operation.startContainerClassName = operation.newContainerClassName = state.activeContainerClassName;
  4197. if (operation.newFilter.selector === 'all') {
  4198. operation.newFilter.selector = self.config.selectors.target;
  4199. } else if (operation.newFilter.selector === 'none') {
  4200. operation.newFilter.selector = '';
  4201. }
  4202. }
  4203. operation = self.callFilters('operationGetInitialState', operation, [state]);
  4204. self.lastOperation = operation;
  4205. if (operation.newFilter) {
  4206. self.filterOperation(operation);
  4207. }
  4208. state = self.buildState(operation);
  4209. return state;
  4210. },
  4211. /**
  4212. * Caches references of DOM elements neccessary for the mixer's functionality.
  4213. *
  4214. * @private
  4215. * @instance
  4216. * @since 3.0.0
  4217. * @param {HTMLElement} el
  4218. * @param {HTMLHtmlElement} document
  4219. * @return {void}
  4220. */
  4221. cacheDom: function(el, document) {
  4222. var self = this;
  4223. self.callActions('beforeCacheDom', arguments);
  4224. self.dom.document = document;
  4225. self.dom.body = self.dom.document.querySelector('body');
  4226. self.dom.container = el;
  4227. self.dom.parent = el;
  4228. self.callActions('afterCacheDom', arguments);
  4229. },
  4230. /**
  4231. * Indexes all child elements of the mixer matching the `selectors.target`
  4232. * selector, instantiating a mixitup.Target for each one.
  4233. *
  4234. * @private
  4235. * @instance
  4236. * @since 3.0.0
  4237. * @return {void}
  4238. */
  4239. indexTargets: function() {
  4240. var self = this,
  4241. target = null,
  4242. el = null,
  4243. dataset = null,
  4244. i = -1;
  4245. self.callActions('beforeIndexTargets', arguments);
  4246. self.dom.targets = self.config.layout.allowNestedTargets ?
  4247. self.dom.container.querySelectorAll(self.config.selectors.target) :
  4248. h.children(self.dom.container, self.config.selectors.target, self.dom.document);
  4249. self.dom.targets = h.arrayFromList(self.dom.targets);
  4250. self.targets = [];
  4251. if ((dataset = self.config.load.dataset) && dataset.length !== self.dom.targets.length) {
  4252. throw new Error(mixitup.messages.errorDatasetPrerenderedMismatch());
  4253. }
  4254. if (self.dom.targets.length) {
  4255. for (i = 0; el = self.dom.targets[i]; i++) {
  4256. target = new mixitup.Target();
  4257. target.init(el, self, dataset ? dataset[i] : void(0));
  4258. target.isInDom = true;
  4259. self.targets.push(target);
  4260. }
  4261. self.dom.parent = self.dom.targets[0].parentElement === self.dom.container ?
  4262. self.dom.container :
  4263. self.dom.targets[0].parentElement;
  4264. }
  4265. self.origOrder = self.targets;
  4266. self.callActions('afterIndexTargets', arguments);
  4267. },
  4268. initControls: function() {
  4269. var self = this,
  4270. definition = '',
  4271. controlElements = null,
  4272. el = null,
  4273. parent = null,
  4274. delagators = null,
  4275. control = null,
  4276. i = -1,
  4277. j = -1;
  4278. self.callActions('beforeInitControls', arguments);
  4279. switch (self.config.controls.scope) {
  4280. case 'local':
  4281. parent = self.dom.container;
  4282. break;
  4283. case 'global':
  4284. parent = self.dom.document;
  4285. break;
  4286. default:
  4287. throw new Error(mixitup.messages.errorConfigInvalidControlsScope());
  4288. }
  4289. for (i = 0; definition = mixitup.controlDefinitions[i]; i++) {
  4290. if (self.config.controls.live || definition.live) {
  4291. if (definition.parent) {
  4292. delagators = self.dom[definition.parent];
  4293. if (!delagators || delagators.length < 0) continue;
  4294. if (typeof delagators.length !== 'number') {
  4295. delagators = [delagators];
  4296. }
  4297. } else {
  4298. delagators = [parent];
  4299. }
  4300. for (j = 0; (el = delagators[j]); j++) {
  4301. control = self.getControl(el, definition.type, definition.selector);
  4302. self.controls.push(control);
  4303. }
  4304. } else {
  4305. controlElements = parent.querySelectorAll(self.config.selectors.control + definition.selector);
  4306. for (j = 0; (el = controlElements[j]); j++) {
  4307. control = self.getControl(el, definition.type, '');
  4308. if (!control) continue;
  4309. self.controls.push(control);
  4310. }
  4311. }
  4312. }
  4313. self.callActions('afterInitControls', arguments);
  4314. },
  4315. /**
  4316. * @private
  4317. * @instance
  4318. * @since 3.0.0
  4319. * @param {HTMLElement} el
  4320. * @param {string} type
  4321. * @param {string} selector
  4322. * @return {mixitup.Control|null}
  4323. */
  4324. getControl: function(el, type, selector) {
  4325. var self = this,
  4326. control = null,
  4327. i = -1;
  4328. self.callActions('beforeGetControl', arguments);
  4329. if (!selector) {
  4330. // Static controls only
  4331. for (i = 0; control = mixitup.controls[i]; i++) {
  4332. if (control.el === el && control.isBound(self)) {
  4333. // Control already bound to this mixer (as another type).
  4334. // NB: This prevents duplicate controls from being registered where a selector
  4335. // might collide, eg: "[data-filter]" and "[data-filter][data-sort]"
  4336. return self.callFilters('controlGetControl', null, arguments);
  4337. } else if (control.el === el && control.type === type && control.selector === selector) {
  4338. // Another mixer is already using this control, add this mixer as a binding
  4339. control.addBinding(self);
  4340. return self.callFilters('controlGetControl', control, arguments);
  4341. }
  4342. }
  4343. }
  4344. // Create new control
  4345. control = new mixitup.Control();
  4346. control.init(el, type, selector);
  4347. control.classNames.base = h.getClassname(self.config.classNames, type);
  4348. control.classNames.active = h.getClassname(self.config.classNames, type, self.config.classNames.modifierActive);
  4349. control.classNames.disabled = h.getClassname(self.config.classNames, type, self.config.classNames.modifierDisabled);
  4350. // Add a reference to this mixer as a binding
  4351. control.addBinding(self);
  4352. return self.callFilters('controlGetControl', control, arguments);
  4353. },
  4354. /**
  4355. * Creates a compound selector by joining the `toggleArray` value as per the
  4356. * defined toggle logic.
  4357. *
  4358. * @private
  4359. * @instance
  4360. * @since 3.0.0
  4361. * @return {string}
  4362. */
  4363. getToggleSelector: function() {
  4364. var self = this,
  4365. delineator = self.config.controls.toggleLogic === 'or' ? ', ' : '',
  4366. toggleSelector = '';
  4367. self.callActions('beforeGetToggleSelector', arguments);
  4368. self.toggleArray = h.clean(self.toggleArray);
  4369. toggleSelector = self.toggleArray.join(delineator);
  4370. if (toggleSelector === '') {
  4371. toggleSelector = self.config.controls.toggleDefault;
  4372. }
  4373. return self.callFilters('selectorGetToggleSelector', toggleSelector, arguments);
  4374. },
  4375. /**
  4376. * Breaks compound selector strings in an array of discreet selectors,
  4377. * as per the active `controls.toggleLogic` configuration option. Accepts
  4378. * either a dynamic command object, or a state object.
  4379. *
  4380. * @private
  4381. * @instance
  4382. * @since 2.0.0
  4383. * @param {object} [command]
  4384. * @param {mixitup.State} [state]
  4385. * @return {void}
  4386. */
  4387. buildToggleArray: function(command, state) {
  4388. var self = this,
  4389. activeFilterSelector = '';
  4390. self.callActions('beforeBuildToggleArray', arguments);
  4391. if (command && command.filter) {
  4392. activeFilterSelector = command.filter.selector.replace(/\s/g, '');
  4393. } else if (state) {
  4394. activeFilterSelector = state.activeFilter.selector.replace(/\s/g, '');
  4395. } else {
  4396. return;
  4397. }
  4398. if (activeFilterSelector === self.config.selectors.target || activeFilterSelector === 'all') {
  4399. activeFilterSelector = '';
  4400. }
  4401. if (self.config.controls.toggleLogic === 'or') {
  4402. self.toggleArray = activeFilterSelector.split(',');
  4403. } else {
  4404. self.toggleArray = self.splitCompoundSelector(activeFilterSelector);
  4405. }
  4406. self.toggleArray = h.clean(self.toggleArray);
  4407. self.callActions('afterBuildToggleArray', arguments);
  4408. },
  4409. /**
  4410. * Takes a compound selector (e.g. `.cat-1.cat-2`, `[data-cat="1"][data-cat="2"]`)
  4411. * and breaks into its individual selectors.
  4412. *
  4413. * @private
  4414. * @instance
  4415. * @since 3.0.0
  4416. * @param {string} compoundSelector
  4417. * @return {string[]}
  4418. */
  4419. splitCompoundSelector: function(compoundSelector) {
  4420. // Break at a `.` or `[`, capturing the delineator
  4421. var partials = compoundSelector.split(/([\.\[])/g),
  4422. toggleArray = [],
  4423. selector = '',
  4424. i = -1;
  4425. if (partials[0] === '') {
  4426. partials.shift();
  4427. }
  4428. for (i = 0; i < partials.length; i++) {
  4429. if (i % 2 === 0) {
  4430. selector = '';
  4431. }
  4432. selector += partials[i];
  4433. if (i % 2 !== 0) {
  4434. toggleArray.push(selector);
  4435. }
  4436. }
  4437. return toggleArray;
  4438. },
  4439. /**
  4440. * Updates controls to their active/inactive state based on the command or
  4441. * current state of the mixer.
  4442. *
  4443. * @private
  4444. * @instance
  4445. * @since 2.0.0
  4446. * @param {object} command
  4447. * @return {void}
  4448. */
  4449. updateControls: function(command) {
  4450. var self = this,
  4451. control = null,
  4452. output = new mixitup.CommandMultimix(),
  4453. i = -1;
  4454. self.callActions('beforeUpdateControls', arguments);
  4455. // Sanitise to defaults
  4456. if (command.filter) {
  4457. output.filter = command.filter.selector;
  4458. } else {
  4459. output.filter = self.state.activeFilter.selector;
  4460. }
  4461. if (command.sort) {
  4462. output.sort = self.buildSortString(command.sort);
  4463. } else {
  4464. output.sort = self.buildSortString(self.state.activeSort);
  4465. }
  4466. if (output.filter === self.config.selectors.target) {
  4467. output.filter = 'all';
  4468. }
  4469. if (output.filter === '') {
  4470. output.filter = 'none';
  4471. }
  4472. h.freeze(output);
  4473. for (i = 0; control = self.controls[i]; i++) {
  4474. control.update(output, self.toggleArray);
  4475. }
  4476. self.callActions('afterUpdateControls', arguments);
  4477. },
  4478. /**
  4479. * @private
  4480. * @instance
  4481. * @since 3.0.0
  4482. * @param {mixitup.CommandSort} command
  4483. * @return {string}
  4484. */
  4485. buildSortString: function(command) {
  4486. var self = this;
  4487. var output = '';
  4488. output += command.sortString;
  4489. if (command.next) {
  4490. output += ' ' + self.buildSortString(command.next);
  4491. }
  4492. return output;
  4493. },
  4494. /**
  4495. * @private
  4496. * @instance
  4497. * @since 3.0.0
  4498. * @param {object} command
  4499. * @param {Operation} operation
  4500. * @return {Promise.<mixitup.State>}
  4501. */
  4502. insertTargets: function(command, operation) {
  4503. var self = this,
  4504. nextSibling = null,
  4505. insertionIndex = -1,
  4506. frag = null,
  4507. target = null,
  4508. el = null,
  4509. i = -1;
  4510. self.callActions('beforeInsertTargets', arguments);
  4511. if (typeof command.index === 'undefined') command.index = 0;
  4512. nextSibling = self.getNextSibling(command.index, command.sibling, command.position);
  4513. frag = self.dom.document.createDocumentFragment();
  4514. if (nextSibling) {
  4515. insertionIndex = h.index(nextSibling, self.config.selectors.target);
  4516. } else {
  4517. insertionIndex = self.targets.length;
  4518. }
  4519. if (command.collection) {
  4520. for (i = 0; el = command.collection[i]; i++) {
  4521. if (self.dom.targets.indexOf(el) > -1) {
  4522. throw new Error(mixitup.messages.errorInsertPreexistingElement());
  4523. }
  4524. // Ensure elements are hidden when they are added to the DOM, so they can
  4525. // be animated in gracefully
  4526. el.style.display = 'none';
  4527. frag.appendChild(el);
  4528. frag.appendChild(self.dom.document.createTextNode(' '));
  4529. if (!h.isElement(el, self.dom.document) || !el.matches(self.config.selectors.target)) continue;
  4530. target = new mixitup.Target();
  4531. target.init(el, self);
  4532. target.isInDom = true;
  4533. self.targets.splice(insertionIndex, 0, target);
  4534. insertionIndex++;
  4535. }
  4536. self.dom.parent.insertBefore(frag, nextSibling);
  4537. }
  4538. // Since targets have been added, the original order must be updated
  4539. operation.startOrder = self.origOrder = self.targets;
  4540. self.callActions('afterInsertTargets', arguments);
  4541. },
  4542. /**
  4543. * @private
  4544. * @instance
  4545. * @since 3.0.0
  4546. * @param {Number} [index]
  4547. * @param {Element} [sibling]
  4548. * @param {string} [position]
  4549. * @return {Element}
  4550. */
  4551. getNextSibling: function(index, sibling, position) {
  4552. var self = this,
  4553. element = null;
  4554. index = Math.max(index, 0);
  4555. if (sibling && position === 'before') {
  4556. // Explicit sibling
  4557. element = sibling;
  4558. } else if (sibling && position === 'after') {
  4559. // Explicit sibling
  4560. element = sibling.nextElementSibling || null;
  4561. } else if (self.targets.length > 0 && typeof index !== 'undefined') {
  4562. // Index and targets exist
  4563. element = (index < self.targets.length || !self.targets.length) ?
  4564. self.targets[index].dom.el :
  4565. self.targets[self.targets.length - 1].dom.el.nextElementSibling;
  4566. } else if (self.targets.length === 0 && self.dom.parent.children.length > 0) {
  4567. // No targets but other siblings
  4568. if (self.config.layout.siblingAfter) {
  4569. element = self.config.layout.siblingAfter;
  4570. } else if (self.config.layout.siblingBefore) {
  4571. element = self.config.layout.siblingBefore.nextElementSibling;
  4572. } else {
  4573. self.dom.parent.children[0];
  4574. }
  4575. } else {
  4576. element === null;
  4577. }
  4578. return self.callFilters('elementGetNextSibling', element, arguments);
  4579. },
  4580. /**
  4581. * @private
  4582. * @instance
  4583. * @since 2.0.0
  4584. * @param {Operation} operation
  4585. * @return {void}
  4586. */
  4587. filterOperation: function(operation) {
  4588. var self = this,
  4589. testResult = false,
  4590. index = -1,
  4591. action = '',
  4592. target = null,
  4593. i = -1;
  4594. self.callActions('beforeFilterOperation', arguments);
  4595. action = operation.newFilter.action;
  4596. for (i = 0; target = operation.newOrder[i]; i++) {
  4597. if (operation.newFilter.collection) {
  4598. // show via collection
  4599. testResult = operation.newFilter.collection.indexOf(target.dom.el) > -1;
  4600. } else {
  4601. // show via selector
  4602. if (operation.newFilter.selector === '') {
  4603. testResult = false;
  4604. } else {
  4605. testResult = target.dom.el.matches(operation.newFilter.selector);
  4606. }
  4607. }
  4608. self.evaluateHideShow(testResult, target, action, operation);
  4609. }
  4610. if (operation.toRemove.length) {
  4611. for (i = 0; target = operation.show[i]; i++) {
  4612. if (operation.toRemove.indexOf(target) > -1) {
  4613. // If any shown targets should be removed, move them into the toHide array
  4614. operation.show.splice(i, 1);
  4615. if ((index = operation.toShow.indexOf(target)) > -1) {
  4616. operation.toShow.splice(index, 1);
  4617. }
  4618. operation.toHide.push(target);
  4619. operation.hide.push(target);
  4620. i--;
  4621. }
  4622. }
  4623. }
  4624. operation.matching = operation.show.slice();
  4625. if (operation.show.length === 0 && operation.newFilter.selector !== '' && self.targets.length !== 0) {
  4626. operation.hasFailed = true;
  4627. }
  4628. self.callActions('afterFilterOperation', arguments);
  4629. },
  4630. /**
  4631. * @private
  4632. * @instance
  4633. * @since 3.0.0
  4634. * @param {boolean} testResult
  4635. * @param {Element} target
  4636. * @param {string} action
  4637. * @param {Operation} operation
  4638. * @return {void}
  4639. */
  4640. evaluateHideShow: function(testResult, target, action, operation) {
  4641. var self = this,
  4642. filteredTestResult = false,
  4643. args = Array.prototype.slice.call(arguments, 1);
  4644. filteredTestResult = self.callFilters('testResultEvaluateHideShow', testResult, args);
  4645. self.callActions('beforeEvaluateHideShow', arguments);
  4646. if (
  4647. filteredTestResult === true && action === 'show' ||
  4648. filteredTestResult === false && action === 'hide'
  4649. ) {
  4650. operation.show.push(target);
  4651. !target.isShown && operation.toShow.push(target);
  4652. } else {
  4653. operation.hide.push(target);
  4654. target.isShown && operation.toHide.push(target);
  4655. }
  4656. self.callActions('afterEvaluateHideShow', arguments);
  4657. },
  4658. /**
  4659. * @private
  4660. * @instance
  4661. * @since 2.0.0
  4662. * @param {Operation} operation
  4663. * @return {void}
  4664. */
  4665. sortOperation: function(operation) {
  4666. var self = this;
  4667. self.callActions('beforeSortOperation', arguments);
  4668. operation.startOrder = self.targets;
  4669. if (operation.newSort.collection) {
  4670. // Sort by collection
  4671. operation.newOrder = operation.newSort.collection;
  4672. } else if (operation.newSort.order === 'random') {
  4673. // Sort random
  4674. operation.newOrder = h.arrayShuffle(operation.startOrder);
  4675. } else if (operation.newSort.attribute === '') {
  4676. // Sort by default
  4677. operation.newOrder = self.origOrder.slice();
  4678. if (operation.newSort.order === 'desc') {
  4679. operation.newOrder.reverse();
  4680. }
  4681. } else {
  4682. // Sort by attribute
  4683. operation.newOrder = operation.startOrder.slice();
  4684. operation.newOrder.sort(function(a, b) {
  4685. return self.compare(a, b, operation.newSort);
  4686. });
  4687. }
  4688. if (h.isEqualArray(operation.newOrder, operation.startOrder)) {
  4689. operation.willSort = false;
  4690. }
  4691. self.callActions('afterSortOperation', arguments);
  4692. },
  4693. /**
  4694. * @private
  4695. * @instance
  4696. * @since 2.0.0
  4697. * @param {mixitup.Target} a
  4698. * @param {mixitup.Target} b
  4699. * @param {mixitup.CommandSort} command
  4700. * @return {Number}
  4701. */
  4702. compare: function(a, b, command) {
  4703. var self = this,
  4704. order = command.order,
  4705. attrA = self.getAttributeValue(a, command.attribute),
  4706. attrB = self.getAttributeValue(b, command.attribute);
  4707. if (isNaN(attrA * 1) || isNaN(attrB * 1)) {
  4708. attrA = attrA.toLowerCase();
  4709. attrB = attrB.toLowerCase();
  4710. } else {
  4711. attrA = attrA * 1;
  4712. attrB = attrB * 1;
  4713. }
  4714. if (attrA < attrB) {
  4715. return order === 'asc' ? -1 : 1;
  4716. }
  4717. if (attrA > attrB) {
  4718. return order === 'asc' ? 1 : -1;
  4719. }
  4720. if (attrA === attrB && command.next) {
  4721. return self.compare(a, b, command.next);
  4722. }
  4723. return 0;
  4724. },
  4725. /**
  4726. * Reads the values of any data attributes present the provided target element
  4727. * which match the current sort command.
  4728. *
  4729. * @private
  4730. * @instance
  4731. * @since 3.0.0
  4732. * @param {mixitup.Target} target
  4733. * @param {string} [attribute]
  4734. * @return {(String|Number)}
  4735. */
  4736. getAttributeValue: function(target, attribute) {
  4737. var self = this,
  4738. value = '';
  4739. value = target.dom.el.getAttribute('data-' + attribute);
  4740. if (value === null) {
  4741. if (self.config.debug.showWarnings) {
  4742. // Encourage users to assign values to all targets to avoid erroneous sorting
  4743. // when types are mixed
  4744. console.warn(mixitup.messages.warningInconsistentSortingAttributes({
  4745. attribute: 'data-' + attribute
  4746. }));
  4747. }
  4748. }
  4749. // If an attribute is not present, return 0 as a safety value
  4750. return self.callFilters('valueGetAttributeValue', value || 0, arguments);
  4751. },
  4752. /**
  4753. * Inserts elements into the DOM in the appropriate
  4754. * order using a document fragment for minimal
  4755. * DOM thrashing
  4756. *
  4757. * @private
  4758. * @instance
  4759. * @since 2.0.0
  4760. * @param {boolean} isResetting
  4761. * @param {Operation} operation
  4762. * @return {void}
  4763. */
  4764. printSort: function(isResetting, operation) {
  4765. var self = this,
  4766. startOrder = isResetting ? operation.newOrder : operation.startOrder,
  4767. newOrder = isResetting ? operation.startOrder : operation.newOrder,
  4768. nextSibling = startOrder.length ? startOrder[startOrder.length - 1].dom.el.nextElementSibling : null,
  4769. frag = window.document.createDocumentFragment(),
  4770. whitespace = null,
  4771. target = null,
  4772. el = null,
  4773. i = -1;
  4774. self.callActions('beforePrintSort', arguments);
  4775. // Empty the container
  4776. for (i = 0; target = startOrder[i]; i++) {
  4777. el = target.dom.el;
  4778. if (el.style.position === 'absolute') continue;
  4779. h.removeWhitespace(el.previousSibling);
  4780. el.parentElement.removeChild(el);
  4781. }
  4782. whitespace = nextSibling ? nextSibling.previousSibling : self.dom.parent.lastChild;
  4783. if (whitespace && whitespace.nodeName === '#text') {
  4784. h.removeWhitespace(whitespace);
  4785. }
  4786. for (i = 0; target = newOrder[i]; i++) {
  4787. // Add targets into a document fragment
  4788. el = target.dom.el;
  4789. if (h.isElement(frag.lastChild)) {
  4790. frag.appendChild(window.document.createTextNode(' '));
  4791. }
  4792. frag.appendChild(el);
  4793. }
  4794. // Insert the document fragment into the container
  4795. // before any other non-target elements
  4796. if (self.dom.parent.firstChild && self.dom.parent.firstChild !== nextSibling) {
  4797. frag.insertBefore(window.document.createTextNode(' '), frag.childNodes[0]);
  4798. }
  4799. if (nextSibling) {
  4800. frag.appendChild(window.document.createTextNode(' '));
  4801. self.dom.parent.insertBefore(frag, nextSibling);
  4802. } else {
  4803. self.dom.parent.appendChild(frag);
  4804. }
  4805. self.callActions('afterPrintSort', arguments);
  4806. },
  4807. /**
  4808. * Parses user-defined sort strings (i.e. `default:asc`) into sort commands objects.
  4809. *
  4810. * @private
  4811. * @instance
  4812. * @since 3.0.0
  4813. * @param {string} sortString
  4814. * @param {mixitup.CommandSort} command
  4815. * @return {mixitup.CommandSort}
  4816. */
  4817. parseSortString: function(sortString, command) {
  4818. var self = this,
  4819. rules = sortString.split(' '),
  4820. current = command,
  4821. rule = [],
  4822. i = -1;
  4823. // command.sortString = sortString;
  4824. for (i = 0; i < rules.length; i++) {
  4825. rule = rules[i].split(':');
  4826. current.sortString = rules[i];
  4827. current.attribute = h.dashCase(rule[0]);
  4828. current.order = rule[1] || 'asc';
  4829. switch (current.attribute) {
  4830. case 'default':
  4831. // treat "default" as sorting by no attribute
  4832. current.attribute = '';
  4833. break;
  4834. case 'random':
  4835. // treat "random" as an order not an attribute
  4836. current.attribute = '';
  4837. current.order = 'random';
  4838. break;
  4839. }
  4840. if (!current.attribute || current.order === 'random') break;
  4841. if (i < rules.length - 1) {
  4842. // Embed reference to the next command
  4843. current.next = new mixitup.CommandSort();
  4844. h.freeze(current);
  4845. current = current.next;
  4846. }
  4847. }
  4848. return self.callFilters('commandsParseSort', command, arguments);
  4849. },
  4850. /**
  4851. * Parses all effects out of the user-defined `animation.effects` string into
  4852. * their respective properties and units.
  4853. *
  4854. * @private
  4855. * @instance
  4856. * @since 2.0.0
  4857. * @return {void}
  4858. */
  4859. parseEffects: function() {
  4860. var self = this,
  4861. transformName = '',
  4862. effectsIn = self.config.animation.effectsIn || self.config.animation.effects,
  4863. effectsOut = self.config.animation.effectsOut || self.config.animation.effects;
  4864. self.callActions('beforeParseEffects', arguments);
  4865. self.effectsIn = new mixitup.StyleData();
  4866. self.effectsOut = new mixitup.StyleData();
  4867. self.transformIn = [];
  4868. self.transformOut = [];
  4869. self.effectsIn.opacity = self.effectsOut.opacity = 1;
  4870. self.parseEffect('fade', effectsIn, self.effectsIn, self.transformIn);
  4871. self.parseEffect('fade', effectsOut, self.effectsOut, self.transformOut, true);
  4872. for (transformName in mixitup.transformDefaults) {
  4873. if (!(mixitup.transformDefaults[transformName] instanceof mixitup.TransformData)) {
  4874. continue;
  4875. }
  4876. self.parseEffect(transformName, effectsIn, self.effectsIn, self.transformIn);
  4877. self.parseEffect(transformName, effectsOut, self.effectsOut, self.transformOut, true);
  4878. }
  4879. self.parseEffect('stagger', effectsIn, self.effectsIn, self.transformIn);
  4880. self.parseEffect('stagger', effectsOut, self.effectsOut, self.transformOut, true);
  4881. self.callActions('afterParseEffects', arguments);
  4882. },
  4883. /**
  4884. * @private
  4885. * @instance
  4886. * @since 2.0.0
  4887. * @param {string} effectName
  4888. * @param {string} effectString
  4889. * @param {StyleData} effects
  4890. * @param {String[]} transform
  4891. * @param {boolean} [isOut]
  4892. */
  4893. parseEffect: function(effectName, effectString, effects, transform, isOut) {
  4894. var self = this,
  4895. re = /\(([^)]+)\)/,
  4896. propIndex = -1,
  4897. str = '',
  4898. match = [],
  4899. val = '',
  4900. units = ['%', 'px', 'em', 'rem', 'vh', 'vw', 'deg'],
  4901. unit = '',
  4902. i = -1;
  4903. self.callActions('beforeParseEffect', arguments);
  4904. if (typeof effectString !== 'string') {
  4905. throw new TypeError(mixitup.messages.errorConfigInvalidAnimationEffects());
  4906. }
  4907. if (effectString.indexOf(effectName) < 0) {
  4908. // The effect is not present in the effects string
  4909. if (effectName === 'stagger') {
  4910. // Reset stagger to 0
  4911. self.staggerDuration = 0;
  4912. }
  4913. return;
  4914. }
  4915. // The effect is present
  4916. propIndex = effectString.indexOf(effectName + '(');
  4917. if (propIndex > -1) {
  4918. // The effect has a user defined value in parentheses
  4919. // Extract from the first parenthesis to the end of string
  4920. str = effectString.substring(propIndex);
  4921. // Match any number of characters between "(" and ")"
  4922. match = re.exec(str);
  4923. val = match[1];
  4924. }
  4925. switch (effectName) {
  4926. case 'fade':
  4927. effects.opacity = val ? parseFloat(val) : 0;
  4928. break;
  4929. case 'stagger':
  4930. self.staggerDuration = val ? parseFloat(val) : 100;
  4931. // TODO: Currently stagger must be applied globally, but
  4932. // if seperate values are specified for in/out, this should
  4933. // be respected
  4934. break;
  4935. default:
  4936. // All other effects are transforms following the same structure
  4937. if (isOut && self.config.animation.reverseOut && effectName !== 'scale') {
  4938. effects[effectName].value =
  4939. (val ? parseFloat(val) : mixitup.transformDefaults[effectName].value) * -1;
  4940. } else {
  4941. effects[effectName].value =
  4942. (val ? parseFloat(val) : mixitup.transformDefaults[effectName].value);
  4943. }
  4944. if (val) {
  4945. for (i = 0; unit = units[i]; i++) {
  4946. if (val.indexOf(unit) > -1) {
  4947. effects[effectName].unit = unit;
  4948. break;
  4949. }
  4950. }
  4951. } else {
  4952. effects[effectName].unit = mixitup.transformDefaults[effectName].unit;
  4953. }
  4954. transform.push(
  4955. effectName +
  4956. '(' +
  4957. effects[effectName].value +
  4958. effects[effectName].unit +
  4959. ')'
  4960. );
  4961. }
  4962. self.callActions('afterParseEffect', arguments);
  4963. },
  4964. /**
  4965. * @private
  4966. * @instance
  4967. * @since 2.0.0
  4968. * @param {Operation} operation
  4969. * @return {State}
  4970. */
  4971. buildState: function(operation) {
  4972. var self = this,
  4973. state = new mixitup.State(),
  4974. target = null,
  4975. i = -1;
  4976. self.callActions('beforeBuildState', arguments);
  4977. // Map target elements into state arrays.
  4978. // the real target objects should never be exposed
  4979. for (i = 0; target = self.targets[i]; i++) {
  4980. if (!operation.toRemove.length || operation.toRemove.indexOf(target) < 0) {
  4981. state.targets.push(target.dom.el);
  4982. }
  4983. }
  4984. for (i = 0; target = operation.matching[i]; i++) {
  4985. state.matching.push(target.dom.el);
  4986. }
  4987. for (i = 0; target = operation.show[i]; i++) {
  4988. state.show.push(target.dom.el);
  4989. }
  4990. for (i = 0; target = operation.hide[i]; i++) {
  4991. if (!operation.toRemove.length || operation.toRemove.indexOf(target) < 0) {
  4992. state.hide.push(target.dom.el);
  4993. }
  4994. }
  4995. state.id = self.id;
  4996. state.container = self.dom.container;
  4997. state.activeFilter = operation.newFilter;
  4998. state.activeSort = operation.newSort;
  4999. state.activeDataset = operation.newDataset;
  5000. state.activeContainerClassName = operation.newContainerClassName;
  5001. state.hasFailed = operation.hasFailed;
  5002. state.totalTargets = self.targets.length;
  5003. state.totalShow = operation.show.length;
  5004. state.totalHide = operation.hide.length;
  5005. state.totalMatching = operation.matching.length;
  5006. state.triggerElement = operation.triggerElement;
  5007. return self.callFilters('stateBuildState', state, arguments);
  5008. },
  5009. /**
  5010. * @private
  5011. * @instance
  5012. * @since 2.0.0
  5013. * @param {boolean} shouldAnimate
  5014. * @param {Operation} operation
  5015. * @return {void}
  5016. */
  5017. goMix: function(shouldAnimate, operation) {
  5018. var self = this,
  5019. deferred = null;
  5020. self.callActions('beforeGoMix', arguments);
  5021. // If the animation duration is set to 0ms,
  5022. // or no effects specified,
  5023. // or the container is hidden
  5024. // then abort animation
  5025. if (
  5026. !self.config.animation.duration || !self.config.animation.effects || !h.isVisible(self.dom.container)
  5027. ) {
  5028. shouldAnimate = false;
  5029. }
  5030. if (
  5031. !operation.toShow.length &&
  5032. !operation.toHide.length &&
  5033. !operation.willSort &&
  5034. !operation.willChangeLayout
  5035. ) {
  5036. // If nothing to show or hide, and not sorting or
  5037. // changing layout
  5038. shouldAnimate = false;
  5039. }
  5040. if (
  5041. !operation.startState.show.length &&
  5042. !operation.show.length
  5043. ) {
  5044. // If nothing currently shown, nothing to show
  5045. shouldAnimate = false;
  5046. }
  5047. mixitup.events.fire('mixStart', self.dom.container, {
  5048. state: operation.startState,
  5049. futureState: operation.newState,
  5050. instance: self
  5051. }, self.dom.document);
  5052. if (typeof self.config.callbacks.onMixStart === 'function') {
  5053. self.config.callbacks.onMixStart.call(
  5054. self.dom.container,
  5055. operation.startState,
  5056. operation.newState,
  5057. self
  5058. );
  5059. }
  5060. h.removeClass(self.dom.container, h.getClassname(self.config.classNames, 'container', self.config.classNames.modifierFailed));
  5061. if (!self.userDeferred) {
  5062. // Queue empty, no pending operations
  5063. deferred = self.userDeferred = h.defer(mixitup.libraries);
  5064. } else {
  5065. // Use existing deferred
  5066. deferred = self.userDeferred;
  5067. }
  5068. self.isBusy = true;
  5069. if (!shouldAnimate || !mixitup.features.has.transitions) {
  5070. // Abort
  5071. if (self.config.debug.fauxAsync) {
  5072. setTimeout(function() {
  5073. self.cleanUp(operation);
  5074. }, self.config.animation.duration);
  5075. } else {
  5076. self.cleanUp(operation);
  5077. }
  5078. return self.callFilters('promiseGoMix', deferred.promise, arguments);
  5079. }
  5080. // If we should animate and the platform supports transitions, go for it
  5081. if (window.pageYOffset !== operation.docState.scrollTop) {
  5082. window.scrollTo(operation.docState.scrollLeft, operation.docState.scrollTop);
  5083. }
  5084. if (self.config.animation.applyPerspective) {
  5085. self.dom.parent.style[mixitup.features.perspectiveProp] =
  5086. self.config.animation.perspectiveDistance;
  5087. self.dom.parent.style[mixitup.features.perspectiveOriginProp] =
  5088. self.config.animation.perspectiveOrigin;
  5089. }
  5090. if (
  5091. self.config.animation.animateResizeContainer &&
  5092. operation.startHeight !== operation.newHeight &&
  5093. operation.viewportDeltaY !== operation.startHeight - operation.newHeight
  5094. ) {
  5095. self.dom.parent.style.height = operation.startHeight + 'px';
  5096. }
  5097. if (
  5098. self.config.animation.animateResizeContainer &&
  5099. operation.startWidth !== operation.newWidth &&
  5100. operation.viewportDeltaX !== operation.startWidth - operation.newWidth
  5101. ) {
  5102. self.dom.parent.style.width = operation.startWidth + 'px';
  5103. }
  5104. if (operation.startHeight === operation.newHeight) {
  5105. self.dom.parent.style.height = operation.startHeight + 'px';
  5106. }
  5107. if (operation.startWidth === operation.newWidth) {
  5108. self.dom.parent.style.width = operation.startWidth + 'px';
  5109. }
  5110. if (operation.startHeight === operation.newHeight && operation.startWidth === operation.newWidth) {
  5111. self.dom.parent.style.overflow = 'hidden';
  5112. }
  5113. requestAnimationFrame(function() {
  5114. self.moveTargets(operation);
  5115. });
  5116. return self.callFilters('promiseGoMix', deferred.promise, arguments);
  5117. },
  5118. /**
  5119. * @private
  5120. * @instance
  5121. * @since 2.0.0
  5122. * @param {Operation} operation
  5123. * @return {void}
  5124. */
  5125. getStartMixData: function(operation) {
  5126. var self = this,
  5127. parentStyle = window.getComputedStyle(self.dom.parent),
  5128. parentRect = self.dom.parent.getBoundingClientRect(),
  5129. target = null,
  5130. data = {},
  5131. i = -1,
  5132. boxSizing = parentStyle[mixitup.features.boxSizingProp];
  5133. self.incPadding = (boxSizing === 'border-box');
  5134. self.callActions('beforeGetStartMixData', arguments);
  5135. for (i = 0; target = operation.show[i]; i++) {
  5136. data = target.getPosData();
  5137. operation.showPosData[i] = {
  5138. startPosData: data
  5139. };
  5140. }
  5141. for (i = 0; target = operation.toHide[i]; i++) {
  5142. data = target.getPosData();
  5143. operation.toHidePosData[i] = {
  5144. startPosData: data
  5145. };
  5146. }
  5147. operation.startX = parentRect.left;
  5148. operation.startY = parentRect.top;
  5149. operation.startHeight = self.incPadding ?
  5150. parentRect.height :
  5151. parentRect.height -
  5152. parseFloat(parentStyle.paddingTop) -
  5153. parseFloat(parentStyle.paddingBottom) -
  5154. parseFloat(parentStyle.borderTop) -
  5155. parseFloat(parentStyle.borderBottom);
  5156. operation.startWidth = self.incPadding ?
  5157. parentRect.width :
  5158. parentRect.width -
  5159. parseFloat(parentStyle.paddingLeft) -
  5160. parseFloat(parentStyle.paddingRight) -
  5161. parseFloat(parentStyle.borderLeft) -
  5162. parseFloat(parentStyle.borderRight);
  5163. self.callActions('afterGetStartMixData', arguments);
  5164. },
  5165. /**
  5166. * @private
  5167. * @instance
  5168. * @since 2.0.0
  5169. * @param {Operation} operation
  5170. * @return {void}
  5171. */
  5172. setInter: function(operation) {
  5173. var self = this,
  5174. target = null,
  5175. i = -1;
  5176. self.callActions('beforeSetInter', arguments);
  5177. // Prevent scrollbar flicker on non-inertial scroll platforms by clamping height/width
  5178. if (self.config.animation.clampHeight) {
  5179. self.dom.parent.style.height = operation.startHeight + 'px';
  5180. self.dom.parent.style.overflow = 'hidden';
  5181. }
  5182. if (self.config.animation.clampWidth) {
  5183. self.dom.parent.style.width = operation.startWidth + 'px';
  5184. self.dom.parent.style.overflow = 'hidden';
  5185. }
  5186. for (i = 0; target = operation.toShow[i]; i++) {
  5187. target.show();
  5188. }
  5189. if (operation.willChangeLayout) {
  5190. h.removeClass(self.dom.container, operation.startContainerClassName);
  5191. h.addClass(self.dom.container, operation.newContainerClassName);
  5192. }
  5193. self.callActions('afterSetInter', arguments);
  5194. },
  5195. /**
  5196. * @private
  5197. * @instance
  5198. * @since 2.0.0
  5199. * @param {Operation} operation
  5200. * @return {void}
  5201. */
  5202. getInterMixData: function(operation) {
  5203. var self = this,
  5204. target = null,
  5205. i = -1;
  5206. self.callActions('beforeGetInterMixData', arguments);
  5207. for (i = 0; target = operation.show[i]; i++) {
  5208. operation.showPosData[i].interPosData = target.getPosData();
  5209. }
  5210. for (i = 0; target = operation.toHide[i]; i++) {
  5211. operation.toHidePosData[i].interPosData = target.getPosData();
  5212. }
  5213. self.callActions('afterGetInterMixData', arguments);
  5214. },
  5215. /**
  5216. * @private
  5217. * @instance
  5218. * @since 2.0.0
  5219. * @param {Operation} operation
  5220. * @return {void}
  5221. */
  5222. setFinal: function(operation) {
  5223. var self = this,
  5224. target = null,
  5225. i = -1;
  5226. self.callActions('beforeSetFinal', arguments);
  5227. operation.willSort && self.printSort(false, operation);
  5228. for (i = 0; target = operation.toHide[i]; i++) {
  5229. target.hide();
  5230. }
  5231. self.callActions('afterSetFinal', arguments);
  5232. },
  5233. /**
  5234. * @private
  5235. * @instance
  5236. * @since 2.0.0
  5237. * @param {Operation} operation
  5238. * @return {void}
  5239. */
  5240. getFinalMixData: function(operation) {
  5241. var self = this,
  5242. parentStyle = null,
  5243. parentRect = null,
  5244. target = null,
  5245. i = -1;
  5246. self.callActions('beforeGetFinalMixData', arguments);
  5247. for (i = 0; target = operation.show[i]; i++) {
  5248. operation.showPosData[i].finalPosData = target.getPosData();
  5249. }
  5250. for (i = 0; target = operation.toHide[i]; i++) {
  5251. operation.toHidePosData[i].finalPosData = target.getPosData();
  5252. }
  5253. // Remove clamping
  5254. if (self.config.animation.clampHeight || self.config.animation.clampWidth) {
  5255. self.dom.parent.style.height =
  5256. self.dom.parent.style.width =
  5257. self.dom.parent.style.overflow = '';
  5258. }
  5259. if (!self.incPadding) {
  5260. parentStyle = window.getComputedStyle(self.dom.parent);
  5261. }
  5262. parentRect = self.dom.parent.getBoundingClientRect();
  5263. operation.newX = parentRect.left;
  5264. operation.newY = parentRect.top;
  5265. operation.newHeight = self.incPadding ?
  5266. parentRect.height :
  5267. parentRect.height -
  5268. parseFloat(parentStyle.paddingTop) -
  5269. parseFloat(parentStyle.paddingBottom) -
  5270. parseFloat(parentStyle.borderTop) -
  5271. parseFloat(parentStyle.borderBottom);
  5272. operation.newWidth = self.incPadding ?
  5273. parentRect.width :
  5274. parentRect.width -
  5275. parseFloat(parentStyle.paddingLeft) -
  5276. parseFloat(parentStyle.paddingRight) -
  5277. parseFloat(parentStyle.borderLeft) -
  5278. parseFloat(parentStyle.borderRight);
  5279. operation.viewportDeltaX = operation.docState.viewportWidth - this.dom.document.documentElement.clientWidth;
  5280. operation.viewportDeltaY = operation.docState.viewportHeight - this.dom.document.documentElement.clientHeight;
  5281. if (operation.willSort) {
  5282. self.printSort(true, operation);
  5283. }
  5284. for (i = 0; target = operation.toShow[i]; i++) {
  5285. target.hide();
  5286. }
  5287. for (i = 0; target = operation.toHide[i]; i++) {
  5288. target.show();
  5289. }
  5290. if (operation.willChangeLayout) {
  5291. h.removeClass(self.dom.container, operation.newContainerClassName);
  5292. h.addClass(self.dom.container, self.config.layout.containerClassName);
  5293. }
  5294. self.callActions('afterGetFinalMixData', arguments);
  5295. },
  5296. /**
  5297. * @private
  5298. * @instance
  5299. * @since 3.0.0
  5300. * @param {Operation} operation
  5301. */
  5302. getTweenData: function(operation) {
  5303. var self = this,
  5304. target = null,
  5305. posData = null,
  5306. effectNames = Object.getOwnPropertyNames(self.effectsIn),
  5307. effectName = '',
  5308. effect = null,
  5309. widthChange = -1,
  5310. heightChange = -1,
  5311. i = -1,
  5312. j = -1;
  5313. self.callActions('beforeGetTweenData', arguments);
  5314. for (i = 0; target = operation.show[i]; i++) {
  5315. posData = operation.showPosData[i];
  5316. posData.posIn = new mixitup.StyleData();
  5317. posData.posOut = new mixitup.StyleData();
  5318. posData.tweenData = new mixitup.StyleData();
  5319. // Process x and y
  5320. if (target.isShown) {
  5321. posData.posIn.x = posData.startPosData.x - posData.interPosData.x;
  5322. posData.posIn.y = posData.startPosData.y - posData.interPosData.y;
  5323. } else {
  5324. posData.posIn.x = posData.posIn.y = 0;
  5325. }
  5326. posData.posOut.x = posData.finalPosData.x - posData.interPosData.x;
  5327. posData.posOut.y = posData.finalPosData.y - posData.interPosData.y;
  5328. // Process opacity
  5329. posData.posIn.opacity = target.isShown ? 1 : self.effectsIn.opacity;
  5330. posData.posOut.opacity = 1;
  5331. posData.tweenData.opacity = posData.posOut.opacity - posData.posIn.opacity;
  5332. // Adjust x and y if not nudging
  5333. if (!target.isShown && !self.config.animation.nudge) {
  5334. posData.posIn.x = posData.posOut.x;
  5335. posData.posIn.y = posData.posOut.y;
  5336. }
  5337. posData.tweenData.x = posData.posOut.x - posData.posIn.x;
  5338. posData.tweenData.y = posData.posOut.y - posData.posIn.y;
  5339. // Process width, height, and margins
  5340. if (self.config.animation.animateResizeTargets) {
  5341. posData.posIn.width = posData.startPosData.width;
  5342. posData.posIn.height = posData.startPosData.height;
  5343. // "||" Prevents width/height change from including 0 width/height if hiding or showing
  5344. widthChange = (posData.startPosData.width || posData.finalPosData.width) - posData.interPosData.width;
  5345. posData.posIn.marginRight = posData.startPosData.marginRight - widthChange;
  5346. heightChange = (posData.startPosData.height || posData.finalPosData.height) - posData.interPosData.height;
  5347. posData.posIn.marginBottom = posData.startPosData.marginBottom - heightChange;
  5348. posData.posOut.width = posData.finalPosData.width;
  5349. posData.posOut.height = posData.finalPosData.height;
  5350. widthChange = (posData.finalPosData.width || posData.startPosData.width) - posData.interPosData.width;
  5351. posData.posOut.marginRight = posData.finalPosData.marginRight - widthChange;
  5352. heightChange = (posData.finalPosData.height || posData.startPosData.height) - posData.interPosData.height;
  5353. posData.posOut.marginBottom = posData.finalPosData.marginBottom - heightChange;
  5354. posData.tweenData.width = posData.posOut.width - posData.posIn.width;
  5355. posData.tweenData.height = posData.posOut.height - posData.posIn.height;
  5356. posData.tweenData.marginRight = posData.posOut.marginRight - posData.posIn.marginRight;
  5357. posData.tweenData.marginBottom = posData.posOut.marginBottom - posData.posIn.marginBottom;
  5358. }
  5359. // Process transforms
  5360. for (j = 0; effectName = effectNames[j]; j++) {
  5361. effect = self.effectsIn[effectName];
  5362. if (!(effect instanceof mixitup.TransformData) || !effect.value) continue;
  5363. posData.posIn[effectName].value = effect.value;
  5364. posData.posOut[effectName].value = 0;
  5365. posData.tweenData[effectName].value =
  5366. posData.posOut[effectName].value - posData.posIn[effectName].value;
  5367. posData.posIn[effectName].unit =
  5368. posData.posOut[effectName].unit =
  5369. posData.tweenData[effectName].unit =
  5370. effect.unit;
  5371. }
  5372. }
  5373. for (i = 0; target = operation.toHide[i]; i++) {
  5374. posData = operation.toHidePosData[i];
  5375. posData.posIn = new mixitup.StyleData();
  5376. posData.posOut = new mixitup.StyleData();
  5377. posData.tweenData = new mixitup.StyleData();
  5378. // Process x and y
  5379. posData.posIn.x = target.isShown ? posData.startPosData.x - posData.interPosData.x : 0;
  5380. posData.posIn.y = target.isShown ? posData.startPosData.y - posData.interPosData.y : 0;
  5381. posData.posOut.x = self.config.animation.nudge ? 0 : posData.posIn.x;
  5382. posData.posOut.y = self.config.animation.nudge ? 0 : posData.posIn.y;
  5383. posData.tweenData.x = posData.posOut.x - posData.posIn.x;
  5384. posData.tweenData.y = posData.posOut.y - posData.posIn.y;
  5385. // Process width, height, and margins
  5386. if (self.config.animation.animateResizeTargets) {
  5387. posData.posIn.width = posData.startPosData.width;
  5388. posData.posIn.height = posData.startPosData.height;
  5389. widthChange = posData.startPosData.width - posData.interPosData.width;
  5390. posData.posIn.marginRight = posData.startPosData.marginRight - widthChange;
  5391. heightChange = posData.startPosData.height - posData.interPosData.height;
  5392. posData.posIn.marginBottom = posData.startPosData.marginBottom - heightChange;
  5393. }
  5394. // Process opacity
  5395. posData.posIn.opacity = 1;
  5396. posData.posOut.opacity = self.effectsOut.opacity;
  5397. posData.tweenData.opacity = posData.posOut.opacity - posData.posIn.opacity;
  5398. // Process transforms
  5399. for (j = 0; effectName = effectNames[j]; j++) {
  5400. effect = self.effectsOut[effectName];
  5401. if (!(effect instanceof mixitup.TransformData) || !effect.value) continue;
  5402. posData.posIn[effectName].value = 0;
  5403. posData.posOut[effectName].value = effect.value;
  5404. posData.tweenData[effectName].value =
  5405. posData.posOut[effectName].value - posData.posIn[effectName].value;
  5406. posData.posIn[effectName].unit =
  5407. posData.posOut[effectName].unit =
  5408. posData.tweenData[effectName].unit =
  5409. effect.unit;
  5410. }
  5411. }
  5412. self.callActions('afterGetTweenData', arguments);
  5413. },
  5414. /**
  5415. * @private
  5416. * @instance
  5417. * @since 3.0.0
  5418. * @param {Operation} operation
  5419. * @return {void}
  5420. */
  5421. moveTargets: function(operation) {
  5422. var self = this,
  5423. target = null,
  5424. moveData = null,
  5425. posData = null,
  5426. statusChange = '',
  5427. willTransition = false,
  5428. staggerIndex = -1,
  5429. i = -1,
  5430. checkProgress = self.checkProgress.bind(self);
  5431. self.callActions('beforeMoveTargets', arguments);
  5432. // TODO: this is an extra loop in addition to the calcs
  5433. // done in getOperation, could some of this be done there?
  5434. for (i = 0; target = operation.show[i]; i++) {
  5435. moveData = new mixitup.IMoveData();
  5436. posData = operation.showPosData[i];
  5437. statusChange = target.isShown ? 'none' : 'show';
  5438. willTransition = self.willTransition(
  5439. statusChange,
  5440. operation.hasEffect,
  5441. posData.posIn,
  5442. posData.posOut
  5443. );
  5444. if (willTransition) {
  5445. // Prevent non-transitioning targets from incrementing the staggerIndex
  5446. staggerIndex++;
  5447. }
  5448. target.show();
  5449. moveData.posIn = posData.posIn;
  5450. moveData.posOut = posData.posOut;
  5451. moveData.statusChange = statusChange;
  5452. moveData.staggerIndex = staggerIndex;
  5453. moveData.operation = operation;
  5454. moveData.callback = willTransition ? checkProgress : null;
  5455. target.move(moveData);
  5456. }
  5457. for (i = 0; target = operation.toHide[i]; i++) {
  5458. posData = operation.toHidePosData[i];
  5459. moveData = new mixitup.IMoveData();
  5460. statusChange = 'hide';
  5461. willTransition = self.willTransition(statusChange, posData.posIn, posData.posOut);
  5462. moveData.posIn = posData.posIn;
  5463. moveData.posOut = posData.posOut;
  5464. moveData.statusChange = statusChange;
  5465. moveData.staggerIndex = i;
  5466. moveData.operation = operation;
  5467. moveData.callback = willTransition ? checkProgress : null;
  5468. target.move(moveData);
  5469. }
  5470. if (self.config.animation.animateResizeContainer) {
  5471. self.dom.parent.style[mixitup.features.transitionProp] =
  5472. 'height ' + self.config.animation.duration + 'ms ease, ' +
  5473. 'width ' + self.config.animation.duration + 'ms ease ';
  5474. requestAnimationFrame(function() {
  5475. if (
  5476. operation.startHeight !== operation.newHeight &&
  5477. operation.viewportDeltaY !== operation.startHeight - operation.newHeight
  5478. ) {
  5479. self.dom.parent.style.height = operation.newHeight + 'px';
  5480. }
  5481. if (
  5482. operation.startWidth !== operation.newWidth &&
  5483. operation.viewportDeltaX !== operation.startWidth - operation.newWidth
  5484. ) {
  5485. self.dom.parent.style.width = operation.newWidth + 'px';
  5486. }
  5487. });
  5488. }
  5489. if (operation.willChangeLayout) {
  5490. h.removeClass(self.dom.container, self.config.layout.ContainerClassName);
  5491. h.addClass(self.dom.container, operation.newContainerClassName);
  5492. }
  5493. self.callActions('afterMoveTargets', arguments);
  5494. },
  5495. /**
  5496. * @private
  5497. * @instance
  5498. * @return {boolean}
  5499. */
  5500. hasEffect: function() {
  5501. var self = this,
  5502. EFFECTABLES = [
  5503. 'scale',
  5504. 'translateX', 'translateY', 'translateZ',
  5505. 'rotateX', 'rotateY', 'rotateZ'
  5506. ],
  5507. effectName = '',
  5508. effect = null,
  5509. result = false,
  5510. value = -1,
  5511. i = -1;
  5512. if (self.effectsIn.opacity !== 1) {
  5513. return self.callFilters('resultHasEffect', true, arguments);
  5514. }
  5515. for (i = 0; effectName = EFFECTABLES[i]; i++) {
  5516. effect = self.effectsIn[effectName];
  5517. value = (typeof effect && effect.value !== 'undefined') ?
  5518. effect.value : effect;
  5519. if (value !== 0) {
  5520. result = true;
  5521. break;
  5522. }
  5523. }
  5524. return self.callFilters('resultHasEffect', result, arguments);
  5525. },
  5526. /**
  5527. * Determines if a target element will transition in
  5528. * some fasion and therefore requires binding of
  5529. * transitionEnd
  5530. *
  5531. * @private
  5532. * @instance
  5533. * @since 3.0.0
  5534. * @param {string} statusChange
  5535. * @param {boolean} hasEffect
  5536. * @param {StyleData} posIn
  5537. * @param {StyleData} posOut
  5538. * @return {boolean}
  5539. */
  5540. willTransition: function(statusChange, hasEffect, posIn, posOut) {
  5541. var self = this,
  5542. result = false;
  5543. if (!h.isVisible(self.dom.container)) {
  5544. // If the container is not visible, the transitionEnd
  5545. // event will not occur and MixItUp will hang
  5546. result = false;
  5547. } else if (
  5548. (statusChange !== 'none' && hasEffect) ||
  5549. posIn.x !== posOut.x ||
  5550. posIn.y !== posOut.y
  5551. ) {
  5552. // If opacity and/or translate will change
  5553. result = true;
  5554. } else if (self.config.animation.animateResizeTargets) {
  5555. // Check if width, height or margins will change
  5556. result = (
  5557. posIn.width !== posOut.width ||
  5558. posIn.height !== posOut.height ||
  5559. posIn.marginRight !== posOut.marginRight ||
  5560. posIn.marginTop !== posOut.marginTop
  5561. );
  5562. } else {
  5563. result = false;
  5564. }
  5565. return self.callFilters('resultWillTransition', result, arguments);
  5566. },
  5567. /**
  5568. * @private
  5569. * @instance
  5570. * @since 2.0.0
  5571. * @param {Operation} operation
  5572. * @return {void}
  5573. */
  5574. checkProgress: function(operation) {
  5575. var self = this;
  5576. self.targetsDone++;
  5577. if (self.targetsBound === self.targetsDone) {
  5578. self.cleanUp(operation);
  5579. }
  5580. },
  5581. /**
  5582. * @private
  5583. * @instance
  5584. * @since 2.0.0
  5585. * @param {Operation} operation
  5586. * @return {void}
  5587. */
  5588. cleanUp: function(operation) {
  5589. var self = this,
  5590. target = null,
  5591. whitespaceBefore = null,
  5592. whitespaceAfter = null,
  5593. nextInQueue = null,
  5594. i = -1;
  5595. self.callActions('beforeCleanUp', arguments);
  5596. self.targetsMoved =
  5597. self.targetsImmovable =
  5598. self.targetsBound =
  5599. self.targetsDone = 0;
  5600. for (i = 0; target = operation.show[i]; i++) {
  5601. target.cleanUp();
  5602. target.show();
  5603. }
  5604. for (i = 0; target = operation.toHide[i]; i++) {
  5605. target.cleanUp();
  5606. target.hide();
  5607. }
  5608. if (operation.willSort) {
  5609. self.printSort(false, operation);
  5610. }
  5611. // Remove any styles applied to the parent container
  5612. self.dom.parent.style[mixitup.features.transitionProp] =
  5613. self.dom.parent.style.height =
  5614. self.dom.parent.style.width =
  5615. self.dom.parent.style.overflow =
  5616. self.dom.parent.style[mixitup.features.perspectiveProp] =
  5617. self.dom.parent.style[mixitup.features.perspectiveOriginProp] = '';
  5618. if (operation.willChangeLayout) {
  5619. h.removeClass(self.dom.container, operation.startContainerClassName);
  5620. h.addClass(self.dom.container, operation.newContainerClassName);
  5621. }
  5622. if (operation.toRemove.length) {
  5623. for (i = 0; target = self.targets[i]; i++) {
  5624. if (operation.toRemove.indexOf(target) > -1) {
  5625. if (
  5626. (whitespaceBefore = target.dom.el.previousSibling) && whitespaceBefore.nodeName === '#text' &&
  5627. (whitespaceAfter = target.dom.el.nextSibling) && whitespaceAfter.nodeName === '#text'
  5628. ) {
  5629. h.removeWhitespace(whitespaceBefore);
  5630. }
  5631. if (!operation.willSort) {
  5632. // NB: Sorting will remove targets as a bi-product of `printSort()`
  5633. self.dom.parent.removeChild(target.dom.el);
  5634. }
  5635. self.targets.splice(i, 1);
  5636. target.isInDom = false;
  5637. i--;
  5638. }
  5639. }
  5640. // Since targets have been removed, the original order must be updated
  5641. self.origOrder = self.targets;
  5642. }
  5643. if (operation.willSort) {
  5644. self.targets = operation.newOrder;
  5645. }
  5646. self.state = operation.newState;
  5647. self.lastOperation = operation;
  5648. self.dom.targets = self.state.targets;
  5649. // mixEnd
  5650. mixitup.events.fire('mixEnd', self.dom.container, {
  5651. state: self.state,
  5652. instance: self
  5653. }, self.dom.document);
  5654. if (typeof self.config.callbacks.onMixEnd === 'function') {
  5655. self.config.callbacks.onMixEnd.call(self.dom.container, self.state, self);
  5656. }
  5657. if (operation.hasFailed) {
  5658. // mixFail
  5659. mixitup.events.fire('mixFail', self.dom.container, {
  5660. state: self.state,
  5661. instance: self
  5662. }, self.dom.document);
  5663. if (typeof self.config.callbacks.onMixFail === 'function') {
  5664. self.config.callbacks.onMixFail.call(self.dom.container, self.state, self);
  5665. }
  5666. h.addClass(self.dom.container, h.getClassname(self.config.classNames, 'container', self.config.classNames.modifierFailed));
  5667. }
  5668. // User-defined callback function
  5669. if (typeof self.userCallback === 'function') {
  5670. self.userCallback.call(self.dom.container, self.state, self);
  5671. }
  5672. if (typeof self.userDeferred.resolve === 'function') {
  5673. self.userDeferred.resolve(self.state);
  5674. }
  5675. self.userCallback = null;
  5676. self.userDeferred = null;
  5677. self.lastClicked = null;
  5678. self.isToggling = false;
  5679. self.isBusy = false;
  5680. if (self.queue.length) {
  5681. self.callActions('beforeReadQueueCleanUp', arguments);
  5682. nextInQueue = self.queue.shift();
  5683. // Update non-public API properties stored in queue
  5684. self.userDeferred = nextInQueue.deferred;
  5685. self.isToggling = nextInQueue.isToggling;
  5686. self.lastClicked = nextInQueue.triggerElement;
  5687. if (nextInQueue.instruction.command instanceof mixitup.CommandMultimix) {
  5688. self.multimix.apply(self, nextInQueue.args);
  5689. } else {
  5690. self.dataset.apply(self, nextInQueue.args);
  5691. }
  5692. }
  5693. self.callActions('afterCleanUp', arguments);
  5694. },
  5695. /**
  5696. * @private
  5697. * @instance
  5698. * @since 2.0.0
  5699. * @param {Array<*>} args
  5700. * @return {mixitup.UserInstruction}
  5701. */
  5702. parseMultimixArgs: function(args) {
  5703. var self = this,
  5704. instruction = new mixitup.UserInstruction(),
  5705. arg = null,
  5706. i = -1;
  5707. instruction.animate = self.config.animation.enable;
  5708. instruction.command = new mixitup.CommandMultimix();
  5709. for (i = 0; i < args.length; i++) {
  5710. arg = args[i];
  5711. if (arg === null) continue;
  5712. if (typeof arg === 'object') {
  5713. h.extend(instruction.command, arg);
  5714. } else if (typeof arg === 'boolean') {
  5715. instruction.animate = arg;
  5716. } else if (typeof arg === 'function') {
  5717. instruction.callback = arg;
  5718. }
  5719. }
  5720. // Coerce arbitrary command arguments into typed command objects
  5721. if (instruction.command.insert && !(instruction.command.insert instanceof mixitup.CommandInsert)) {
  5722. instruction.command.insert = self.parseInsertArgs([instruction.command.insert]).command;
  5723. }
  5724. if (instruction.command.remove && !(instruction.command.remove instanceof mixitup.CommandRemove)) {
  5725. instruction.command.remove = self.parseRemoveArgs([instruction.command.remove]).command;
  5726. }
  5727. if (instruction.command.filter && !(instruction.command.filter instanceof mixitup.CommandFilter)) {
  5728. instruction.command.filter = self.parseFilterArgs([instruction.command.filter]).command;
  5729. }
  5730. if (instruction.command.sort && !(instruction.command.sort instanceof mixitup.CommandSort)) {
  5731. instruction.command.sort = self.parseSortArgs([instruction.command.sort]).command;
  5732. }
  5733. if (instruction.command.changeLayout && !(instruction.command.changeLayout instanceof mixitup.CommandChangeLayout)) {
  5734. instruction.command.changeLayout = self.parseChangeLayoutArgs([instruction.command.changeLayout]).command;
  5735. }
  5736. instruction = self.callFilters('instructionParseMultimixArgs', instruction, arguments);
  5737. h.freeze(instruction);
  5738. return instruction;
  5739. },
  5740. /**
  5741. * @private
  5742. * @instance
  5743. * @since 2.0.0
  5744. * @param {Array<*>} args
  5745. * @return {mixitup.UserInstruction}
  5746. */
  5747. parseFilterArgs: function(args) {
  5748. var self = this,
  5749. instruction = new mixitup.UserInstruction(),
  5750. arg = null,
  5751. i = -1;
  5752. instruction.animate = self.config.animation.enable;
  5753. instruction.command = new mixitup.CommandFilter();
  5754. for (i = 0; i < args.length; i++) {
  5755. arg = args[i];
  5756. if (typeof arg === 'string') {
  5757. // Selector
  5758. instruction.command.selector = arg;
  5759. } else if (arg === null) {
  5760. instruction.command.collection = [];
  5761. } else if (typeof arg === 'object' && h.isElement(arg, self.dom.document)) {
  5762. // Single element
  5763. instruction.command.collection = [arg];
  5764. } else if (typeof arg === 'object' && typeof arg.length !== 'undefined') {
  5765. // Multiple elements in array, NodeList or jQuery collection
  5766. instruction.command.collection = h.arrayFromList(arg);
  5767. } else if (typeof arg === 'object') {
  5768. // Filter command
  5769. h.extend(instruction.command, arg);
  5770. } else if (typeof arg === 'boolean') {
  5771. instruction.animate = arg;
  5772. } else if (typeof arg === 'function') {
  5773. instruction.callback = arg;
  5774. }
  5775. }
  5776. if (instruction.command.selector && instruction.command.collection) {
  5777. throw new Error(mixitup.messages.errorFilterInvalidArguments());
  5778. }
  5779. instruction = self.callFilters('instructionParseFilterArgs', instruction, arguments);
  5780. h.freeze(instruction);
  5781. return instruction;
  5782. },
  5783. parseSortArgs: function(args) {
  5784. var self = this,
  5785. instruction = new mixitup.UserInstruction(),
  5786. arg = null,
  5787. sortString = '',
  5788. i = -1;
  5789. instruction.animate = self.config.animation.enable;
  5790. instruction.command = new mixitup.CommandSort();
  5791. for (i = 0; i < args.length; i++) {
  5792. arg = args[i];
  5793. if (arg === null) continue;
  5794. switch (typeof arg) {
  5795. case 'string':
  5796. // Sort string
  5797. sortString = arg;
  5798. break;
  5799. case 'object':
  5800. // Array of element references
  5801. if (arg.length) {
  5802. instruction.command.collection = h.arrayFromList(arg);
  5803. }
  5804. break;
  5805. case 'boolean':
  5806. instruction.animate = arg;
  5807. break;
  5808. case 'function':
  5809. instruction.callback = arg;
  5810. break;
  5811. }
  5812. }
  5813. if (sortString) {
  5814. instruction.command = self.parseSortString(sortString, instruction.command);
  5815. }
  5816. instruction = self.callFilters('instructionParseSortArgs', instruction, arguments);
  5817. h.freeze(instruction);
  5818. return instruction;
  5819. },
  5820. /**
  5821. * @private
  5822. * @instance
  5823. * @since 2.0.0
  5824. * @param {Array<*>} args
  5825. * @return {mixitup.UserInstruction}
  5826. */
  5827. parseInsertArgs: function(args) {
  5828. var self = this,
  5829. instruction = new mixitup.UserInstruction(),
  5830. arg = null,
  5831. i = -1;
  5832. instruction.animate = self.config.animation.enable;
  5833. instruction.command = new mixitup.CommandInsert();
  5834. for (i = 0; i < args.length; i++) {
  5835. arg = args[i];
  5836. if (arg === null) continue;
  5837. if (typeof arg === 'number') {
  5838. // Insert index
  5839. instruction.command.index = arg;
  5840. } else if (typeof arg === 'string' && ['before', 'after'].indexOf(arg) > -1) {
  5841. // 'before'/'after'
  5842. instruction.command.position = arg;
  5843. } else if (typeof arg === 'string') {
  5844. // Markup
  5845. instruction.command.collection =
  5846. h.arrayFromList(h.createElement(arg).childNodes);
  5847. } else if (typeof arg === 'object' && h.isElement(arg, self.dom.document)) {
  5848. // Single element
  5849. !instruction.command.collection.length ?
  5850. (instruction.command.collection = [arg]) :
  5851. (instruction.command.sibling = arg);
  5852. } else if (typeof arg === 'object' && arg.length) {
  5853. // Multiple elements in array or jQuery collection
  5854. !instruction.command.collection.length ?
  5855. (instruction.command.collection = arg) :
  5856. instruction.command.sibling = arg[0];
  5857. } else if (typeof arg === 'object' && arg.childNodes && arg.childNodes.length) {
  5858. // Document fragment
  5859. !instruction.command.collection.length ?
  5860. instruction.command.collection = h.arrayFromList(arg.childNodes) :
  5861. instruction.command.sibling = arg.childNodes[0];
  5862. } else if (typeof arg === 'object') {
  5863. // Insert command
  5864. h.extend(instruction.command, arg);
  5865. } else if (typeof arg === 'boolean') {
  5866. instruction.animate = arg;
  5867. } else if (typeof arg === 'function') {
  5868. instruction.callback = arg;
  5869. }
  5870. }
  5871. if (instruction.command.index && instruction.command.sibling) {
  5872. throw new Error(mixitup.messages.errorInsertInvalidArguments());
  5873. }
  5874. if (!instruction.command.collection.length && self.config.debug.showWarnings) {
  5875. console.warn(mixitup.messages.warningInsertNoElements());
  5876. }
  5877. instruction = self.callFilters('instructionParseInsertArgs', instruction, arguments);
  5878. h.freeze(instruction);
  5879. return instruction;
  5880. },
  5881. /**
  5882. * @private
  5883. * @instance
  5884. * @since 3.0.0
  5885. * @param {Array<*>} args
  5886. * @return {mixitup.UserInstruction}
  5887. */
  5888. parseRemoveArgs: function(args) {
  5889. var self = this,
  5890. instruction = new mixitup.UserInstruction(),
  5891. target = null,
  5892. arg = null,
  5893. i = -1;
  5894. instruction.animate = self.config.animation.enable;
  5895. instruction.command = new mixitup.CommandRemove();
  5896. for (i = 0; i < args.length; i++) {
  5897. arg = args[i];
  5898. if (arg === null) continue;
  5899. switch (typeof arg) {
  5900. case 'number':
  5901. if (self.targets[arg]) {
  5902. instruction.command.targets[0] = self.targets[arg];
  5903. }
  5904. break;
  5905. case 'string':
  5906. instruction.command.collection = h.arrayFromList(self.dom.parent.querySelectorAll(arg));
  5907. break;
  5908. case 'object':
  5909. if (arg && arg.length) {
  5910. instruction.command.collection = arg;
  5911. } else if (h.isElement(arg, self.dom.document)) {
  5912. instruction.command.collection = [arg];
  5913. } else {
  5914. // Remove command
  5915. h.extend(instruction.command, arg);
  5916. }
  5917. break;
  5918. case 'boolean':
  5919. instruction.animate = arg;
  5920. break;
  5921. case 'function':
  5922. instruction.callback = arg;
  5923. break;
  5924. }
  5925. }
  5926. if (instruction.command.collection.length) {
  5927. for (i = 0; target = self.targets[i]; i++) {
  5928. if (instruction.command.collection.indexOf(target.dom.el) > -1) {
  5929. instruction.command.targets.push(target);
  5930. }
  5931. }
  5932. }
  5933. if (!instruction.command.targets.length && self.config.debug.showWarnings) {
  5934. console.warn(mixitup.messages.warningRemoveNoElements());
  5935. }
  5936. h.freeze(instruction);
  5937. return instruction;
  5938. },
  5939. /**
  5940. * @private
  5941. * @instance
  5942. * @since 3.0.0
  5943. * @param {Array<*>} args
  5944. * @return {mixitup.UserInstruction}
  5945. */
  5946. parseDatasetArgs: function(args) {
  5947. var self = this,
  5948. instruction = new mixitup.UserInstruction(),
  5949. arg = null,
  5950. i = -1;
  5951. instruction.animate = self.config.animation.enable;
  5952. instruction.command = new mixitup.CommandDataset();
  5953. for (i = 0; i < args.length; i++) {
  5954. arg = args[i];
  5955. if (arg === null) continue;
  5956. switch (typeof arg) {
  5957. case 'object':
  5958. if (Array.isArray(arg) || typeof arg.length === 'number') {
  5959. instruction.command.dataset = arg;
  5960. } else {
  5961. // Change layout command
  5962. h.extend(instruction.command, arg);
  5963. }
  5964. break;
  5965. case 'boolean':
  5966. instruction.animate = arg;
  5967. break;
  5968. case 'function':
  5969. instruction.callback = arg;
  5970. break;
  5971. }
  5972. }
  5973. h.freeze(instruction);
  5974. return instruction;
  5975. },
  5976. /**
  5977. * @private
  5978. * @instance
  5979. * @since 3.0.0
  5980. * @param {Array<*>} args
  5981. * @return {mixitup.UserInstruction}
  5982. */
  5983. parseChangeLayoutArgs: function(args) {
  5984. var self = this,
  5985. instruction = new mixitup.UserInstruction(),
  5986. arg = null,
  5987. i = -1;
  5988. instruction.animate = self.config.animation.enable;
  5989. instruction.command = new mixitup.CommandChangeLayout();
  5990. for (i = 0; i < args.length; i++) {
  5991. arg = args[i];
  5992. if (arg === null) continue;
  5993. switch (typeof arg) {
  5994. case 'string':
  5995. instruction.command.containerClassName = arg;
  5996. break;
  5997. case 'object':
  5998. // Change layout command
  5999. h.extend(instruction.command, arg);
  6000. break;
  6001. case 'boolean':
  6002. instruction.animate = arg;
  6003. break;
  6004. case 'function':
  6005. instruction.callback = arg;
  6006. break;
  6007. }
  6008. }
  6009. h.freeze(instruction);
  6010. return instruction;
  6011. },
  6012. /**
  6013. * @private
  6014. * @instance
  6015. * @since 3.0.0
  6016. * @param {mixitup.QueueItem} queueItem
  6017. * @return {Promise.<mixitup.State>}
  6018. */
  6019. queueMix: function(queueItem) {
  6020. var self = this,
  6021. deferred = null,
  6022. toggleSelector = '';
  6023. self.callActions('beforeQueueMix', arguments);
  6024. deferred = h.defer(mixitup.libraries);
  6025. if (self.config.animation.queue && self.queue.length < self.config.animation.queueLimit) {
  6026. queueItem.deferred = deferred;
  6027. self.queue.push(queueItem);
  6028. // Keep controls in sync with user interactions. Mixer will catch up as it drains the queue.
  6029. if (self.config.controls.enable) {
  6030. if (self.isToggling) {
  6031. self.buildToggleArray(queueItem.instruction.command);
  6032. toggleSelector = self.getToggleSelector();
  6033. self.updateControls({
  6034. filter: {
  6035. selector: toggleSelector
  6036. }
  6037. });
  6038. } else {
  6039. self.updateControls(queueItem.instruction.command);
  6040. }
  6041. }
  6042. } else {
  6043. if (self.config.debug.showWarnings) {
  6044. console.warn(mixitup.messages.warningMultimixInstanceQueueFull());
  6045. }
  6046. deferred.resolve(self.state);
  6047. mixitup.events.fire('mixBusy', self.dom.container, {
  6048. state: self.state,
  6049. instance: self
  6050. }, self.dom.document);
  6051. if (typeof self.config.callbacks.onMixBusy === 'function') {
  6052. self.config.callbacks.onMixBusy.call(self.dom.container, self.state, self);
  6053. }
  6054. }
  6055. return self.callFilters('promiseQueueMix', deferred.promise, arguments);
  6056. },
  6057. /**
  6058. * @private
  6059. * @instance
  6060. * @since 3.0.0
  6061. * @param {Array.<object>} newDataset
  6062. * @return {Operation}
  6063. */
  6064. getDataOperation: function(newDataset) {
  6065. var self = this,
  6066. operation = new mixitup.Operation(),
  6067. startDataset = [];
  6068. operation = self.callFilters('operationUnmappedGetDataOperation', operation, arguments);
  6069. if (self.dom.targets.length && !(startDataset = (self.state.activeDataset || [])).length) {
  6070. throw new Error(mixitup.messages.errorDatasetNotSet());
  6071. }
  6072. operation.id = h.randomHex();
  6073. operation.startState = self.state;
  6074. operation.startDataset = startDataset;
  6075. operation.newDataset = newDataset.slice();
  6076. self.diffDatasets(operation);
  6077. operation.startOrder = self.targets;
  6078. operation.newOrder = operation.show;
  6079. if (self.config.animation.enable) {
  6080. self.getStartMixData(operation);
  6081. self.setInter(operation);
  6082. operation.docState = h.getDocumentState(self.dom.document);
  6083. self.getInterMixData(operation);
  6084. self.setFinal(operation);
  6085. self.getFinalMixData(operation);
  6086. self.parseEffects();
  6087. operation.hasEffect = self.hasEffect();
  6088. self.getTweenData(operation);
  6089. }
  6090. self.targets = operation.show.slice();
  6091. operation.newState = self.buildState(operation);
  6092. // NB: Targets to be removed must be included in `self.targets` for removal during clean up,
  6093. // but are added after state is built so that state is accurate
  6094. Array.prototype.push.apply(self.targets, operation.toRemove);
  6095. operation = self.callFilters('operationMappedGetDataOperation', operation, arguments);
  6096. return operation;
  6097. },
  6098. /**
  6099. * @private
  6100. * @instance
  6101. * @since 3.0.0
  6102. * @param {mixitup.Operation} operation
  6103. * @return {void}
  6104. */
  6105. diffDatasets: function(operation) {
  6106. var self = this,
  6107. persistantStartIds = [],
  6108. persistantNewIds = [],
  6109. insertedTargets = [],
  6110. data = null,
  6111. target = null,
  6112. el = null,
  6113. frag = null,
  6114. nextEl = null,
  6115. uids = {},
  6116. id = '',
  6117. i = -1;
  6118. self.callActions('beforeDiffDatasets', arguments);
  6119. for (i = 0; data = operation.newDataset[i]; i++) {
  6120. if (typeof (id = data[self.config.data.uidKey]) === 'undefined' || id.toString().length < 1) {
  6121. throw new TypeError(mixitup.messages.errorDatasetInvalidUidKey({
  6122. uidKey: self.config.data.uidKey
  6123. }));
  6124. }
  6125. if (!uids[id]) {
  6126. uids[id] = true;
  6127. } else {
  6128. throw new Error(mixitup.messages.errorDatasetDuplicateUid({
  6129. uid: id
  6130. }));
  6131. }
  6132. if ((target = self.cache[id]) instanceof mixitup.Target) {
  6133. // Already in cache
  6134. if (self.config.data.dirtyCheck && !h.deepEquals(data, target.data)) {
  6135. // change detected
  6136. el = target.render(data);
  6137. target.data = data;
  6138. if (el !== target.dom.el) {
  6139. // Update target element reference
  6140. if (target.isInDom) {
  6141. target.unbindEvents();
  6142. self.dom.parent.replaceChild(el, target.dom.el);
  6143. }
  6144. if (!target.isShown) {
  6145. el.style.display = 'none';
  6146. }
  6147. target.dom.el = el;
  6148. if (target.isInDom) {
  6149. target.bindEvents();
  6150. }
  6151. }
  6152. }
  6153. el = target.dom.el;
  6154. } else {
  6155. // New target
  6156. target = new mixitup.Target();
  6157. target.init(null, self, data);
  6158. target.hide();
  6159. }
  6160. if (!target.isInDom) {
  6161. // Adding to DOM
  6162. if (!frag) {
  6163. // Open frag
  6164. frag = self.dom.document.createDocumentFragment();
  6165. }
  6166. if (frag.lastElementChild) {
  6167. frag.appendChild(self.dom.document.createTextNode(' '));
  6168. }
  6169. frag.appendChild(target.dom.el);
  6170. target.isInDom = true;
  6171. target.unbindEvents();
  6172. target.bindEvents();
  6173. target.hide();
  6174. operation.toShow.push(target);
  6175. insertedTargets.push(target);
  6176. } else {
  6177. // Already in DOM
  6178. nextEl = target.dom.el.nextElementSibling;
  6179. persistantNewIds.push(id);
  6180. if (frag) {
  6181. // Close and insert previously opened frag
  6182. if (frag.lastElementChild) {
  6183. frag.appendChild(self.dom.document.createTextNode(' '));
  6184. }
  6185. self.insertDatasetFrag(frag, target.dom.el, insertedTargets);
  6186. frag = null;
  6187. }
  6188. }
  6189. operation.show.push(target);
  6190. }
  6191. if (frag) {
  6192. // Unclosed frag remaining
  6193. nextEl = nextEl || self.config.layout.siblingAfter;
  6194. if (nextEl) {
  6195. frag.appendChild(self.dom.document.createTextNode(' '));
  6196. }
  6197. self.insertDatasetFrag(frag, nextEl, insertedTargets);
  6198. }
  6199. for (i = 0; data = operation.startDataset[i]; i++) {
  6200. id = data[self.config.data.uidKey];
  6201. target = self.cache[id];
  6202. if (operation.show.indexOf(target) < 0) {
  6203. // Previously shown but now absent
  6204. operation.hide.push(target);
  6205. operation.toHide.push(target);
  6206. operation.toRemove.push(target);
  6207. } else {
  6208. persistantStartIds.push(id);
  6209. }
  6210. }
  6211. if (!h.isEqualArray(persistantStartIds, persistantNewIds)) {
  6212. operation.willSort = true;
  6213. }
  6214. self.callActions('afterDiffDatasets', arguments);
  6215. },
  6216. /**
  6217. * @private
  6218. * @instance
  6219. * @since 3.1.5
  6220. * @param {DocumentFragment} frag
  6221. * @param {(HTMLElement|null)} nextEl
  6222. * @param {Array.<mixitup.Target>} targets
  6223. * @return {void}
  6224. */
  6225. insertDatasetFrag: function(frag, nextEl, targets) {
  6226. var self = this;
  6227. var insertAt = nextEl ? Array.from(self.dom.parent.children).indexOf(nextEl) : self.targets.length;
  6228. self.dom.parent.insertBefore(frag, nextEl);
  6229. while (targets.length) {
  6230. self.targets.splice(insertAt, 0, targets.shift());
  6231. insertAt++;
  6232. }
  6233. },
  6234. /**
  6235. * @private
  6236. * @instance
  6237. * @since 3.0.0
  6238. * @param {mixitup.CommandSort} sortCommandA
  6239. * @param {mixitup.CommandSort} sortCommandB
  6240. * @return {boolean}
  6241. */
  6242. willSort: function(sortCommandA, sortCommandB) {
  6243. var self = this,
  6244. result = false;
  6245. if (
  6246. self.config.behavior.liveSort ||
  6247. sortCommandA.order === 'random' ||
  6248. sortCommandA.attribute !== sortCommandB.attribute ||
  6249. sortCommandA.order !== sortCommandB.order ||
  6250. sortCommandA.collection !== sortCommandB.collection ||
  6251. (sortCommandA.next === null && sortCommandB.next) ||
  6252. (sortCommandA.next && sortCommandB.next === null)
  6253. ) {
  6254. result = true;
  6255. } else if (sortCommandA.next && sortCommandB.next) {
  6256. result = self.willSort(sortCommandA.next, sortCommandB.next);
  6257. } else {
  6258. result = false;
  6259. }
  6260. return self.callFilters('resultWillSort', result, arguments);
  6261. },
  6262. /**
  6263. * A shorthand method for `.filter('all')`. Shows all targets in the container.
  6264. *
  6265. * @example
  6266. *
  6267. * .show()
  6268. *
  6269. * @example <caption>Example: Showing all targets</caption>
  6270. *
  6271. * mixer.show()
  6272. * .then(function(state) {
  6273. * console.log(state.totalShow === state.totalTargets); // true
  6274. * });
  6275. *
  6276. * @public
  6277. * @instance
  6278. * @since 3.0.0
  6279. * @return {Promise.<mixitup.State>}
  6280. */
  6281. show: function() {
  6282. var self = this;
  6283. return self.filter('all');
  6284. },
  6285. /**
  6286. * A shorthand method for `.filter('none')`. Hides all targets in the container.
  6287. *
  6288. * @example
  6289. *
  6290. * .hide()
  6291. *
  6292. * @example <caption>Example: Hiding all targets</caption>
  6293. *
  6294. * mixer.hide()
  6295. * .then(function(state) {
  6296. * console.log(state.totalShow === 0); // true
  6297. * console.log(state.totalHide === state.totalTargets); // true
  6298. * });
  6299. *
  6300. * @public
  6301. * @instance
  6302. * @since 3.0.0
  6303. * @return {Promise.<mixitup.State>}
  6304. */
  6305. hide: function() {
  6306. var self = this;
  6307. return self.filter('none');
  6308. },
  6309. /**
  6310. * Returns a boolean indicating whether or not a MixItUp operation is
  6311. * currently in progress.
  6312. *
  6313. * @example
  6314. *
  6315. * .isMixing()
  6316. *
  6317. * @example <caption>Example: Checking the status of a mixer</caption>
  6318. *
  6319. * mixer.sort('random', function() {
  6320. * console.log(mixer.isMixing()) // false
  6321. * });
  6322. *
  6323. * console.log(mixer.isMixing()) // true
  6324. *
  6325. * @public
  6326. * @instance
  6327. * @since 2.0.0
  6328. * @return {boolean}
  6329. */
  6330. isMixing: function() {
  6331. var self = this;
  6332. return self.isBusy;
  6333. },
  6334. /**
  6335. * Filters all targets in the container by a provided selector string, or the values `'all'`
  6336. * or `'none'`. Only targets matching the selector will be shown.
  6337. *
  6338. * @example
  6339. *
  6340. * .filter(selector [, animate] [, callback])
  6341. *
  6342. * @example <caption>Example 1: Filtering targets by a class selector</caption>
  6343. *
  6344. * mixer.filter('.category-a')
  6345. * .then(function(state) {
  6346. * console.log(state.totalShow === containerEl.querySelectorAll('.category-a').length); // true
  6347. * });
  6348. *
  6349. * @example <caption>Example 2: Filtering targets by an attribute selector</caption>
  6350. *
  6351. * mixer.filter('[data-category~="a"]')
  6352. * .then(function(state) {
  6353. * console.log(state.totalShow === containerEl.querySelectorAll('[data-category~="a"]').length); // true
  6354. * });
  6355. *
  6356. * @example <caption>Example 3: Filtering targets by a compound selector</caption>
  6357. *
  6358. * // Show only those targets with the classes 'category-a' AND 'category-b'
  6359. *
  6360. * mixer.filter('.category-a.category-c')
  6361. * .then(function(state) {
  6362. * console.log(state.totalShow === containerEl.querySelectorAll('.category-a.category-c').length); // true
  6363. * });
  6364. *
  6365. * @example <caption>Example 4: Filtering via an element collection</caption>
  6366. *
  6367. * var collection = Array.from(container.querySelectorAll('.mix'));
  6368. *
  6369. * console.log(collection.length); // 34
  6370. *
  6371. * // Filter the collection manually using Array.prototype.filter
  6372. *
  6373. * var filtered = collection.filter(function(target) {
  6374. * return parseInt(target.getAttribute('data-price')) > 10;
  6375. * });
  6376. *
  6377. * console.log(filtered.length); // 22
  6378. *
  6379. * // Pass the filtered collection to MixItUp
  6380. *
  6381. * mixer.filter(filtered)
  6382. * .then(function(state) {
  6383. * console.log(state.activeFilter.collection.length === 22); // true
  6384. * });
  6385. *
  6386. * @public
  6387. * @instance
  6388. * @since 2.0.0
  6389. * @param {(string|HTMLElement|Array.<HTMLElement>)} selector
  6390. * Any valid CSS selector (i.e. `'.category-a'`), or the values `'all'` or `'none'`. The filter method also accepts a reference to single target element or a collection of target elements to show.
  6391. * @param {boolean} [animate=true]
  6392. * An optional boolean dictating whether the operation should animate, or occur syncronously with no animation. `true` by default.
  6393. * @param {function} [callback=null]
  6394. * An optional callback function to be invoked after the operation has completed.
  6395. * @return {Promise.<mixitup.State>}
  6396. * A promise resolving with the current state object.
  6397. */
  6398. filter: function() {
  6399. var self = this,
  6400. instruction = self.parseFilterArgs(arguments);
  6401. return self.multimix({
  6402. filter: instruction.command
  6403. }, instruction.animate, instruction.callback);
  6404. },
  6405. /**
  6406. * Adds an additional selector to the currently active filter selector, concatenating
  6407. * as per the logic defined in `controls.toggleLogic`.
  6408. *
  6409. * @example
  6410. *
  6411. * .toggleOn(selector [, animate] [, callback])
  6412. *
  6413. * @example <caption>Example: Toggling on a filter selector</caption>
  6414. *
  6415. * console.log(mixer.getState().activeFilter.selector); // '.category-a'
  6416. *
  6417. * mixer.toggleOn('.category-b')
  6418. * .then(function(state) {
  6419. * console.log(state.activeFilter.selector); // '.category-a, .category-b'
  6420. * });
  6421. *
  6422. * @public
  6423. * @instance
  6424. * @since 3.0.0
  6425. * @param {string} selector
  6426. * Any valid CSS selector (i.e. `'.category-a'`)
  6427. * @param {boolean} [animate=true]
  6428. * An optional boolean dictating whether the operation should animate, or occur syncronously with no animation. `true` by default.
  6429. * @param {function} [callback=null]
  6430. * An optional callback function to be invoked after the operation has completed.
  6431. * @return {Promise.<mixitup.State>}
  6432. * A promise resolving with the current state object.
  6433. */
  6434. toggleOn: function() {
  6435. var self = this,
  6436. instruction = self.parseFilterArgs(arguments),
  6437. selector = instruction.command.selector,
  6438. toggleSelector = '';
  6439. self.isToggling = true;
  6440. if (self.toggleArray.indexOf(selector) < 0) {
  6441. self.toggleArray.push(selector);
  6442. }
  6443. toggleSelector = self.getToggleSelector();
  6444. return self.multimix({
  6445. filter: toggleSelector
  6446. }, instruction.animate, instruction.callback);
  6447. },
  6448. /**
  6449. * Removes a selector from the active filter selector.
  6450. *
  6451. * @example
  6452. *
  6453. * .toggleOff(selector [, animate] [, callback])
  6454. *
  6455. * @example <caption>Example: Toggling off a filter selector</caption>
  6456. *
  6457. * console.log(mixer.getState().activeFilter.selector); // '.category-a, .category-b'
  6458. *
  6459. * mixer.toggleOff('.category-b')
  6460. * .then(function(state) {
  6461. * console.log(state.activeFilter.selector); // '.category-a'
  6462. * });
  6463. *
  6464. * @public
  6465. * @instance
  6466. * @since 3.0.0
  6467. * @param {string} selector
  6468. * Any valid CSS selector (i.e. `'.category-a'`)
  6469. * @param {boolean} [animate=true]
  6470. * An optional boolean dictating whether the operation should animate, or occur syncronously with no animation. `true` by default.
  6471. * @param {function} [callback=null]
  6472. * An optional callback function to be invoked after the operation has completed.
  6473. * @return {Promise.<mixitup.State>}
  6474. * A promise resolving with the current state object.
  6475. */
  6476. toggleOff: function() {
  6477. var self = this,
  6478. instruction = self.parseFilterArgs(arguments),
  6479. selector = instruction.command.selector,
  6480. selectorIndex = self.toggleArray.indexOf(selector),
  6481. toggleSelector = '';
  6482. self.isToggling = true;
  6483. if (selectorIndex > -1) {
  6484. self.toggleArray.splice(selectorIndex, 1);
  6485. }
  6486. toggleSelector = self.getToggleSelector();
  6487. return self.multimix({
  6488. filter: toggleSelector
  6489. }, instruction.animate, instruction.callback);
  6490. },
  6491. /**
  6492. * Sorts all targets in the container according to a provided sort string.
  6493. *
  6494. * @example
  6495. *
  6496. * .sort(sortString [, animate] [, callback])
  6497. *
  6498. * @example <caption>Example 1: Sorting by the default DOM order</caption>
  6499. *
  6500. * // Reverse the default order of the targets
  6501. *
  6502. * mixer.sort('default:desc')
  6503. * .then(function(state) {
  6504. * console.log(state.activeSort.attribute === 'default'); // true
  6505. * console.log(state.activeSort.order === 'desc'); // true
  6506. * });
  6507. *
  6508. * @example <caption>Example 2: Sorting by a custom data-attribute</caption>
  6509. *
  6510. * // Sort the targets by the value of a `data-published-date` attribute
  6511. *
  6512. * mixer.sort('published-date:asc')
  6513. * .then(function(state) {
  6514. * console.log(state.activeSort.attribute === 'published-date'); // true
  6515. * console.log(state.activeSort.order === 'asc'); // true
  6516. * });
  6517. *
  6518. * @example <caption>Example 3: Sorting by multiple attributes</caption>
  6519. *
  6520. * // Sort the targets by the value of a `data-published-date` attribute, then by `data-title`
  6521. *
  6522. * mixer.sort('published-date:desc data-title:asc')
  6523. * .then(function(state) {
  6524. * console.log(state.activeSort.attribute === 'published-date'); // true
  6525. * console.log(state.activeSort.order === 'desc'); // true
  6526. *
  6527. * console.log(state.activeSort.next.attribute === 'title'); // true
  6528. * console.log(state.activeSort.next.order === 'asc'); // true
  6529. * });
  6530. *
  6531. * @example <caption>Example 4: Sorting by random</caption>
  6532. *
  6533. * mixer.sort('random')
  6534. * .then(function(state) {
  6535. * console.log(state.activeSort.order === 'random') // true
  6536. * });
  6537. *
  6538. * @example <caption>Example 5: Sorting via an element collection</caption>
  6539. *
  6540. * var collection = Array.from(container.querySelectorAll('.mix'));
  6541. *
  6542. * // Swap the position of two elements in the collection:
  6543. *
  6544. * var temp = collection[1];
  6545. *
  6546. * collection[1] = collection[0];
  6547. * collection[0] = temp;
  6548. *
  6549. * // Pass the sorted collection to MixItUp
  6550. *
  6551. * mixer.sort(collection)
  6552. * .then(function(state) {
  6553. * console.log(state.targets[0] === collection[0]); // true
  6554. * });
  6555. *
  6556. * @public
  6557. * @instance
  6558. * @since 2.0.0
  6559. * @param {(string|Array.<HTMLElement>)} sortString
  6560. * A valid sort string (e.g. `'default'`, `'published-date:asc'`, or `'random'`). The sort method also accepts an array of all target elements in a user-defined order.
  6561. * @param {boolean} [animate=true]
  6562. * An optional boolean dictating whether the operation should animate, or occur syncronously with no animation. `true` by default.
  6563. * @param {function} [callback=null]
  6564. * An optional callback function to be invoked after the operation has completed.
  6565. * @return {Promise.<mixitup.State>}
  6566. * A promise resolving with the current state object.
  6567. */
  6568. sort: function() {
  6569. var self = this,
  6570. instruction = self.parseSortArgs(arguments);
  6571. return self.multimix({
  6572. sort: instruction.command
  6573. }, instruction.animate, instruction.callback);
  6574. },
  6575. /**
  6576. * Changes the layout of the container by adding, removing or updating a
  6577. * layout-specific class name. If `animation.animateResizetargets` is
  6578. * enabled, MixItUp will attempt to gracefully animate the width, height,
  6579. * and position of targets between layout states.
  6580. *
  6581. * @example
  6582. *
  6583. * .changeLayout(containerClassName [, animate] [, callback])
  6584. *
  6585. * @example <caption>Example 1: Adding a new class name to the container</caption>
  6586. *
  6587. * mixer.changeLayout('container-list')
  6588. * .then(function(state) {
  6589. * console.log(state.activeContainerClass === 'container-list'); // true
  6590. * });
  6591. *
  6592. * @example <caption>Example 2: Removing a previously added class name from the container</caption>
  6593. *
  6594. * mixer.changeLayout('')
  6595. * .then(function(state) {
  6596. * console.log(state.activeContainerClass === ''); // true
  6597. * });
  6598. *
  6599. * @public
  6600. * @instance
  6601. * @since 2.0.0
  6602. * @param {string} containerClassName
  6603. * A layout-specific class name to add to the container.
  6604. * @param {boolean} [animate=true]
  6605. * An optional boolean dictating whether the operation should animate, or occur syncronously with no animation. `true` by default.
  6606. * @param {function} [callback=null]
  6607. * An optional callback function to be invoked after the operation has completed.
  6608. * @return {Promise.<mixitup.State>}
  6609. * A promise resolving with the current state object.
  6610. */
  6611. changeLayout: function() {
  6612. var self = this,
  6613. instruction = self.parseChangeLayoutArgs(arguments);
  6614. return self.multimix({
  6615. changeLayout: instruction.command
  6616. }, instruction.animate, instruction.callback);
  6617. },
  6618. /**
  6619. * Updates the contents and order of the container to reflect the provided dataset,
  6620. * if the dataset API is in use.
  6621. *
  6622. * The dataset API is designed for use in API-driven JavaScript applications, and
  6623. * can be used instead of DOM-based methods such as `.filter()`, `.sort()`,
  6624. * `.insert()`, etc. When used, insertion, removal, sorting and pagination can be
  6625. * achieved purely via changes to your data model, without the uglyness of having
  6626. * to interact with or query the DOM directly.
  6627. *
  6628. * @example
  6629. *
  6630. * .dataset(dataset [, animate] [, callback])
  6631. *
  6632. * @example <caption>Example 1: Rendering a dataset</caption>
  6633. *
  6634. * var myDataset = [
  6635. * {id: 1, ...},
  6636. * {id: 2, ...},
  6637. * {id: 3, ...}
  6638. * ];
  6639. *
  6640. * mixer.dataset(myDataset)
  6641. * .then(function(state) {
  6642. * console.log(state.totalShow === 3); // true
  6643. * });
  6644. *
  6645. * @example <caption>Example 2: Sorting a dataset</caption>
  6646. *
  6647. * // Create a new dataset in reverse order
  6648. *
  6649. * var newDataset = myDataset.slice().reverse();
  6650. *
  6651. * mixer.dataset(newDataset)
  6652. * .then(function(state) {
  6653. * console.log(state.activeDataset[0] === myDataset[2]); // true
  6654. * });
  6655. *
  6656. * @example <caption>Example 3: Removing an item from the dataset</caption>
  6657. *
  6658. * console.log(myDataset.length); // 3
  6659. *
  6660. * // Create a new dataset with the last item removed.
  6661. *
  6662. * var newDataset = myDataset.slice().pop();
  6663. *
  6664. * mixer.dataset(newDataset)
  6665. * .then(function(state) {
  6666. * console.log(state.totalShow === 2); // true
  6667. * });
  6668. *
  6669. * @public
  6670. * @instance
  6671. * @since 3.0.0
  6672. * @param {Array.<object>} dataset
  6673. * An array of objects, each one representing the underlying data model of a target to be rendered.
  6674. * @param {boolean} [animate=true]
  6675. * An optional boolean dictating whether the operation should animate, or occur syncronously with no animation. `true` by default.
  6676. * @param {function} [callback=null]
  6677. * An optional callback function to be invoked after the operation has completed.
  6678. * @return {Promise.<mixitup.State>}
  6679. * A promise resolving with the current state object.
  6680. */
  6681. dataset: function() {
  6682. var self = this,
  6683. instruction = self.parseDatasetArgs(arguments),
  6684. operation = null,
  6685. queueItem = null,
  6686. animate = false;
  6687. self.callActions('beforeDataset', arguments);
  6688. if (!self.isBusy) {
  6689. if (instruction.callback) self.userCallback = instruction.callback;
  6690. animate = (instruction.animate ^ self.config.animation.enable) ? instruction.animate : self.config.animation.enable;
  6691. operation = self.getDataOperation(instruction.command.dataset);
  6692. return self.goMix(animate, operation);
  6693. } else {
  6694. queueItem = new mixitup.QueueItem();
  6695. queueItem.args = arguments;
  6696. queueItem.instruction = instruction;
  6697. return self.queueMix(queueItem);
  6698. }
  6699. },
  6700. /**
  6701. * Performs simultaneous `filter`, `sort`, `insert`, `remove` and `changeLayout`
  6702. * operations as requested.
  6703. *
  6704. * @example
  6705. *
  6706. * .multimix(multimixCommand [, animate] [, callback])
  6707. *
  6708. * @example <caption>Example 1: Performing simultaneous filtering and sorting</caption>
  6709. *
  6710. * mixer.multimix({
  6711. * filter: '.category-b',
  6712. * sort: 'published-date:desc'
  6713. * })
  6714. * .then(function(state) {
  6715. * console.log(state.activeFilter.selector === '.category-b'); // true
  6716. * console.log(state.activeSort.attribute === 'published-date'); // true
  6717. * });
  6718. *
  6719. * @example <caption>Example 2: Performing simultaneous sorting, insertion, and removal</caption>
  6720. *
  6721. * console.log(mixer.getState().totalShow); // 6
  6722. *
  6723. * // NB: When inserting via `multimix()`, an object should be provided as the value
  6724. * // for the `insert` portion of the command, allowing for a collection of elements
  6725. * // and an insertion index to be specified.
  6726. *
  6727. * mixer.multimix({
  6728. * sort: 'published-date:desc', // Sort the container, including any new elements
  6729. * insert: {
  6730. * collection: [newElementReferenceA, newElementReferenceB], // Add 2 new elements at index 5
  6731. * index: 5
  6732. * },
  6733. * remove: existingElementReference // Remove 1 existing element
  6734. * })
  6735. * .then(function(state) {
  6736. * console.log(state.activeSort.attribute === 'published-date'); // true
  6737. * console.log(state.totalShow === 7); // true
  6738. * });
  6739. *
  6740. * @public
  6741. * @instance
  6742. * @since 2.0.0
  6743. * @param {object} multimixCommand
  6744. * An object containing one or more things to do
  6745. * @param {boolean} [animate=true]
  6746. * An optional boolean dictating whether the operation should animate, or occur syncronously with no animation. `true` by default.
  6747. * @param {function} [callback=null]
  6748. * An optional callback function to be invoked after the operation has completed.
  6749. * @return {Promise.<mixitup.State>}
  6750. * A promise resolving with the current state object.
  6751. */
  6752. multimix: function() {
  6753. var self = this,
  6754. operation = null,
  6755. animate = false,
  6756. queueItem = null,
  6757. instruction = self.parseMultimixArgs(arguments);
  6758. self.callActions('beforeMultimix', arguments);
  6759. if (!self.isBusy) {
  6760. operation = self.getOperation(instruction.command);
  6761. if (self.config.controls.enable) {
  6762. // Update controls for API calls
  6763. if (instruction.command.filter && !self.isToggling) {
  6764. // As we are not toggling, reset the toggle array
  6765. // so new filter overrides existing toggles
  6766. self.toggleArray.length = 0;
  6767. self.buildToggleArray(operation.command);
  6768. }
  6769. if (self.queue.length < 1) {
  6770. self.updateControls(operation.command);
  6771. }
  6772. }
  6773. if (instruction.callback) self.userCallback = instruction.callback;
  6774. // Always allow the instruction to override the instance setting
  6775. animate = (instruction.animate ^ self.config.animation.enable) ?
  6776. instruction.animate :
  6777. self.config.animation.enable;
  6778. self.callFilters('operationMultimix', operation, arguments);
  6779. return self.goMix(animate, operation);
  6780. } else {
  6781. queueItem = new mixitup.QueueItem();
  6782. queueItem.args = arguments;
  6783. queueItem.instruction = instruction;
  6784. queueItem.triggerElement = self.lastClicked;
  6785. queueItem.isToggling = self.isToggling;
  6786. return self.queueMix(queueItem);
  6787. }
  6788. },
  6789. /**
  6790. * @private
  6791. * @instance
  6792. * @since 3.0.0
  6793. * @param {object} multimixCommand
  6794. * @param {boolean} [isPreFetch]
  6795. * An optional boolean indicating that the operation is being pre-fetched for execution at a later time.
  6796. * @return {Operation|null}
  6797. */
  6798. getOperation: function(multimixCommand) {
  6799. var self = this,
  6800. sortCommand = multimixCommand.sort,
  6801. filterCommand = multimixCommand.filter,
  6802. changeLayoutCommand = multimixCommand.changeLayout,
  6803. removeCommand = multimixCommand.remove,
  6804. insertCommand = multimixCommand.insert,
  6805. operation = new mixitup.Operation();
  6806. operation = self.callFilters('operationUnmappedGetOperation', operation, arguments);
  6807. operation.id = h.randomHex();
  6808. operation.command = multimixCommand;
  6809. operation.startState = self.state;
  6810. operation.triggerElement = self.lastClicked;
  6811. if (self.isBusy) {
  6812. if (self.config.debug.showWarnings) {
  6813. console.warn(mixitup.messages.warningGetOperationInstanceBusy());
  6814. }
  6815. return null;
  6816. }
  6817. if (insertCommand) {
  6818. self.insertTargets(insertCommand, operation);
  6819. }
  6820. if (removeCommand) {
  6821. operation.toRemove = removeCommand.targets;
  6822. }
  6823. operation.startSort = operation.newSort = operation.startState.activeSort;
  6824. operation.startOrder = operation.newOrder = self.targets;
  6825. if (sortCommand) {
  6826. operation.startSort = operation.startState.activeSort;
  6827. operation.newSort = sortCommand;
  6828. operation.willSort = self.willSort(sortCommand, operation.startState.activeSort);
  6829. if (operation.willSort) {
  6830. self.sortOperation(operation);
  6831. }
  6832. }
  6833. operation.startFilter = operation.startState.activeFilter;
  6834. if (filterCommand) {
  6835. operation.newFilter = filterCommand;
  6836. } else {
  6837. operation.newFilter = h.extend(new mixitup.CommandFilter(), operation.startFilter);
  6838. }
  6839. if (operation.newFilter.selector === 'all') {
  6840. operation.newFilter.selector = self.config.selectors.target;
  6841. } else if (operation.newFilter.selector === 'none') {
  6842. operation.newFilter.selector = '';
  6843. }
  6844. self.filterOperation(operation);
  6845. operation.startContainerClassName = operation.startState.activeContainerClassName;
  6846. if (changeLayoutCommand) {
  6847. operation.newContainerClassName = changeLayoutCommand.containerClassName;
  6848. if (operation.newContainerClassName !== operation.startContainerClassName) {
  6849. operation.willChangeLayout = true;
  6850. }
  6851. } else {
  6852. operation.newContainerClassName = operation.startContainerClassName;
  6853. }
  6854. if (self.config.animation.enable) {
  6855. // Populate the operation's position data
  6856. self.getStartMixData(operation);
  6857. self.setInter(operation);
  6858. operation.docState = h.getDocumentState(self.dom.document);
  6859. self.getInterMixData(operation);
  6860. self.setFinal(operation);
  6861. self.getFinalMixData(operation);
  6862. self.parseEffects();
  6863. operation.hasEffect = self.hasEffect();
  6864. self.getTweenData(operation);
  6865. }
  6866. if (operation.willSort) {
  6867. self.targets = operation.newOrder;
  6868. }
  6869. operation.newState = self.buildState(operation);
  6870. return self.callFilters('operationMappedGetOperation', operation, arguments);
  6871. },
  6872. /**
  6873. * Renders a previously created operation at a specific point in its path, as
  6874. * determined by a multiplier between 0 and 1.
  6875. *
  6876. * @example
  6877. * .tween(operation, multiplier)
  6878. *
  6879. * @private
  6880. * @instance
  6881. * @since 3.0.0
  6882. * @param {mixitup.Operation} operation
  6883. * An operation object created via the `getOperation` method
  6884. *
  6885. * @param {Float} multiplier
  6886. * Any number between 0 and 1 representing the percentage complete of the operation
  6887. * @return {void}
  6888. */
  6889. tween: function(operation, multiplier) {
  6890. var target = null,
  6891. posData = null,
  6892. toHideIndex = -1,
  6893. i = -1;
  6894. multiplier = Math.min(multiplier, 1);
  6895. multiplier = Math.max(multiplier, 0);
  6896. for (i = 0; target = operation.show[i]; i++) {
  6897. posData = operation.showPosData[i];
  6898. target.applyTween(posData, multiplier);
  6899. }
  6900. for (i = 0; target = operation.hide[i]; i++) {
  6901. if (target.isShown) {
  6902. target.hide();
  6903. }
  6904. if ((toHideIndex = operation.toHide.indexOf(target)) > -1) {
  6905. posData = operation.toHidePosData[toHideIndex];
  6906. if (!target.isShown) {
  6907. target.show();
  6908. }
  6909. target.applyTween(posData, multiplier);
  6910. }
  6911. }
  6912. },
  6913. /**
  6914. * Inserts one or more new target elements into the container at a specified
  6915. * index.
  6916. *
  6917. * To be indexed as targets, new elements must match the `selectors.target`
  6918. * selector (`'.mix'` by default).
  6919. *
  6920. * @example
  6921. *
  6922. * .insert(newElements [, index] [, animate], [, callback])
  6923. *
  6924. * @example <caption>Example 1: Inserting a single element via reference</caption>
  6925. *
  6926. * console.log(mixer.getState().totalShow); // 0
  6927. *
  6928. * // Create a new element
  6929. *
  6930. * var newElement = document.createElement('div');
  6931. * newElement.classList.add('mix');
  6932. *
  6933. * mixer.insert(newElement)
  6934. * .then(function(state) {
  6935. * console.log(state.totalShow === 1); // true
  6936. * });
  6937. *
  6938. * @example <caption>Example 2: Inserting a single element via HTML string</caption>
  6939. *
  6940. * console.log(mixer.getState().totalShow); // 1
  6941. *
  6942. * // Create a new element via reference
  6943. *
  6944. * var newElementHtml = '&lt;div class="mix"&gt;&lt;/div&gt;';
  6945. *
  6946. * // Create and insert the new element at index 1
  6947. *
  6948. * mixer.insert(newElementHtml, 1)
  6949. * .then(function(state) {
  6950. * console.log(state.totalShow === 2); // true
  6951. * console.log(state.show[1].outerHTML === newElementHtml); // true
  6952. * });
  6953. *
  6954. * @example <caption>Example 3: Inserting multiple elements via reference</caption>
  6955. *
  6956. * console.log(mixer.getState().totalShow); // 2
  6957. *
  6958. * // Create an array of new elements to insert.
  6959. *
  6960. * var newElement1 = document.createElement('div');
  6961. * var newElement2 = document.createElement('div');
  6962. *
  6963. * newElement1.classList.add('mix');
  6964. * newElement2.classList.add('mix');
  6965. *
  6966. * var newElementsCollection = [newElement1, newElement2];
  6967. *
  6968. * // Insert the new elements starting at index 1
  6969. *
  6970. * mixer.insert(newElementsCollection, 1)
  6971. * .then(function(state) {
  6972. * console.log(state.totalShow === 4); // true
  6973. * console.log(state.show[1] === newElement1); // true
  6974. * console.log(state.show[2] === newElement2); // true
  6975. * });
  6976. *
  6977. * @example <caption>Example 4: Inserting a jQuery collection object containing one or more elements</caption>
  6978. *
  6979. * console.log(mixer.getState().totalShow); // 4
  6980. *
  6981. * var $newElement = $('&lt;div class="mix"&gt;&lt;/div&gt;');
  6982. *
  6983. * // Insert the new elements starting at index 3
  6984. *
  6985. * mixer.insert($newElement, 3)
  6986. * .then(function(state) {
  6987. * console.log(state.totalShow === 5); // true
  6988. * console.log(state.show[3] === $newElement[0]); // true
  6989. * });
  6990. *
  6991. * @public
  6992. * @instance
  6993. * @since 2.0.0
  6994. * @param {(HTMLElement|Array.<HTMLElement>|string)} newElements
  6995. * A reference to a single element to insert, an array-like collection of elements, or an HTML string representing a single element.
  6996. * @param {number} index=0
  6997. * The index at which to insert the new element(s). `0` by default.
  6998. * @param {boolean} [animate=true]
  6999. * An optional boolean dictating whether the operation should animate, or occur syncronously with no animation. `true` by default.
  7000. * @param {function} [callback=null]
  7001. * An optional callback function to be invoked after the operation has completed.
  7002. * @return {Promise.<mixitup.State>}
  7003. * A promise resolving with the current state object.
  7004. */
  7005. insert: function() {
  7006. var self = this,
  7007. args = self.parseInsertArgs(arguments);
  7008. return self.multimix({
  7009. insert: args.command
  7010. }, args.animate, args.callback);
  7011. },
  7012. /**
  7013. * Inserts one or more new elements before a provided reference element.
  7014. *
  7015. * @example
  7016. *
  7017. * .insertBefore(newElements, referenceElement [, animate] [, callback])
  7018. *
  7019. * @example <caption>Example: Inserting a new element before a reference element</caption>
  7020. *
  7021. * // An existing reference element is chosen at index 2
  7022. *
  7023. * var referenceElement = mixer.getState().show[2];
  7024. *
  7025. * // Create a new element
  7026. *
  7027. * var newElement = document.createElement('div');
  7028. * newElement.classList.add('mix');
  7029. *
  7030. * mixer.insertBefore(newElement, referenceElement)
  7031. * .then(function(state) {
  7032. * // The new element is inserted into the container at index 2, before the reference element
  7033. *
  7034. * console.log(state.show[2] === newElement); // true
  7035. *
  7036. * // The reference element is now at index 3
  7037. *
  7038. * console.log(state.show[3] === referenceElement); // true
  7039. * });
  7040. *
  7041. * @public
  7042. * @instance
  7043. * @since 3.0.0
  7044. * @param {(HTMLElement|Array.<HTMLElement>|string)} newElements
  7045. * A reference to a single element to insert, an array-like collection of elements, or an HTML string representing a single element.
  7046. * @param {HTMLElement} referenceElement
  7047. * A reference to an existing element in the container to insert new elements before.
  7048. *@param {boolean} [animate=true]
  7049. * An optional boolean dictating whether the operation should animate, or occur syncronously with no animation. `true` by default.
  7050. * @param {function} [callback=null]
  7051. * An optional callback function to be invoked after the operation has completed.
  7052. * @return {Promise.<mixitup.State>}
  7053. * A promise resolving with the current state object.
  7054. */
  7055. insertBefore: function() {
  7056. var self = this,
  7057. args = self.parseInsertArgs(arguments);
  7058. return self.insert(args.command.collection, 'before', args.command.sibling, args.animate, args.callback);
  7059. },
  7060. /**
  7061. * Inserts one or more new elements after a provided reference element.
  7062. *
  7063. * @example
  7064. *
  7065. * .insertAfter(newElements, referenceElement [, animate] [, callback])
  7066. *
  7067. * @example <caption>Example: Inserting a new element after a reference element</caption>
  7068. *
  7069. * // An existing reference element is chosen at index 2
  7070. *
  7071. * var referenceElement = mixer.getState().show[2];
  7072. *
  7073. * // Create a new element
  7074. *
  7075. * var newElement = document.createElement('div');
  7076. * newElement.classList.add('mix');
  7077. *
  7078. * mixer.insertAfter(newElement, referenceElement)
  7079. * .then(function(state) {
  7080. * // The new element is inserted into the container at index 3, after the reference element
  7081. *
  7082. * console.log(state.show[3] === newElement); // true
  7083. * });
  7084. *
  7085. * @public
  7086. * @instance
  7087. * @since 3.0.0
  7088. * @param {(HTMLElement|Array.<HTMLElement>|string)} newElements
  7089. * A reference to a single element to insert, an array-like collection of elements, or an HTML string representing a single element.
  7090. * @param {HTMLElement} referenceElement
  7091. * A reference to an existing element in the container to insert new elements after.
  7092. * @param {boolean} [animate=true]
  7093. * An optional boolean dictating whether the operation should animate, or occur syncronously with no animation. `true` by default.
  7094. * @param {function} [callback=null]
  7095. * An optional callback function to be invoked after the operation has completed.
  7096. * @return {Promise.<mixitup.State>}
  7097. * A promise resolving with the current state object.
  7098. */
  7099. insertAfter: function() {
  7100. var self = this,
  7101. args = self.parseInsertArgs(arguments);
  7102. return self.insert(args.command.collection, 'after', args.command.sibling, args.animate, args.callback);
  7103. },
  7104. /**
  7105. * Inserts one or more new elements into the container before all existing targets.
  7106. *
  7107. * @example
  7108. *
  7109. * .prepend(newElements [,animate] [,callback])
  7110. *
  7111. * @example <caption>Example: Prepending a new element</caption>
  7112. *
  7113. * // Create a new element
  7114. *
  7115. * var newElement = document.createElement('div');
  7116. * newElement.classList.add('mix');
  7117. *
  7118. * // Insert the element into the container
  7119. *
  7120. * mixer.prepend(newElement)
  7121. * .then(function(state) {
  7122. * console.log(state.show[0] === newElement); // true
  7123. * });
  7124. *
  7125. * @public
  7126. * @instance
  7127. * @since 3.0.0
  7128. * @param {(HTMLElement|Array.<HTMLElement>|string)} newElements
  7129. * A reference to a single element to insert, an array-like collection of elements, or an HTML string representing a single element.
  7130. * @param {boolean} [animate=true]
  7131. * An optional boolean dictating whether the operation should animate, or occur syncronously with no animation. `true` by default.
  7132. * @param {function} [callback=null]
  7133. * An optional callback function to be invoked after the operation has completed.
  7134. * @return {Promise.<mixitup.State>}
  7135. * A promise resolving with the current state object.
  7136. */
  7137. prepend: function() {
  7138. var self = this,
  7139. args = self.parseInsertArgs(arguments);
  7140. return self.insert(0, args.command.collection, args.animate, args.callback);
  7141. },
  7142. /**
  7143. * Inserts one or more new elements into the container after all existing targets.
  7144. *
  7145. * @example
  7146. *
  7147. * .append(newElements [,animate] [,callback])
  7148. *
  7149. * @example <caption>Example: Appending a new element</caption>
  7150. *
  7151. * // Create a new element
  7152. *
  7153. * var newElement = document.createElement('div');
  7154. * newElement.classList.add('mix');
  7155. *
  7156. * // Insert the element into the container
  7157. *
  7158. * mixer.append(newElement)
  7159. * .then(function(state) {
  7160. * console.log(state.show[state.show.length - 1] === newElement); // true
  7161. * });
  7162. *
  7163. * @public
  7164. * @instance
  7165. * @since 3.0.0
  7166. * @param {(HTMLElement|Array.<HTMLElement>|string)} newElements
  7167. * A reference to a single element to insert, an array-like collection of elements, or an HTML string representing a single element.
  7168. * @param {boolean} [animate=true]
  7169. * An optional boolean dictating whether the operation should animate, or occur syncronously with no animation. `true` by default.
  7170. * @param {function} [callback=null]
  7171. * An optional callback function to be invoked after the operation has completed.
  7172. * @return {Promise.<mixitup.State>}
  7173. * A promise resolving with the current state object.
  7174. */
  7175. append: function() {
  7176. var self = this,
  7177. args = self.parseInsertArgs(arguments);
  7178. return self.insert(self.state.totalTargets, args.command.collection, args.animate, args.callback);
  7179. },
  7180. /**
  7181. * Removes one or more existing target elements from the container.
  7182. *
  7183. * @example
  7184. *
  7185. * .remove(elements [, animate] [, callback])
  7186. *
  7187. * @example <caption>Example 1: Removing an element by reference</caption>
  7188. *
  7189. * var elementToRemove = containerEl.firstElementChild;
  7190. *
  7191. * mixer.remove(elementToRemove)
  7192. * .then(function(state) {
  7193. * console.log(state.targets.indexOf(elementToRemove) === -1); // true
  7194. * });
  7195. *
  7196. * @example <caption>Example 2: Removing a collection of elements by reference</caption>
  7197. *
  7198. * var elementsToRemove = containerEl.querySelectorAll('.category-a');
  7199. *
  7200. * console.log(elementsToRemove.length) // 3
  7201. *
  7202. * mixer.remove(elementsToRemove)
  7203. * .then(function() {
  7204. * console.log(containerEl.querySelectorAll('.category-a').length); // 0
  7205. * });
  7206. *
  7207. * @example <caption>Example 3: Removing one or more elements by selector</caption>
  7208. *
  7209. * mixer.remove('.category-a')
  7210. * .then(function() {
  7211. * console.log(containerEl.querySelectorAll('.category-a').length); // 0
  7212. * });
  7213. *
  7214. * @example <caption>Example 4: Removing an element by index</caption>
  7215. *
  7216. * console.log(mixer.getState.totalShow); // 4
  7217. *
  7218. * // Remove the element at index 3
  7219. *
  7220. * mixer.remove(3)
  7221. * .then(function(state) {
  7222. * console.log(state.totalShow); // 3
  7223. * console.log(state.show[3]); // undefined
  7224. * });
  7225. *
  7226. *
  7227. * @public
  7228. * @instance
  7229. * @since 3.0.0
  7230. * @param {(HTMLElement|Array.<HTMLElement>|string|number)} elements
  7231. * A reference to a single element to remove, an array-like collection of elements, a selector string, or the index of an element to remove.
  7232. * @param {boolean} [animate=true]
  7233. * An optional boolean dictating whether the operation should animate, or occur syncronously with no animation. `true` by default.
  7234. * @param {function} [callback=null]
  7235. * An optional callback function to be invoked after the operation has completed.
  7236. * @return {Promise.<mixitup.State>}
  7237. * A promise resolving with the current state object.
  7238. */
  7239. remove: function() {
  7240. var self = this,
  7241. args = self.parseRemoveArgs(arguments);
  7242. return self.multimix({
  7243. remove: args.command
  7244. }, args.animate, args.callback);
  7245. },
  7246. /**
  7247. * Retrieves the the value of any property or sub-object within the current
  7248. * mixitup configuration, or the whole configuration object.
  7249. *
  7250. * @example
  7251. *
  7252. * .getConfig([stringKey])
  7253. *
  7254. * @example <caption>Example 1: retrieve the entire configuration object</caption>
  7255. *
  7256. * var config = mixer.getConfig(); // Config { ... }
  7257. *
  7258. * @example <caption>Example 2: retrieve a named sub-object of configuration object</caption>
  7259. *
  7260. * var animation = mixer.getConfig('animation'); // ConfigAnimation { ... }
  7261. *
  7262. * @example <caption>Example 3: retrieve a value of configuration object via a dot-notation string key</caption>
  7263. *
  7264. * var effects = mixer.getConfig('animation.effects'); // 'fade scale'
  7265. *
  7266. * @public
  7267. * @instance
  7268. * @since 2.0.0
  7269. * @param {string} [stringKey] A "dot-notation" string key
  7270. * @return {*}
  7271. */
  7272. getConfig: function(stringKey) {
  7273. var self = this,
  7274. value = null;
  7275. if (!stringKey) {
  7276. value = self.config;
  7277. } else {
  7278. value = h.getProperty(self.config, stringKey);
  7279. }
  7280. return self.callFilters('valueGetConfig', value, arguments);
  7281. },
  7282. /**
  7283. * Updates the configuration of the mixer, after it has been instantiated.
  7284. *
  7285. * See the Configuration Object documentation for a full list of avilable
  7286. * configuration options.
  7287. *
  7288. * @example
  7289. *
  7290. * .configure(config)
  7291. *
  7292. * @example <caption>Example 1: Updating animation options</caption>
  7293. *
  7294. * mixer.configure({
  7295. * animation: {
  7296. * effects: 'fade translateX(-100%)',
  7297. * duration: 300
  7298. * }
  7299. * });
  7300. *
  7301. * @example <caption>Example 2: Removing a callback after it has been set</caption>
  7302. *
  7303. * var mixer;
  7304. *
  7305. * function handleMixEndOnce() {
  7306. * // Do something ..
  7307. *
  7308. * // Then nullify the callback
  7309. *
  7310. * mixer.configure({
  7311. * callbacks: {
  7312. * onMixEnd: null
  7313. * }
  7314. * });
  7315. * };
  7316. *
  7317. * // Instantiate a mixer with a callback defined
  7318. *
  7319. * mixer = mixitup(containerEl, {
  7320. * callbacks: {
  7321. * onMixEnd: handleMixEndOnce
  7322. * }
  7323. * });
  7324. *
  7325. * @public
  7326. * @instance
  7327. * @since 3.0.0
  7328. * @param {object} config
  7329. * An object containing one of more configuration options.
  7330. * @return {void}
  7331. */
  7332. configure: function(config) {
  7333. var self = this;
  7334. self.callActions('beforeConfigure', arguments);
  7335. h.extend(self.config, config, true, true);
  7336. self.callActions('afterConfigure', arguments);
  7337. },
  7338. /**
  7339. * Returns an object containing information about the current state of the
  7340. * mixer. See the State Object documentation for more information.
  7341. *
  7342. * NB: State objects are immutable and should therefore be regenerated
  7343. * after any operation.
  7344. *
  7345. * @example
  7346. *
  7347. * .getState();
  7348. *
  7349. * @example <caption>Example: Retrieving a state object</caption>
  7350. *
  7351. * var state = mixer.getState();
  7352. *
  7353. * console.log(state.totalShow + 'targets are currently shown');
  7354. *
  7355. * @public
  7356. * @instance
  7357. * @since 2.0.0
  7358. * @return {mixitup.State} An object reflecting the current state of the mixer.
  7359. */
  7360. getState: function() {
  7361. var self = this,
  7362. state = null;
  7363. state = new mixitup.State();
  7364. h.extend(state, self.state);
  7365. h.freeze(state);
  7366. return self.callFilters('stateGetState', state, arguments);
  7367. },
  7368. /**
  7369. * Forces the re-indexing all targets within the container.
  7370. *
  7371. * This should only be used if some other piece of code in your application
  7372. * has manipulated the contents of your container, which should be avoided.
  7373. *
  7374. * If you need to add or remove target elements from the container, use
  7375. * the built-in `.insert()` or `.remove()` methods, and MixItUp will keep
  7376. * itself up to date.
  7377. *
  7378. * @example
  7379. *
  7380. * .forceRefresh()
  7381. *
  7382. * @example <caption>Example: Force refreshing the mixer after external DOM manipulation</caption>
  7383. *
  7384. * console.log(mixer.getState().totalShow); // 3
  7385. *
  7386. * // An element is removed from the container via some external DOM manipulation code:
  7387. *
  7388. * containerEl.removeChild(containerEl.firstElementChild);
  7389. *
  7390. * // The mixer does not know that the number of targets has changed:
  7391. *
  7392. * console.log(mixer.getState().totalShow); // 3
  7393. *
  7394. * mixer.forceRefresh();
  7395. *
  7396. * // After forceRefresh, the mixer is in sync again:
  7397. *
  7398. * console.log(mixer.getState().totalShow); // 2
  7399. *
  7400. * @public
  7401. * @instance
  7402. * @since 2.1.2
  7403. * @return {void}
  7404. */
  7405. forceRefresh: function() {
  7406. var self = this;
  7407. self.indexTargets();
  7408. },
  7409. /**
  7410. * Forces the re-rendering of all targets when using the Dataset API.
  7411. *
  7412. * By default, targets are only re-rendered when `data.dirtyCheck` is
  7413. * enabled, and an item's data has changed when `dataset()` is called.
  7414. *
  7415. * The `forceRender()` method allows for the re-rendering of all targets
  7416. * in response to some arbitrary event, such as the changing of the target
  7417. * render function.
  7418. *
  7419. * Targets are rendered against their existing data.
  7420. *
  7421. * @example
  7422. *
  7423. * .forceRender()
  7424. *
  7425. * @example <caption>Example: Force render targets after changing the target render function</caption>
  7426. *
  7427. * console.log(container.innerHTML); // ... &lt;span class="mix"&gt;Foo&lt;/span&gt; ...
  7428. *
  7429. * mixer.configure({
  7430. * render: {
  7431. * target: (item) => `&lt;a href="/${item.slug}/" class="mix"&gt;${item.title}&lt;/a&gt;`
  7432. * }
  7433. * });
  7434. *
  7435. * mixer.forceRender();
  7436. *
  7437. * console.log(container.innerHTML); // ... &lt;a href="/foo/" class="mix"&gt;Foo&lt;/a&gt; ...
  7438. *
  7439. * @public
  7440. * @instance
  7441. * @since 3.2.1
  7442. * @return {void}
  7443. */
  7444. forceRender: function() {
  7445. var self = this,
  7446. target = null,
  7447. el = null,
  7448. id = '';
  7449. for (id in self.cache) {
  7450. target = self.cache[id];
  7451. el = target.render(target.data);
  7452. if (el !== target.dom.el) {
  7453. // Update target element reference
  7454. if (target.isInDom) {
  7455. target.unbindEvents();
  7456. self.dom.parent.replaceChild(el, target.dom.el);
  7457. }
  7458. if (!target.isShown) {
  7459. el.style.display = 'none';
  7460. }
  7461. target.dom.el = el;
  7462. if (target.isInDom) {
  7463. target.bindEvents();
  7464. }
  7465. }
  7466. }
  7467. self.state = self.buildState(self.lastOperation);
  7468. },
  7469. /**
  7470. * Removes mixitup functionality from the container, unbinds all control
  7471. * event handlers, and deletes the mixer instance from MixItUp's internal
  7472. * cache.
  7473. *
  7474. * This should be performed whenever a mixer's container is removed from
  7475. * the DOM, such as during a page change in a single page application,
  7476. * or React's `componentWillUnmount()`.
  7477. *
  7478. * @example
  7479. *
  7480. * .destroy([cleanUp])
  7481. *
  7482. * @example <caption>Example: Destroying the mixer before removing its container element</caption>
  7483. *
  7484. * mixer.destroy();
  7485. *
  7486. * containerEl.parentElement.removeChild(containerEl);
  7487. *
  7488. * @public
  7489. * @instance
  7490. * @since 2.0.0
  7491. * @param {boolean} [cleanUp=false]
  7492. * An optional boolean dictating whether or not to clean up any inline `display: none;` styling applied to hidden targets.
  7493. * @return {void}
  7494. */
  7495. destroy: function(cleanUp) {
  7496. var self = this,
  7497. control = null,
  7498. target = null,
  7499. i = 0;
  7500. self.callActions('beforeDestroy', arguments);
  7501. for (i = 0; control = self.controls[i]; i++) {
  7502. control.removeBinding(self);
  7503. }
  7504. for (i = 0; target = self.targets[i]; i++) {
  7505. if (cleanUp) {
  7506. target.show();
  7507. }
  7508. target.unbindEvents();
  7509. }
  7510. if (self.dom.container.id.match(/^MixItUp/)) {
  7511. self.dom.container.removeAttribute('id');
  7512. }
  7513. delete mixitup.instances[self.id];
  7514. self.callActions('afterDestroy', arguments);
  7515. }
  7516. });
  7517. /**
  7518. * @constructor
  7519. * @memberof mixitup
  7520. * @private
  7521. * @since 3.0.0
  7522. */
  7523. mixitup.IMoveData = function() {
  7524. mixitup.Base.call(this);
  7525. this.callActions('beforeConstruct');
  7526. this.posIn = null;
  7527. this.posOut = null;
  7528. this.operation = null;
  7529. this.callback = null;
  7530. this.statusChange = '';
  7531. this.duration = -1;
  7532. this.staggerIndex = -1;
  7533. this.callActions('afterConstruct');
  7534. h.seal(this);
  7535. };
  7536. mixitup.BaseStatic.call(mixitup.IMoveData);
  7537. mixitup.IMoveData.prototype = Object.create(mixitup.Base.prototype);
  7538. mixitup.IMoveData.prototype.constructor = mixitup.IMoveData;
  7539. /**
  7540. * @constructor
  7541. * @memberof mixitup
  7542. * @private
  7543. * @since 3.0.0
  7544. */
  7545. mixitup.TargetDom = function() {
  7546. mixitup.Base.call(this);
  7547. this.callActions('beforeConstruct');
  7548. this.el = null;
  7549. this.callActions('afterConstruct');
  7550. h.seal(this);
  7551. };
  7552. mixitup.BaseStatic.call(mixitup.TargetDom);
  7553. mixitup.TargetDom.prototype = Object.create(mixitup.Base.prototype);
  7554. mixitup.TargetDom.prototype.constructor = mixitup.TargetDom;
  7555. /**
  7556. * @constructor
  7557. * @namespace
  7558. * @memberof mixitup
  7559. * @private
  7560. * @since 3.0.0
  7561. */
  7562. mixitup.Target = function() {
  7563. mixitup.Base.call(this);
  7564. this.callActions('beforeConstruct');
  7565. this.id = '';
  7566. this.sortString = '';
  7567. this.mixer = null;
  7568. this.callback = null;
  7569. this.isShown = false;
  7570. this.isBound = false;
  7571. this.isExcluded = false;
  7572. this.isInDom = false;
  7573. this.handler = null;
  7574. this.operation = null;
  7575. this.data = null;
  7576. this.dom = new mixitup.TargetDom();
  7577. this.callActions('afterConstruct');
  7578. h.seal(this);
  7579. };
  7580. mixitup.BaseStatic.call(mixitup.Target);
  7581. mixitup.Target.prototype = Object.create(mixitup.Base.prototype);
  7582. h.extend(mixitup.Target.prototype, {
  7583. constructor: mixitup.Target,
  7584. /**
  7585. * Initialises a newly instantiated Target.
  7586. *
  7587. * @private
  7588. * @instance
  7589. * @since 3.0.0
  7590. * @param {(Element|null)} el
  7591. * @param {object} mixer
  7592. * @param {object} [data]
  7593. * @return {void}
  7594. */
  7595. init: function(el, mixer, data) {
  7596. var self = this,
  7597. id = '';
  7598. self.callActions('beforeInit', arguments);
  7599. self.mixer = mixer;
  7600. if (!el) {
  7601. // If no element is provided, render it
  7602. el = self.render(data);
  7603. }
  7604. self.cacheDom(el);
  7605. self.bindEvents();
  7606. if (self.dom.el.style.display !== 'none') {
  7607. self.isShown = true;
  7608. }
  7609. if (data && mixer.config.data.uidKey) {
  7610. if (typeof (id = data[mixer.config.data.uidKey]) === 'undefined' || id.toString().length < 1) {
  7611. throw new TypeError(mixitup.messages.errorDatasetInvalidUidKey({
  7612. uidKey: mixer.config.data.uidKey
  7613. }));
  7614. }
  7615. self.id = id;
  7616. self.data = data;
  7617. mixer.cache[id] = self;
  7618. }
  7619. self.callActions('afterInit', arguments);
  7620. },
  7621. /**
  7622. * Renders the target element using a user-defined renderer function.
  7623. *
  7624. * @private
  7625. * @instance
  7626. * @since 3.1.4
  7627. * @param {object} data
  7628. * @return {void}
  7629. */
  7630. render: function(data) {
  7631. var self = this,
  7632. render = null,
  7633. el = null,
  7634. temp = null,
  7635. output = '';
  7636. self.callActions('beforeRender', arguments);
  7637. render = self.callFilters('renderRender', self.mixer.config.render.target, arguments);
  7638. if (typeof render !== 'function') {
  7639. throw new TypeError(mixitup.messages.errorDatasetRendererNotSet());
  7640. }
  7641. output = render(data);
  7642. if (output && typeof output === 'object' && h.isElement(output)) {
  7643. el = output;
  7644. } else if (typeof output === 'string') {
  7645. temp = document.createElement('div');
  7646. temp.innerHTML = output;
  7647. el = temp.firstElementChild;
  7648. }
  7649. return self.callFilters('elRender', el, arguments);
  7650. },
  7651. /**
  7652. * Caches references of DOM elements neccessary for the target's functionality.
  7653. *
  7654. * @private
  7655. * @instance
  7656. * @since 3.0.0
  7657. * @param {Element} el
  7658. * @return {void}
  7659. */
  7660. cacheDom: function(el) {
  7661. var self = this;
  7662. self.callActions('beforeCacheDom', arguments);
  7663. self.dom.el = el;
  7664. self.callActions('afterCacheDom', arguments);
  7665. },
  7666. /**
  7667. * @private
  7668. * @instance
  7669. * @since 3.0.0
  7670. * @param {string} attributeName
  7671. * @return {void}
  7672. */
  7673. getSortString: function(attributeName) {
  7674. var self = this,
  7675. value = self.dom.el.getAttribute('data-' + attributeName) || '';
  7676. self.callActions('beforeGetSortString', arguments);
  7677. value = isNaN(value * 1) ?
  7678. value.toLowerCase() :
  7679. value * 1;
  7680. self.sortString = value;
  7681. self.callActions('afterGetSortString', arguments);
  7682. },
  7683. /**
  7684. * @private
  7685. * @instance
  7686. * @since 3.0.0
  7687. * @return {void}
  7688. */
  7689. show: function() {
  7690. var self = this;
  7691. self.callActions('beforeShow', arguments);
  7692. if (!self.isShown) {
  7693. self.dom.el.style.display = '';
  7694. self.isShown = true;
  7695. }
  7696. self.callActions('afterShow', arguments);
  7697. },
  7698. /**
  7699. * @private
  7700. * @instance
  7701. * @since 3.0.0
  7702. * @return {void}
  7703. */
  7704. hide: function() {
  7705. var self = this;
  7706. self.callActions('beforeHide', arguments);
  7707. if (self.isShown) {
  7708. self.dom.el.style.display = 'none';
  7709. self.isShown = false;
  7710. }
  7711. self.callActions('afterHide', arguments);
  7712. },
  7713. /**
  7714. * @private
  7715. * @instance
  7716. * @since 3.0.0
  7717. * @param {mixitup.IMoveData} moveData
  7718. * @return {void}
  7719. */
  7720. move: function(moveData) {
  7721. var self = this;
  7722. self.callActions('beforeMove', arguments);
  7723. if (!self.isExcluded) {
  7724. self.mixer.targetsMoved++;
  7725. }
  7726. self.applyStylesIn(moveData);
  7727. requestAnimationFrame(function() {
  7728. self.applyStylesOut(moveData);
  7729. });
  7730. self.callActions('afterMove', arguments);
  7731. },
  7732. /**
  7733. * @private
  7734. * @instance
  7735. * @since 3.0.0
  7736. * @param {object} posData
  7737. * @param {number} multiplier
  7738. * @return {void}
  7739. */
  7740. applyTween: function(posData, multiplier) {
  7741. var self = this,
  7742. propertyName = '',
  7743. tweenData = null,
  7744. posIn = posData.posIn,
  7745. currentTransformValues = [],
  7746. currentValues = new mixitup.StyleData(),
  7747. i = -1;
  7748. self.callActions('beforeApplyTween', arguments);
  7749. currentValues.x = posIn.x;
  7750. currentValues.y = posIn.y;
  7751. if (multiplier === 0) {
  7752. self.hide();
  7753. } else if (!self.isShown) {
  7754. self.show();
  7755. }
  7756. for (i = 0; propertyName = mixitup.features.TWEENABLE[i]; i++) {
  7757. tweenData = posData.tweenData[propertyName];
  7758. if (propertyName === 'x') {
  7759. if (!tweenData) continue;
  7760. currentValues.x = posIn.x + (tweenData * multiplier);
  7761. } else if (propertyName === 'y') {
  7762. if (!tweenData) continue;
  7763. currentValues.y = posIn.y + (tweenData * multiplier);
  7764. } else if (tweenData instanceof mixitup.TransformData) {
  7765. if (!tweenData.value) continue;
  7766. currentValues[propertyName].value =
  7767. posIn[propertyName].value + (tweenData.value * multiplier);
  7768. currentValues[propertyName].unit = tweenData.unit;
  7769. currentTransformValues.push(
  7770. propertyName + '(' + currentValues[propertyName].value + tweenData.unit + ')'
  7771. );
  7772. } else {
  7773. if (!tweenData) continue;
  7774. currentValues[propertyName] = posIn[propertyName] + (tweenData * multiplier);
  7775. self.dom.el.style[propertyName] = currentValues[propertyName];
  7776. }
  7777. }
  7778. if (currentValues.x || currentValues.y) {
  7779. currentTransformValues.unshift('translate(' + currentValues.x + 'px, ' + currentValues.y + 'px)');
  7780. }
  7781. if (currentTransformValues.length) {
  7782. self.dom.el.style[mixitup.features.transformProp] = currentTransformValues.join(' ');
  7783. }
  7784. self.callActions('afterApplyTween', arguments);
  7785. },
  7786. /**
  7787. * Applies the initial styling to a target element before any transition
  7788. * is applied.
  7789. *
  7790. * @private
  7791. * @instance
  7792. * @param {mixitup.IMoveData} moveData
  7793. * @return {void}
  7794. */
  7795. applyStylesIn: function(moveData) {
  7796. var self = this,
  7797. posIn = moveData.posIn,
  7798. isFading = self.mixer.effectsIn.opacity !== 1,
  7799. transformValues = [];
  7800. self.callActions('beforeApplyStylesIn', arguments);
  7801. transformValues.push('translate(' + posIn.x + 'px, ' + posIn.y + 'px)');
  7802. if (self.mixer.config.animation.animateResizeTargets) {
  7803. if (moveData.statusChange !== 'show') {
  7804. // Don't apply posIn width or height or showing, as will be 0
  7805. self.dom.el.style.width = posIn.width + 'px';
  7806. self.dom.el.style.height = posIn.height + 'px';
  7807. }
  7808. self.dom.el.style.marginRight = posIn.marginRight + 'px';
  7809. self.dom.el.style.marginBottom = posIn.marginBottom + 'px';
  7810. }
  7811. isFading && (self.dom.el.style.opacity = posIn.opacity);
  7812. if (moveData.statusChange === 'show') {
  7813. transformValues = transformValues.concat(self.mixer.transformIn);
  7814. }
  7815. self.dom.el.style[mixitup.features.transformProp] = transformValues.join(' ');
  7816. self.callActions('afterApplyStylesIn', arguments);
  7817. },
  7818. /**
  7819. * Applies a transition followed by the final styles for the element to
  7820. * transition towards.
  7821. *
  7822. * @private
  7823. * @instance
  7824. * @param {mixitup.IMoveData} moveData
  7825. * @return {void}
  7826. */
  7827. applyStylesOut: function(moveData) {
  7828. var self = this,
  7829. transitionRules = [],
  7830. transformValues = [],
  7831. isResizing = self.mixer.config.animation.animateResizeTargets,
  7832. isFading = typeof self.mixer.effectsIn.opacity !== 'undefined';
  7833. self.callActions('beforeApplyStylesOut', arguments);
  7834. // Build the transition rules
  7835. transitionRules.push(self.writeTransitionRule(
  7836. mixitup.features.transformRule,
  7837. moveData.staggerIndex
  7838. ));
  7839. if (moveData.statusChange !== 'none') {
  7840. transitionRules.push(self.writeTransitionRule(
  7841. 'opacity',
  7842. moveData.staggerIndex,
  7843. moveData.duration
  7844. ));
  7845. }
  7846. if (isResizing) {
  7847. transitionRules.push(self.writeTransitionRule(
  7848. 'width',
  7849. moveData.staggerIndex,
  7850. moveData.duration
  7851. ));
  7852. transitionRules.push(self.writeTransitionRule(
  7853. 'height',
  7854. moveData.staggerIndex,
  7855. moveData.duration
  7856. ));
  7857. transitionRules.push(self.writeTransitionRule(
  7858. 'margin',
  7859. moveData.staggerIndex,
  7860. moveData.duration
  7861. ));
  7862. }
  7863. // If no callback was provided, the element will
  7864. // not transition in any way so tag it as "immovable"
  7865. if (!moveData.callback) {
  7866. self.mixer.targetsImmovable++;
  7867. if (self.mixer.targetsMoved === self.mixer.targetsImmovable) {
  7868. // If the total targets moved is equal to the
  7869. // number of immovable targets, the operation
  7870. // should be considered finished
  7871. self.mixer.cleanUp(moveData.operation);
  7872. }
  7873. return;
  7874. }
  7875. // If the target will transition in some fasion,
  7876. // assign a callback function
  7877. self.operation = moveData.operation;
  7878. self.callback = moveData.callback;
  7879. // As long as the target is not excluded, increment
  7880. // the total number of targets bound
  7881. !self.isExcluded && self.mixer.targetsBound++;
  7882. // Tag the target as bound to differentiate from transitionEnd
  7883. // events that may come from stylesheet driven effects
  7884. self.isBound = true;
  7885. // Apply the transition
  7886. self.applyTransition(transitionRules);
  7887. // Apply width, height and margin negation
  7888. if (isResizing && moveData.posOut.width > 0 && moveData.posOut.height > 0) {
  7889. self.dom.el.style.width = moveData.posOut.width + 'px';
  7890. self.dom.el.style.height = moveData.posOut.height + 'px';
  7891. self.dom.el.style.marginRight = moveData.posOut.marginRight + 'px';
  7892. self.dom.el.style.marginBottom = moveData.posOut.marginBottom + 'px';
  7893. }
  7894. if (!self.mixer.config.animation.nudge && moveData.statusChange === 'hide') {
  7895. // If we're not nudging, the translation should be
  7896. // applied before any other transforms to prevent
  7897. // lateral movement
  7898. transformValues.push('translate(' + moveData.posOut.x + 'px, ' + moveData.posOut.y + 'px)');
  7899. }
  7900. // Apply fade
  7901. switch (moveData.statusChange) {
  7902. case 'hide':
  7903. isFading && (self.dom.el.style.opacity = self.mixer.effectsOut.opacity);
  7904. transformValues = transformValues.concat(self.mixer.transformOut);
  7905. break;
  7906. case 'show':
  7907. isFading && (self.dom.el.style.opacity = 1);
  7908. }
  7909. if (
  7910. self.mixer.config.animation.nudge ||
  7911. (!self.mixer.config.animation.nudge && moveData.statusChange !== 'hide')
  7912. ) {
  7913. // Opposite of above - apply translate after
  7914. // other transform
  7915. transformValues.push('translate(' + moveData.posOut.x + 'px, ' + moveData.posOut.y + 'px)');
  7916. }
  7917. // Apply transforms
  7918. self.dom.el.style[mixitup.features.transformProp] = transformValues.join(' ');
  7919. self.callActions('afterApplyStylesOut', arguments);
  7920. },
  7921. /**
  7922. * Combines the name of a CSS property with the appropriate duration and delay
  7923. * values to created a valid transition rule.
  7924. *
  7925. * @private
  7926. * @instance
  7927. * @since 3.0.0
  7928. * @param {string} property
  7929. * @param {number} staggerIndex
  7930. * @param {number} duration
  7931. * @return {string}
  7932. */
  7933. writeTransitionRule: function(property, staggerIndex, duration) {
  7934. var self = this,
  7935. delay = self.getDelay(staggerIndex),
  7936. rule = '';
  7937. rule = property + ' ' +
  7938. (duration > 0 ? duration : self.mixer.config.animation.duration) + 'ms ' +
  7939. delay + 'ms ' +
  7940. (property === 'opacity' ? 'linear' : self.mixer.config.animation.easing);
  7941. return self.callFilters('ruleWriteTransitionRule', rule, arguments);
  7942. },
  7943. /**
  7944. * Calculates the transition delay for each target element based on its index, if
  7945. * staggering is applied. If defined, A custom `animation.staggerSeqeuence`
  7946. * function can be used to manipulate the order of indices to produce custom
  7947. * stagger effects (e.g. for use in a grid with irregular row lengths).
  7948. *
  7949. * @private
  7950. * @instance
  7951. * @since 2.0.0
  7952. * @param {number} index
  7953. * @return {number}
  7954. */
  7955. getDelay: function(index) {
  7956. var self = this,
  7957. delay = -1;
  7958. if (typeof self.mixer.config.animation.staggerSequence === 'function') {
  7959. index = self.mixer.config.animation.staggerSequence.call(self, index, self.state);
  7960. }
  7961. delay = !!self.mixer.staggerDuration ? index * self.mixer.staggerDuration : 0;
  7962. return self.callFilters('delayGetDelay', delay, arguments);
  7963. },
  7964. /**
  7965. * @private
  7966. * @instance
  7967. * @since 3.0.0
  7968. * @param {string[]} rules
  7969. * @return {void}
  7970. */
  7971. applyTransition: function(rules) {
  7972. var self = this,
  7973. transitionString = rules.join(', ');
  7974. self.callActions('beforeApplyTransition', arguments);
  7975. self.dom.el.style[mixitup.features.transitionProp] = transitionString;
  7976. self.callActions('afterApplyTransition', arguments);
  7977. },
  7978. /**
  7979. * @private
  7980. * @instance
  7981. * @since 3.0.0
  7982. * @param {Event} e
  7983. * @return {void}
  7984. */
  7985. handleTransitionEnd: function(e) {
  7986. var self = this,
  7987. propName = e.propertyName,
  7988. canResize = self.mixer.config.animation.animateResizeTargets;
  7989. self.callActions('beforeHandleTransitionEnd', arguments);
  7990. if (
  7991. self.isBound &&
  7992. e.target.matches(self.mixer.config.selectors.target) &&
  7993. (
  7994. propName.indexOf('transform') > -1 ||
  7995. propName.indexOf('opacity') > -1 ||
  7996. canResize && propName.indexOf('height') > -1 ||
  7997. canResize && propName.indexOf('width') > -1 ||
  7998. canResize && propName.indexOf('margin') > -1
  7999. )
  8000. ) {
  8001. self.callback.call(self, self.operation);
  8002. self.isBound = false;
  8003. self.callback = null;
  8004. self.operation = null;
  8005. }
  8006. self.callActions('afterHandleTransitionEnd', arguments);
  8007. },
  8008. /**
  8009. * @private
  8010. * @instance
  8011. * @since 3.0.0
  8012. * @param {Event} e
  8013. * @return {void}
  8014. */
  8015. eventBus: function(e) {
  8016. var self = this;
  8017. self.callActions('beforeEventBus', arguments);
  8018. switch (e.type) {
  8019. case 'webkitTransitionEnd':
  8020. case 'transitionend':
  8021. self.handleTransitionEnd(e);
  8022. }
  8023. self.callActions('afterEventBus', arguments);
  8024. },
  8025. /**
  8026. * @private
  8027. * @instance
  8028. * @since 3.0.0
  8029. * @return {void}
  8030. */
  8031. unbindEvents: function() {
  8032. var self = this;
  8033. self.callActions('beforeUnbindEvents', arguments);
  8034. h.off(self.dom.el, 'webkitTransitionEnd', self.handler);
  8035. h.off(self.dom.el, 'transitionend', self.handler);
  8036. self.callActions('afterUnbindEvents', arguments);
  8037. },
  8038. /**
  8039. * @private
  8040. * @instance
  8041. * @since 3.0.0
  8042. * @return {void}
  8043. */
  8044. bindEvents: function() {
  8045. var self = this,
  8046. transitionEndEvent = '';
  8047. self.callActions('beforeBindEvents', arguments);
  8048. transitionEndEvent = mixitup.features.transitionPrefix === 'webkit' ? 'webkitTransitionEnd' : 'transitionend';
  8049. self.handler = function(e) {
  8050. return self.eventBus(e);
  8051. };
  8052. h.on(self.dom.el, transitionEndEvent, self.handler);
  8053. self.callActions('afterBindEvents', arguments);
  8054. },
  8055. /**
  8056. * @private
  8057. * @instance
  8058. * @since 3.0.0
  8059. * @param {boolean} [getBox]
  8060. * @return {PosData}
  8061. */
  8062. getPosData: function(getBox) {
  8063. var self = this,
  8064. styles = {},
  8065. rect = null,
  8066. posData = new mixitup.StyleData();
  8067. self.callActions('beforeGetPosData', arguments);
  8068. posData.x = self.dom.el.offsetLeft;
  8069. posData.y = self.dom.el.offsetTop;
  8070. if (self.mixer.config.animation.animateResizeTargets || getBox) {
  8071. rect = self.dom.el.getBoundingClientRect();
  8072. posData.top = rect.top;
  8073. posData.right = rect.right;
  8074. posData.bottom = rect.bottom;
  8075. posData.left = rect.left;
  8076. posData.width = rect.width;
  8077. posData.height = rect.height;
  8078. }
  8079. if (self.mixer.config.animation.animateResizeTargets) {
  8080. styles = window.getComputedStyle(self.dom.el);
  8081. posData.marginBottom = parseFloat(styles.marginBottom);
  8082. posData.marginRight = parseFloat(styles.marginRight);
  8083. }
  8084. return self.callFilters('posDataGetPosData', posData, arguments);
  8085. },
  8086. /**
  8087. * @private
  8088. * @instance
  8089. * @since 3.0.0
  8090. * @return {void}
  8091. */
  8092. cleanUp: function() {
  8093. var self = this;
  8094. self.callActions('beforeCleanUp', arguments);
  8095. self.dom.el.style[mixitup.features.transformProp] = '';
  8096. self.dom.el.style[mixitup.features.transitionProp] = '';
  8097. self.dom.el.style.opacity = '';
  8098. if (self.mixer.config.animation.animateResizeTargets) {
  8099. self.dom.el.style.width = '';
  8100. self.dom.el.style.height = '';
  8101. self.dom.el.style.marginRight = '';
  8102. self.dom.el.style.marginBottom = '';
  8103. }
  8104. self.callActions('afterCleanUp', arguments);
  8105. }
  8106. });
  8107. /**
  8108. * A jQuery-collection-like wrapper around one or more `mixitup.Mixer` instances
  8109. * allowing simultaneous control of said instances similar to the MixItUp 2 API.
  8110. *
  8111. * @example
  8112. * new mixitup.Collection(instances)
  8113. *
  8114. * @constructor
  8115. * @namespace
  8116. * @memberof mixitup
  8117. * @private
  8118. * @since 3.0.0
  8119. * @param {mixitup.Mixer[]} instances
  8120. */
  8121. mixitup.Collection = function(instances) {
  8122. var instance = null,
  8123. i = -1;
  8124. this.callActions('beforeConstruct');
  8125. for (i = 0; instance = instances[i]; i++) {
  8126. this[i] = instance;
  8127. }
  8128. this.length = instances.length;
  8129. this.callActions('afterConstruct');
  8130. h.freeze(this);
  8131. };
  8132. mixitup.BaseStatic.call(mixitup.Collection);
  8133. mixitup.Collection.prototype = Object.create(mixitup.Base.prototype);
  8134. h.extend(mixitup.Collection.prototype,
  8135. /** @lends mixitup.Collection */
  8136. {
  8137. constructor: mixitup.Collection,
  8138. /**
  8139. * Calls a method on all instances in the collection by passing the method
  8140. * name as a string followed by any applicable parameters to be curried into
  8141. * to the method.
  8142. *
  8143. * @example
  8144. * .mixitup(methodName[,arg1][,arg2..]);
  8145. *
  8146. * @example
  8147. * var collection = new Collection([mixer1, mixer2]);
  8148. *
  8149. * return collection.mixitup('filter', '.category-a')
  8150. * .then(function(states) {
  8151. * state.forEach(function(state) {
  8152. * console.log(state.activeFilter.selector); // .category-a
  8153. * });
  8154. * });
  8155. *
  8156. * @public
  8157. * @instance
  8158. * @since 3.0.0
  8159. * @param {string} methodName
  8160. * @return {Promise<Array<mixitup.State>>}
  8161. */
  8162. mixitup: function(methodName) {
  8163. var self = this,
  8164. instance = null,
  8165. args = Array.prototype.slice.call(arguments),
  8166. tasks = [],
  8167. i = -1;
  8168. this.callActions('beforeMixitup');
  8169. args.shift();
  8170. for (i = 0; instance = self[i]; i++) {
  8171. tasks.push(instance[methodName].apply(instance, args));
  8172. }
  8173. return self.callFilters('promiseMixitup', h.all(tasks, mixitup.libraries), arguments);
  8174. }
  8175. });
  8176. /**
  8177. * `mixitup.Operation` objects contain all data neccessary to describe the full
  8178. * lifecycle of any MixItUp operation. They can be used to compute and store an
  8179. * operation for use at a later time (e.g. programmatic tweening).
  8180. *
  8181. * @constructor
  8182. * @namespace
  8183. * @memberof mixitup
  8184. * @private
  8185. * @since 3.0.0
  8186. */
  8187. mixitup.Operation = function() {
  8188. mixitup.Base.call(this);
  8189. this.callActions('beforeConstruct');
  8190. this.id = '';
  8191. this.args = [];
  8192. this.command = null;
  8193. this.showPosData = [];
  8194. this.toHidePosData = [];
  8195. this.startState = null;
  8196. this.newState = null;
  8197. this.docState = null;
  8198. this.willSort = false;
  8199. this.willChangeLayout = false;
  8200. this.hasEffect = false;
  8201. this.hasFailed = false;
  8202. this.triggerElement = null;
  8203. this.show = [];
  8204. this.hide = [];
  8205. this.matching = [];
  8206. this.toShow = [];
  8207. this.toHide = [];
  8208. this.toMove = [];
  8209. this.toRemove = [];
  8210. this.startOrder = [];
  8211. this.newOrder = [];
  8212. this.startSort = null;
  8213. this.newSort = null;
  8214. this.startFilter = null;
  8215. this.newFilter = null;
  8216. this.startDataset = null;
  8217. this.newDataset = null;
  8218. this.viewportDeltaX = 0;
  8219. this.viewportDeltaY = 0;
  8220. this.startX = 0;
  8221. this.startY = 0;
  8222. this.startHeight = 0;
  8223. this.startWidth = 0;
  8224. this.newX = 0;
  8225. this.newY = 0;
  8226. this.newHeight = 0;
  8227. this.newWidth = 0;
  8228. this.startContainerClassName = '';
  8229. this.startDisplay = '';
  8230. this.newContainerClassName = '';
  8231. this.newDisplay = '';
  8232. this.callActions('afterConstruct');
  8233. h.seal(this);
  8234. };
  8235. mixitup.BaseStatic.call(mixitup.Operation);
  8236. mixitup.Operation.prototype = Object.create(mixitup.Base.prototype);
  8237. mixitup.Operation.prototype.constructor = mixitup.Operation;
  8238. /**
  8239. * `mixitup.State` objects expose various pieces of data detailing the state of
  8240. * a MixItUp instance. They are provided at the start and end of any operation via
  8241. * callbacks and events, with the most recent state stored between operations
  8242. * for retrieval at any time via the API.
  8243. *
  8244. * @constructor
  8245. * @namespace
  8246. * @memberof mixitup
  8247. * @public
  8248. * @since 3.0.0
  8249. */
  8250. mixitup.State = function() {
  8251. mixitup.Base.call(this);
  8252. this.callActions('beforeConstruct');
  8253. /**
  8254. * The ID of the mixer instance.
  8255. *
  8256. * @name id
  8257. * @memberof mixitup.State
  8258. * @instance
  8259. * @type {string}
  8260. * @default ''
  8261. */
  8262. this.id = '';
  8263. /**
  8264. * The currently active filter command as set by a control click or API call.
  8265. *
  8266. * @name activeFilter
  8267. * @memberof mixitup.State
  8268. * @instance
  8269. * @type {mixitup.CommandFilter}
  8270. * @default null
  8271. */
  8272. this.activeFilter = null;
  8273. /**
  8274. * The currently active sort command as set by a control click or API call.
  8275. *
  8276. * @name activeSort
  8277. * @memberof mixitup.State
  8278. * @instance
  8279. * @type {mixitup.CommandSort}
  8280. * @default null
  8281. */
  8282. this.activeSort = null;
  8283. /**
  8284. * The current layout-specific container class name, if applied.
  8285. *
  8286. * @name activeContainerClassName
  8287. * @memberof mixitup.State
  8288. * @instance
  8289. * @type {string}
  8290. * @default ''
  8291. */
  8292. this.activeContainerClassName = '';
  8293. /**
  8294. * A reference to the container element that the mixer is instantiated on.
  8295. *
  8296. * @name container
  8297. * @memberof mixitup.State
  8298. * @instance
  8299. * @type {Element}
  8300. * @default null
  8301. */
  8302. this.container = null;
  8303. /**
  8304. * An array of all target elements indexed by the mixer.
  8305. *
  8306. * @name targets
  8307. * @memberof mixitup.State
  8308. * @instance
  8309. * @type {Array.<Element>}
  8310. * @default []
  8311. */
  8312. this.targets = [];
  8313. /**
  8314. * An array of all target elements not matching the current filter.
  8315. *
  8316. * @name hide
  8317. * @memberof mixitup.State
  8318. * @instance
  8319. * @type {Array.<Element>}
  8320. * @default []
  8321. */
  8322. this.hide = [];
  8323. /**
  8324. * An array of all target elements matching the current filter and any additional
  8325. * limits applied such as pagination.
  8326. *
  8327. * @name show
  8328. * @memberof mixitup.State
  8329. * @instance
  8330. * @type {Array.<Element>}
  8331. * @default []
  8332. */
  8333. this.show = [];
  8334. /**
  8335. * An array of all target elements matching the current filter irrespective of
  8336. * any additional limits applied such as pagination.
  8337. *
  8338. * @name matching
  8339. * @memberof mixitup.State
  8340. * @instance
  8341. * @type {Array.<Element>}
  8342. * @default []
  8343. */
  8344. this.matching = [];
  8345. /**
  8346. * An integer representing the total number of target elements indexed by the
  8347. * mixer. Equivalent to `state.targets.length`.
  8348. *
  8349. * @name totalTargets
  8350. * @memberof mixitup.State
  8351. * @instance
  8352. * @type {number}
  8353. * @default -1
  8354. */
  8355. this.totalTargets = -1;
  8356. /**
  8357. * An integer representing the total number of target elements matching the
  8358. * current filter and any additional limits applied such as pagination.
  8359. * Equivalent to `state.show.length`.
  8360. *
  8361. * @name totalShow
  8362. * @memberof mixitup.State
  8363. * @instance
  8364. * @type {number}
  8365. * @default -1
  8366. */
  8367. this.totalShow = -1;
  8368. /**
  8369. * An integer representing the total number of target elements not matching
  8370. * the current filter. Equivalent to `state.hide.length`.
  8371. *
  8372. * @name totalHide
  8373. * @memberof mixitup.State
  8374. * @instance
  8375. * @type {number}
  8376. * @default -1
  8377. */
  8378. this.totalHide = -1;
  8379. /**
  8380. * An integer representing the total number of target elements matching the
  8381. * current filter irrespective of any other limits applied such as pagination.
  8382. * Equivalent to `state.matching.length`.
  8383. *
  8384. * @name totalMatching
  8385. * @memberof mixitup.State
  8386. * @instance
  8387. * @type {number}
  8388. * @default -1
  8389. */
  8390. this.totalMatching = -1;
  8391. /**
  8392. * A boolean indicating whether the last operation "failed", i.e. no targets
  8393. * could be found matching the filter.
  8394. *
  8395. * @name hasFailed
  8396. * @memberof mixitup.State
  8397. * @instance
  8398. * @type {boolean}
  8399. * @default false
  8400. */
  8401. this.hasFailed = false;
  8402. /**
  8403. * The DOM element that was clicked if the last operation was triggered by the
  8404. * clicking of a control and not an API call.
  8405. *
  8406. * @name triggerElement
  8407. * @memberof mixitup.State
  8408. * @instance
  8409. * @type {Element|null}
  8410. * @default null
  8411. */
  8412. this.triggerElement = null;
  8413. /**
  8414. * The currently active dataset underlying the rendered targets, if the
  8415. * dataset API is in use.
  8416. *
  8417. * @name activeDataset
  8418. * @memberof mixitup.State
  8419. * @instance
  8420. * @type {Array.<object>}
  8421. * @default null
  8422. */
  8423. this.activeDataset = null;
  8424. this.callActions('afterConstruct');
  8425. h.seal(this);
  8426. };
  8427. mixitup.BaseStatic.call(mixitup.State);
  8428. mixitup.State.prototype = Object.create(mixitup.Base.prototype);
  8429. mixitup.State.prototype.constructor = mixitup.State;
  8430. /**
  8431. * @constructor
  8432. * @memberof mixitup
  8433. * @private
  8434. * @since 3.0.0
  8435. */
  8436. mixitup.UserInstruction = function() {
  8437. mixitup.Base.call(this);
  8438. this.callActions('beforeConstruct');
  8439. this.command = {};
  8440. this.animate = false;
  8441. this.callback = null;
  8442. this.callActions('afterConstruct');
  8443. h.seal(this);
  8444. };
  8445. mixitup.BaseStatic.call(mixitup.UserInstruction);
  8446. mixitup.UserInstruction.prototype = Object.create(mixitup.Base.prototype);
  8447. mixitup.UserInstruction.prototype.constructor = mixitup.UserInstruction;
  8448. /**
  8449. * @constructor
  8450. * @memberof mixitup
  8451. * @private
  8452. * @since 3.0.0
  8453. */
  8454. mixitup.Messages = function() {
  8455. mixitup.Base.call(this);
  8456. this.callActions('beforeConstruct');
  8457. /* Errors
  8458. ----------------------------------------------------------------------------- */
  8459. this.ERROR_FACTORY_INVALID_CONTAINER =
  8460. '[MixItUp] An invalid selector or element reference was passed to the mixitup factory function';
  8461. this.ERROR_FACTORY_CONTAINER_NOT_FOUND =
  8462. '[MixItUp] The provided selector yielded no container element';
  8463. this.ERROR_CONFIG_INVALID_ANIMATION_EFFECTS =
  8464. '[MixItUp] Invalid value for `animation.effects`';
  8465. this.ERROR_CONFIG_INVALID_CONTROLS_SCOPE =
  8466. '[MixItUp] Invalid value for `controls.scope`';
  8467. this.ERROR_CONFIG_INVALID_PROPERTY =
  8468. '[MixitUp] Invalid configuration object property "${erroneous}"${suggestion}';
  8469. this.ERROR_CONFIG_INVALID_PROPERTY_SUGGESTION =
  8470. '. Did you mean "${probableMatch}"?';
  8471. this.ERROR_CONFIG_DATA_UID_KEY_NOT_SET =
  8472. '[MixItUp] To use the dataset API, a UID key must be specified using `data.uidKey`';
  8473. this.ERROR_DATASET_INVALID_UID_KEY =
  8474. '[MixItUp] The specified UID key "${uidKey}" is not present on one or more dataset items';
  8475. this.ERROR_DATASET_DUPLICATE_UID =
  8476. '[MixItUp] The UID "${uid}" was found on two or more dataset items. UIDs must be unique.';
  8477. this.ERROR_INSERT_INVALID_ARGUMENTS =
  8478. '[MixItUp] Please provider either an index or a sibling and position to insert, not both';
  8479. this.ERROR_INSERT_PREEXISTING_ELEMENT =
  8480. '[MixItUp] An element to be inserted already exists in the container';
  8481. this.ERROR_FILTER_INVALID_ARGUMENTS =
  8482. '[MixItUp] Please provide either a selector or collection `.filter()`, not both';
  8483. this.ERROR_DATASET_NOT_SET =
  8484. '[MixItUp] To use the dataset API with pre-rendered targets, a starting dataset must be set using `load.dataset`';
  8485. this.ERROR_DATASET_PRERENDERED_MISMATCH =
  8486. '[MixItUp] `load.dataset` does not match pre-rendered targets';
  8487. this.ERROR_DATASET_RENDERER_NOT_SET =
  8488. '[MixItUp] To insert an element via the dataset API, a target renderer function must be provided to `render.target`';
  8489. /* Warnings
  8490. ----------------------------------------------------------------------------- */
  8491. this.WARNING_FACTORY_PREEXISTING_INSTANCE =
  8492. '[MixItUp] WARNING: This element already has an active MixItUp instance. The provided configuration object will be ignored.' +
  8493. ' If you wish to perform additional methods on this instance, please create a reference.';
  8494. this.WARNING_INSERT_NO_ELEMENTS =
  8495. '[MixItUp] WARNING: No valid elements were passed to `.insert()`';
  8496. this.WARNING_REMOVE_NO_ELEMENTS =
  8497. '[MixItUp] WARNING: No valid elements were passed to `.remove()`';
  8498. this.WARNING_MULTIMIX_INSTANCE_QUEUE_FULL =
  8499. '[MixItUp] WARNING: An operation was requested but the MixItUp instance was busy. The operation was rejected because the ' +
  8500. 'queue is full or queuing is disabled.';
  8501. this.WARNING_GET_OPERATION_INSTANCE_BUSY =
  8502. '[MixItUp] WARNING: Operations can be be created while the MixItUp instance is busy.';
  8503. this.WARNING_NO_PROMISE_IMPLEMENTATION =
  8504. '[MixItUp] WARNING: No Promise implementations could be found. If you wish to use promises with MixItUp please install' +
  8505. ' an ES6 Promise polyfill.';
  8506. this.WARNING_INCONSISTENT_SORTING_ATTRIBUTES =
  8507. '[MixItUp] WARNING: The requested sorting data attribute "${attribute}" was not present on one or more target elements' +
  8508. ' which may product unexpected sort output';
  8509. this.callActions('afterConstruct');
  8510. this.compileTemplates();
  8511. h.seal(this);
  8512. };
  8513. mixitup.BaseStatic.call(mixitup.Messages);
  8514. mixitup.Messages.prototype = Object.create(mixitup.Base.prototype);
  8515. mixitup.Messages.prototype.constructor = mixitup.Messages;
  8516. /**
  8517. * @return {void}
  8518. */
  8519. mixitup.Messages.prototype.compileTemplates = function() {
  8520. var errorKey = '';
  8521. var errorMessage = '';
  8522. for (errorKey in this) {
  8523. if (typeof (errorMessage = this[errorKey]) !== 'string') continue;
  8524. this[h.camelCase(errorKey)] = h.template(errorMessage);
  8525. }
  8526. };
  8527. mixitup.messages = new mixitup.Messages();
  8528. /**
  8529. * @constructor
  8530. * @memberof mixitup
  8531. * @private
  8532. * @since 3.0.0
  8533. * @param {mixitup.Mixer} mixer
  8534. */
  8535. mixitup.Facade = function Mixer(mixer) {
  8536. mixitup.Base.call(this);
  8537. this.callActions('beforeConstruct', arguments);
  8538. this.configure = mixer.configure.bind(mixer);
  8539. this.show = mixer.show.bind(mixer);
  8540. this.hide = mixer.hide.bind(mixer);
  8541. this.filter = mixer.filter.bind(mixer);
  8542. this.toggleOn = mixer.toggleOn.bind(mixer);
  8543. this.toggleOff = mixer.toggleOff.bind(mixer);
  8544. this.sort = mixer.sort.bind(mixer);
  8545. this.changeLayout = mixer.changeLayout.bind(mixer);
  8546. this.multimix = mixer.multimix.bind(mixer);
  8547. this.dataset = mixer.dataset.bind(mixer);
  8548. this.tween = mixer.tween.bind(mixer);
  8549. this.insert = mixer.insert.bind(mixer);
  8550. this.insertBefore = mixer.insertBefore.bind(mixer);
  8551. this.insertAfter = mixer.insertAfter.bind(mixer);
  8552. this.prepend = mixer.prepend.bind(mixer);
  8553. this.append = mixer.append.bind(mixer);
  8554. this.remove = mixer.remove.bind(mixer);
  8555. this.destroy = mixer.destroy.bind(mixer);
  8556. this.forceRefresh = mixer.forceRefresh.bind(mixer);
  8557. this.forceRender = mixer.forceRender.bind(mixer);
  8558. this.isMixing = mixer.isMixing.bind(mixer);
  8559. this.getOperation = mixer.getOperation.bind(mixer);
  8560. this.getConfig = mixer.getConfig.bind(mixer);
  8561. this.getState = mixer.getState.bind(mixer);
  8562. this.callActions('afterConstruct', arguments);
  8563. h.freeze(this);
  8564. h.seal(this);
  8565. };
  8566. mixitup.BaseStatic.call(mixitup.Facade);
  8567. mixitup.Facade.prototype = Object.create(mixitup.Base.prototype);
  8568. mixitup.Facade.prototype.constructor = mixitup.Facade;
  8569. if (typeof exports === 'object' && typeof module === 'object') {
  8570. module.exports = mixitup;
  8571. } else if (typeof define === 'function' && define.amd) {
  8572. define(function() {
  8573. return mixitup;
  8574. });
  8575. } else if (typeof window.mixitup === 'undefined' || typeof window.mixitup !== 'function') {
  8576. window.mixitup = mixitup;
  8577. }
  8578. mixitup.BaseStatic.call(mixitup.constructor);
  8579. mixitup.NAME = 'mixitup';
  8580. mixitup.CORE_VERSION = '3.3.0';
  8581. })(window);